Mana
Loading...
Searching...
No Matches
particleemitterprop.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2006-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <cmath>
25
26static const double PI = 3.14159265;
27
28
37
38template <typename T> struct ParticleEmitterProp
39{
40 void set(T min, T max)
41 {
42 minVal = min;
43 maxVal = max;
44 }
45
46 void set(T val)
47 {
48 set(val, val);
49 }
50
58
60 {
62 T val = (T) (minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1)));
63
64 switch (changeFunc)
65 {
66 case FUNC_SINE:
67 val += (T) std::sin(PI * 2 * ((double)(tick % changePeriod) / (double)changePeriod)) * changeAmplitude;
68 break;
69 case FUNC_SAW:
70 val += (T) (changeAmplitude * ((double)(tick % changePeriod) / (double)changePeriod)) * 2 - changeAmplitude;
71 break;
72 case FUNC_TRIANGLE:
73 if ((tick % changePeriod) * 2 < changePeriod)
74 {
76 }
77 else
78 {
80 // I have no idea why this works but it does
81 }
82 break;
83 case FUNC_SQUARE:
84 if ((tick % changePeriod) * 2 < changePeriod)
86 else
88 break;
89 case FUNC_NONE:
90 default:
91 //nothing
92 break;
93 }
94
95 return val;
96 }
97
100
105};
@ FUNC_TRIANGLE
@ FUNC_SQUARE
@ FUNC_SINE
@ FUNC_NONE
#define PI
void set(T min, T max)
void setFunction(ChangeFunc func, T amplitude, int period, int phase)