-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParticleEmitter.h
157 lines (136 loc) · 5.6 KB
/
ParticleEmitter.h
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
//
// ParticleEmitter.h
// ParticleEmitterDemo
//
// Copyright (c) 2010 71Squared
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "Global.h"
@class Texture2D;
// Particle type
enum kParticleTypes {
kParticleTypeGravity,
kParticleTypeRadial
};
// Structure that holds the location and size for each point sprite
typedef struct {
GLfloat x;
GLfloat y;
GLfloat s;
GLfloat t;
Color4f color;
} PointSprite;
typedef struct {
Vector2f vertex;
Vector2f texture;
Color4f color;
} TexturedColoredVertex;
typedef struct {
TexturedColoredVertex bl;
TexturedColoredVertex br;
TexturedColoredVertex tl;
TexturedColoredVertex tr;
} ParticleQuad;
// Structure used to hold particle specific information
typedef struct {
Vector2f position;
Vector2f direction;
Vector2f startPos;
Color4f color;
Color4f deltaColor;
GLfloat rotation;
GLfloat rotationDelta;
GLfloat radialAcceleration;
GLfloat tangentialAcceleration;
GLfloat radius;
GLfloat radiusDelta;
GLfloat angle;
GLfloat degreesPerSecond;
GLfloat particleSize;
GLfloat particleSizeDelta;
GLfloat timeToLive;
} Particle;
#define MAXIMUM_UPDATE_RATE 90.0f // The maximum number of updates that occur per frame
// The particleEmitter allows you to define parameters that are used when generating particles.
// These particles are OpenGL particle sprites that based on the parameters provided each have
// their own characteristics such as speed, lifespan, start and end colors etc. Using these
// particle emitters allows you to create organic looking effects such as smoke, fire and
// explosions.
//
// The design for this particle emitter was influenced by the point sprite particle system
// used in the Cocos2D game engine
//
@interface ParticleEmitter : NSObject {
/////////////////// Particle iVars
int emitterType;
Texture2D *texture;
Vector2f sourcePosition, sourcePositionVariance;
GLfloat angle, angleVariance;
GLfloat speed, speedVariance;
GLfloat radialAcceleration, tangentialAcceleration;
GLfloat radialAccelVariance, tangentialAccelVariance;
Vector2f gravity;
GLfloat particleLifespan, particleLifespanVariance;
Color4f startColor, startColorVariance;
Color4f finishColor, finishColorVariance;
GLfloat startParticleSize, startParticleSizeVariance;
GLfloat finishParticleSize, finishParticleSizeVariance;
GLuint maxParticles;
GLint particleCount;
GLfloat emissionRate;
GLfloat emitCounter;
GLfloat elapsedTime;
GLfloat duration;
GLfloat rotationStart, rotationStartVariance;
GLfloat rotationEnd, rotationEndVariance;
int blendFuncSource, blendFuncDestination;
//////////////////// Particle ivars only used when a maxRadius value is provided. These values are used for
//////////////////// the special purpose of creating the spinning portal emitter
GLfloat maxRadius; // Max radius at which particles are drawn when rotating
GLfloat maxRadiusVariance; // Variance of the maxRadius
GLfloat radiusSpeed; // The speed at which a particle moves from maxRadius to minRadius
GLfloat minRadius; // Radius from source below which a particle dies
GLfloat minRadiusVariance; // Variance of the minRadius
GLfloat rotatePerSecond; // Numeber of degress to rotate a particle around the source pos per second
GLfloat rotatePerSecondVariance; // Variance in degrees for rotatePerSecond
//////////////////// Particle Emitter iVars
BOOL active;
BOOL useTexture;
GLint particleIndex; // Stores the number of particles that are going to be rendered
GLint vertexIndex; // Stores the index of the vertices being used for each particle
///////////////////// Render
GLuint verticesID; // Holds the buffer name of the VBO that stores the color and vertices info for the particles
GLuint vertexObjectID;
Particle *particles; // Array of particles that hold the particle emitters particle details
ParticleQuad *quads; // Array holding quad information for each particle;
GLushort *indices; // Array holding an index reference into an array of quads for rendering
}
@property(nonatomic, assign) Vector2f sourcePosition;
@property(nonatomic, assign) GLint particleCount;
@property(nonatomic, assign) BOOL active;
@property(nonatomic, assign) GLfloat duration;
// Initialises a particle emitter using configuration read from a file
- (id)initParticleEmitterWithFile:(NSString*)aFileName;
// Renders the particles for this emitter to the screen
- (void)renderParticles;
// Updates all particles in the particle emitter
- (void)updateWithDelta:(GLfloat)aDelta;
// Stops the particle emitter
- (void)stopParticleEmitter;
@end