File: ParticleInitializer.cpp

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (165 lines) | stat: -rw-r--r-- 4,167 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "../CommonConstants.h"
#include "ParticleInitializer.h"
#include "../../Main.h"

namespace nCine
{
	void ParticleInitializer::setAmount(std::int32_t amount)
	{
		DEATH_ASSERT(amount > 0);
		rndAmount.Set(amount, amount);
	}

	void ParticleInitializer::setAmount(std::int32_t minAmount, std::int32_t maxAmount)
	{
		DEATH_ASSERT(minAmount <= maxAmount);
		rndAmount.Set(minAmount, maxAmount);
	}

	void ParticleInitializer::setLife(float life)
	{
		rndLife.Set(life, life);
	}

	void ParticleInitializer::setLife(float minLife, float maxLife)
	{
		DEATH_ASSERT(minLife <= maxLife);
		rndLife.Set(minLife, maxLife);
	}

	void ParticleInitializer::setPosition(float x, float y)
	{
		rndPositionX.Set(x, x);
		rndPositionY.Set(y, y);
	}

	void ParticleInitializer::setPosition(float minX, float minY, float maxX, float maxY)
	{
		DEATH_ASSERT(minX <= maxX && minY <= maxY);
		rndPositionX.Set(minX, maxX);
		rndPositionY.Set(minY, maxY);
	}

	void ParticleInitializer::setPositionAndRadius(float x, float y, float radius)
	{
		DEATH_ASSERT(radius >= 0.0f);
		rndPositionX.Set(x - radius, x + radius);
		rndPositionY.Set(y - radius, y + radius);
	}

	void ParticleInitializer::setPosition(Vector2f pos)
	{
		setPosition(pos.X, pos.Y);
	}

	void ParticleInitializer::setPosition(Vector2f minPos, Vector2f maxPos)
	{
		setPosition(minPos.X, minPos.Y, maxPos.X, maxPos.Y);
	}

	void ParticleInitializer::setPositionAndRadius(Vector2f pos, float radius)
	{
		setPositionAndRadius(pos.X, pos.Y, radius);
	}

	void ParticleInitializer::setPositionInDisc(float radius)
	{
		setPositionAndRadius(0.0f, 0.0f, radius);
	}

	void ParticleInitializer::setVelocity(float x, float y)
	{
		rndVelocityX.Set(x, x);
		rndVelocityY.Set(y, y);
	}

	void ParticleInitializer::setVelocity(float minX, float minY, float maxX, float maxY)
	{
		DEATH_ASSERT(minX <= maxX && minY <= maxY);
		rndVelocityX.Set(minX, maxX);
		rndVelocityY.Set(minY, maxY);
	}

	void ParticleInitializer::setVelocityAndRadius(float x, float y, float radius)
	{
		DEATH_ASSERT(radius >= 0.0f);
		rndVelocityX.Set(x - radius, x + radius);
		rndVelocityY.Set(y - radius, y + radius);
	}

	void ParticleInitializer::setVelocityAndScale(float x, float y, float minScale, float maxScale)
	{
		DEATH_ASSERT(minScale <= maxScale);
		rndVelocityX.Set(x * minScale, x * maxScale);
		rndVelocityY.Set(y * minScale, y * maxScale);

		if (rndVelocityX.X > rndVelocityX.Y) {
			float tmp = rndVelocityX.X;
			rndVelocityX.X = rndVelocityX.Y;
			rndVelocityX.Y = tmp;
		}
		if (rndVelocityY.X > rndVelocityY.Y) {
			float tmp = rndVelocityY.X;
			rndVelocityY.X = rndVelocityY.Y;
			rndVelocityY.Y = tmp;
		}
	}

	void ParticleInitializer::setVelocityAndAngle(float x, float y, float angle)
	{
		const float sinAngle = sinf(angle * 0.5f);
		const float cosAngle = cosf(angle * 0.5f);

		rndVelocityX.X = x * cosAngle - y * sinAngle;
		rndVelocityX.Y = x * cosAngle - y * -sinAngle;
		rndVelocityY.X = x * sinAngle + y * cosAngle;
		rndVelocityY.Y = x * -sinAngle + y * cosAngle;

		if (rndVelocityX.X > rndVelocityX.Y) {
			float tmp = rndVelocityX.X;
			rndVelocityX.X = rndVelocityX.Y;
			rndVelocityX.Y = tmp;
		}
		if (rndVelocityY.X > rndVelocityY.Y) {
			float tmp = rndVelocityY.X;
			rndVelocityY.X = rndVelocityY.Y;
			rndVelocityY.Y = tmp;
		}
	}

	void ParticleInitializer::setVelocity(Vector2f vel)
	{
		setVelocity(vel.X, vel.Y);
	}

	void ParticleInitializer::setVelocity(Vector2f minVel, Vector2f maxVel)
	{
		setVelocity(minVel.X, minVel.Y, maxVel.X, maxVel.Y);
	}

	void ParticleInitializer::setVelocityAndRadius(Vector2f vel, float radius)
	{
		setVelocityAndRadius(vel.X, vel.Y, radius);
	}

	void ParticleInitializer::setVelocityAndScale(Vector2f vel, float minScale, float maxScale)
	{
		setVelocityAndScale(vel.X, vel.Y, minScale, maxScale);
	}

	void ParticleInitializer::setVelocityAndAngle(Vector2f vel, float angle)
	{
		setVelocityAndAngle(vel.X, vel.Y, angle);
	}

	void ParticleInitializer::setRotation(float rot)
	{
		rndRotation.Set(rot, rot);
	}

	void ParticleInitializer::setRotation(float minRot, float maxRot)
	{
		DEATH_ASSERT(minRot <= maxRot);
		rndRotation.Set(minRot, maxRot);
	}
}