Mana
Loading...
Searching...
No Matches
src
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
26
static
const
double
PI
= 3.14159265;
27
28
29
enum
ChangeFunc
30
{
31
FUNC_NONE
,
32
FUNC_SINE
,
33
FUNC_SAW
,
34
FUNC_TRIANGLE
,
35
FUNC_SQUARE
36
};
37
38
template
<
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
51
void
setFunction
(
ChangeFunc
func
,
T
amplitude
,
int
period
,
int
phase
)
52
{
53
changeFunc
=
func
;
54
changeAmplitude
=
amplitude
;
55
changePeriod
=
period
;
56
changePhase
=
phase
;
57
}
58
59
T
value
(
int
tick
)
60
{
61
tick
+=
changePhase
;
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
{
75
val
+=
changeAmplitude
- (
T
)((
tick
%
changePeriod
) / (
double
)
changePeriod
) *
changeAmplitude
* 4;
76
}
77
else
78
{
79
val
+=
changeAmplitude
* -3 + (
T
)((
tick
%
changePeriod
) / (
double
)
changePeriod
) *
changeAmplitude
* 4;
80
// I have no idea why this works but it does
81
}
82
break
;
83
case
FUNC_SQUARE
:
84
if
((
tick
%
changePeriod
) * 2 <
changePeriod
)
85
val
+=
changeAmplitude
;
86
else
87
val
-=
changeAmplitude
;
88
break
;
89
case
FUNC_NONE
:
90
default
:
91
//nothing
92
break
;
93
}
94
95
return
val
;
96
}
97
98
T
minVal
;
99
T
maxVal
;
100
101
ChangeFunc
changeFunc
=
FUNC_NONE
;
102
T
changeAmplitude
;
103
int
changePeriod
;
104
int
changePhase
;
105
};
ChangeFunc
ChangeFunc
Definition
particleemitterprop.h:30
FUNC_TRIANGLE
@ FUNC_TRIANGLE
Definition
particleemitterprop.h:34
FUNC_SQUARE
@ FUNC_SQUARE
Definition
particleemitterprop.h:35
FUNC_SAW
@ FUNC_SAW
Definition
particleemitterprop.h:33
FUNC_SINE
@ FUNC_SINE
Definition
particleemitterprop.h:32
FUNC_NONE
@ FUNC_NONE
Definition
particleemitterprop.h:31
PI
#define PI
Definition
rotationalparticle.cpp:25
ParticleEmitterProp
Definition
particleemitterprop.h:39
ParticleEmitterProp::value
T value(int tick)
Definition
particleemitterprop.h:59
ParticleEmitterProp::set
void set(T val)
Definition
particleemitterprop.h:46
ParticleEmitterProp::changeAmplitude
T changeAmplitude
Definition
particleemitterprop.h:102
ParticleEmitterProp::maxVal
T maxVal
Definition
particleemitterprop.h:99
ParticleEmitterProp::set
void set(T min, T max)
Definition
particleemitterprop.h:40
ParticleEmitterProp::setFunction
void setFunction(ChangeFunc func, T amplitude, int period, int phase)
Definition
particleemitterprop.h:51
ParticleEmitterProp::changeFunc
ChangeFunc changeFunc
Definition
particleemitterprop.h:101
ParticleEmitterProp::changePeriod
int changePeriod
Definition
particleemitterprop.h:103
ParticleEmitterProp::changePhase
int changePhase
Definition
particleemitterprop.h:104
ParticleEmitterProp::minVal
T minVal
Definition
particleemitterprop.h:98
Generated by
1.9.8