Oolite
Loading...
Searching...
No Matches
OOParticleSystem Class Reference

#include <OOParticleSystem.h>

Inheritance diagram for OOParticleSystem:
Collaboration diagram for OOParticleSystem:

Instance Methods

(id) - initWithPosition:velocity:count:minSpeed:maxSpeed:duration:baseColor:
(OOTexture *) - texture
(id) - init [implementation]
(NSString *) - descriptionComponents [implementation]
(BOOL) - canCollide [implementation]
(BOOL) - checkCloseCollisionWith: [implementation]
(void) - update: [implementation]
(void) - drawImmediate:translucent: [implementation]
(BOOL) - isEffect [implementation]
Instance Methods inherited from Entity
(NSUInteger) - sessionID
(BOOL) - isShip
(BOOL) - isDock
(BOOL) - isStation
(BOOL) - isSubEntity
(BOOL) - isPlayer
(BOOL) - isPlanet
(BOOL) - isSun
(BOOL) - isSunlit
(BOOL) - isStellarObject
(BOOL) - isSky
(BOOL) - isWormhole
(BOOL) - isVisualEffect
(BOOL) - isWaypoint
(BOOL) - validForAddToUniverse
(void) - addToLinkedLists
(void) - removeFromLinkedLists
(void) - updateLinkedLists
(void) - wasAddedToUniverse
(void) - wasRemovedFromUniverse
(void) - warnAboutHostiles
(CollisionRegion *) - collisionRegion
(void) - setCollisionRegion:
(void) - setUniversalID:
(OOUniversalID) - universalID
(BOOL) - throwingSparks
(void) - setThrowSparks:
(void) - throwSparks
(void) - setOwner:
(id) - owner
(ShipEntity *) - parentEntity
(ShipEntity *) - rootShipEntity
(void) - setPosition:
(void) - setPositionX:y:z:
(HPVector) - position
(Vector) - cameraRelativePosition
(GLfloat) - cameraRangeFront
(GLfloat) - cameraRangeBack
(void) - updateCameraRelativePosition
(Vector) - vectorTo:
(HPVector) - absolutePositionForSubentity
(HPVector) - absolutePositionForSubentityOffset:
(double) - zeroDistance
(double) - camZeroDistance
(NSComparisonResult) - compareZeroDistance:
(BoundingBox) - boundingBox
(GLfloat) - mass
(Quaternion) - orientation
(void) - setOrientation:
(Quaternion) - normalOrientation
(void) - setNormalOrientation:
(void) - orientationChanged
(void) - setVelocity:
(Vector) - velocity
(double) - speed
(GLfloat) - distanceTravelled
(void) - setDistanceTravelled:
(void) - setStatus:
(OOEntityStatus) - status
(void) - setScanClass:
(OOScanClass) - scanClass
(void) - setEnergy:
(GLfloat) - energy
(void) - setMaxEnergy:
(GLfloat) - maxEnergy
(void) - applyRoll:andClimb:
(void) - applyRoll:climb:andYaw:
(void) - moveForward:
(OOMatrix) - rotationMatrix
(OOMatrix) - drawRotationMatrix
(OOMatrix) - transformationMatrix
(OOMatrix) - drawTransformationMatrix
(GLfloat) - collisionRadius
(GLfloat) - frustumRadius
(void) - setCollisionRadius:
(NSMutableArray *) - collisionArray
(void) - applyVelocity:
(void) - takeEnergyDamage:from:becauseOf:weaponIdentifier:
(void) - dumpState
(void) - dumpSelfState
(NSUInteger) - lastDrawCounter
(void) - setLastDrawCounter:
(double) - findCollisionRadius
(BOOL) - isVisible
(BOOL) - isInSpace
(BOOL) - isImmuneToBreakPatternHide
(GLfloat) - universalTime
(GLfloat) - spawnTime
(GLfloat) - timeElapsedSinceSpawn
(void) - setAtmosphereFogging:
(OOColor *) - fogUniform
(void) - dealloc [implementation]
(BOOL) - checkLinkedLists [implementation]
(id< OOWeakReferenceSupport >) - superShaderBindingTarget [implementation]
(Vector) - relativePosition [implementation]
(void) - subEntityReallyDied: [implementation]
(BOOL) - isBreakPattern
(BOOL) - isECMBlast
(BOOL) - isExhaust
(BOOL) - isFlasher
(BOOL) - isVisibleToScripts
(BOOL) - isVisibleToScripts
(NSString *) - oo_jsClassName
(NSString *) - oo_jsClassName
(void) - getJSClass:andPrototype:
(void) - deleteJSSelf
(void) - deleteJSSelf
(JSClassID) - oo_jsClassID
(jsval) - oo_jsValueInContext: [implementation]
(BOOL) - isCascadeWeapon
(BOOL) - isPlayerLikeShip
(GLfloat) - clock [implementation]
(unsigned) - pseudoFixedD100 [implementation]
(unsigned) - pseudoFixedD256 [implementation]
(unsigned) - systemGovernment [implementation]
(unsigned) - systemEconomy [implementation]
(unsigned) - systemTechLevel [implementation]
(unsigned) - systemPopulation [implementation]
(unsigned) - systemProductivity [implementation]
(BOOL) - isShipWithSubEntityShip:
(void) - drawSubEntityImmediate:translucent: [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED

Protected Attributes

Vector _particlePosition [kFragmentBurstMaxParticles]
Vector _particleVelocity [kFragmentBurstMaxParticles]
GLfloat _particleColor [kFragmentBurstMaxParticles][4]
GLfloat _particleSize [kFragmentBurstMaxParticles]
unsigned _count
unsigned _particleType
OOTimeDelta _timePassed
OOTimeDelta _duration
double _maxSpeed
Protected Attributes inherited from Entity
HPVector lastPosition
Quaternion lastOrientation
GLfloat distanceTravelled
OOMatrix rotMatrix
Vector velocity
GLfloat energy
GLfloat maxEnergy
BoundingBox boundingBox
GLfloat mass
NSMutableArray * collidingEntities
OOTimeAbsolute spawnTime
struct JSObject * _jsSelf
NSUInteger lastDrawCounter
Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Additional Inherited Members

Public Attributes inherited from Entity
OOUniversalID universalID
unsigned isShip: 1
unsigned isStation: 1
unsigned isPlayer: 1
unsigned isWormhole: 1
unsigned isSubEntity: 1
unsigned hasMoved: 1
unsigned hasRotated: 1
unsigned hasCollided: 1
unsigned isSunlit: 1
unsigned collisionTestFilter: 2
unsigned throw_sparks: 1
unsigned isImmuneToBreakPatternHide: 1
unsigned isExplicitlyNotMainStation: 1
unsigned isVisualEffect: 1
OOScanClass scanClass
GLfloat zero_distance
GLfloat cam_zero_distance
GLfloat no_draw_distance
GLfloat collision_radius
HPVector position
Vector cameraRelativePosition
Quaternion orientation
OOColor * atmosphereFogging
int zero_index
Entity * x_previous
Entity * x_next
Entity * y_previous
Entity * y_next
Entity * z_previous
Entity * z_next
Entity * collision_chain
OOUniversalID shadingEntityID
Entity * collider
CollisionRegion * collisionRegion

Detailed Description

Definition at line 38 of file OOParticleSystem.h.

Method Documentation

◆ canCollide

- (BOOL) canCollide
implementation

Reimplemented from Entity.

Definition at line 92 of file OOParticleSystem.m.

93{
94 return NO;
95}

References canCollide.

Referenced by canCollide.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCloseCollisionWith:

- (BOOL) checkCloseCollisionWith: (Entity*) other
implementation

Reimplemented from Entity.

Definition at line 97 of file OOParticleSystem.m.

97 :(Entity*)other
98{
99 if (other == [self owner])
100 return NO;
101 return ![other isEffect];
102}
BOOL isEffect()
Definition Entity.m:180
id owner()
Definition Entity.m:548

References Entity::isEffect, and Entity::owner.

Here is the call graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from Entity.

Definition at line 87 of file OOParticleSystem.m.

88{
89 return [NSString stringWithFormat:@"ttl: %.3fs", _duration - _timePassed];
90}

References descriptionComponents.

Referenced by descriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawImmediate:translucent:

- (void) drawImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from Entity.

Definition at line 136 of file OOParticleSystem.m.

136 :(bool)immediate translucent:(bool)translucent
137{
138 if (!translucent || [UNIVERSE breakPatternHide])
139 return;
140
143
144 OOGL(glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT));
145
146 OOGL(glEnable(GL_TEXTURE_2D));
147 OOGL(glEnable(GL_BLEND));
148 OOGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
149 [[self texture] apply];
150
151 HPVector viewPosition = [PLAYER viewpointPosition];
152 HPVector selfPosition = [self position];
153
154 unsigned i, count = _count;
155 Vector* particlePosition = _particlePosition;
156 GLfloat(*particleColor)[4] = _particleColor;
157 GLfloat* particleSize = _particleSize;
158
159 if ([UNIVERSE reducedDetail]) {
160 // Quick rendering - particle cloud is effectively a 2D billboard.
162 OOGLMultModelView(OOMatrixForBillboard(selfPosition, viewPosition));
163
164 OOGLBEGIN(GL_QUADS);
165 for (i = 0; i < count; i++) {
166 glColor4fv(particleColor[i]);
167 DrawQuadForView(particlePosition[i].x, particlePosition[i].y, particlePosition[i].z, particleSize[i]);
168 }
169 OOGLEND();
170
172 } else {
173 float distanceThreshold = collision_radius * 2.0f; // Distance between player and middle of effect where we start to transition to "non-fast rendering."
174 float thresholdSq = distanceThreshold * distanceThreshold;
175 float distanceSq = cam_zero_distance;
176
177 if (distanceSq > thresholdSq) {
178 /* Semi-quick rendering - particle positions are volumetric, but
179 orientation is shared. This can cause noticeable distortion
180 if the player is close to the centre of the cloud.
181 */
182 OOMatrix bbMatrix = OOMatrixForBillboard(selfPosition, viewPosition);
183
184 for (i = 0; i < count; i++) {
186 OOGLTranslateModelView(particlePosition[i]);
187 OOGLMultModelView(bbMatrix);
188
189 glColor4fv(particleColor[i]);
190 OOGLBEGIN(GL_QUADS);
191 DrawQuadForView(0, 0, 0, particleSize[i]);
192 OOGLEND();
193
195 }
196 } else {
197 /* Non-fast rendering - each particle is billboarded individually.
198 The "individuality" factor interpolates between this behavior
199 and "semi-quick" to avoid jumping at the boundary.
200 */
201 float individuality = 3.0f * (1.0f - distanceSq / thresholdSq);
202 individuality = OOClamp_0_1_f(individuality);
203
204 for (i = 0; i < count; i++) {
206 OOGLTranslateModelView(particlePosition[i]);
207 OOGLMultModelView(OOMatrixForBillboard(HPvector_add(selfPosition, vectorToHPVector(vector_multiply_scalar(particlePosition[i], individuality))), viewPosition));
208
209 glColor4fv(particleColor[i]);
210 OOGLBEGIN(GL_QUADS);
211 DrawQuadForView(0, 0, 0, particleSize[i]);
212 OOGLEND();
213
215 }
216 }
217 }
218
219 OOGL(glPopAttrib());
220
222 OOCheckOpenGLErrors(@"OOParticleSystem after drawing %@", self);
223}
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
struct HPVector HPVector
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
#define OO_ENTER_OPENGL()
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
Definition OOMatrix.m:186
struct OOMatrix OOMatrix
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
#define DrawQuadForView(x, y, z, sz)
unsigned count
float y
float x
struct Vector Vector
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
#define UNIVERSE
Definition Universe.h:827
GLfloat collision_radius
Definition Entity.h:107
GLfloat cam_zero_distance
Definition Entity.h:105
GLfloat _particleSize[kFragmentBurstMaxParticles]
GLfloat _particleColor[kFragmentBurstMaxParticles][4]
Vector _particlePosition[kFragmentBurstMaxParticles]

References _count, _particleColor, _particlePosition, _particleSize, OOTexture::apply, Entity::cam_zero_distance, Entity::collision_radius, count, DrawQuadForView, HPvector_add(), OO_ENTER_OPENGL, OOCheckOpenGLErrors(), OOClamp_0_1_f(), OOGL, OOGLBEGIN, OOGLEND, OOGLMultModelView(), OOGLPopModelView(), OOGLPushModelView(), OOGLTranslateModelView(), OOMatrixForBillboard(), OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_ADDITIVE_BLENDING, Entity::position, texture, UNIVERSE, vector_multiply_scalar(), vectorToHPVector(), x, and y.

Here is the call graph for this function:

◆ init

- (id) init
implementation

Reimplemented from Entity.

Definition at line 39 of file OOParticleSystem.m.

40{
41 [self release];
42 return nil;
43}
return nil

References init, and nil.

Referenced by init, and initWithPosition:velocity:count:minSpeed:maxSpeed:duration:baseColor:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithPosition:velocity:count:minSpeed:maxSpeed:duration:baseColor:

- (id) initWithPosition: (HPVector) position
velocity: (Vector) velocity
count: (unsigned) count
minSpeed: (float) minSpeed
maxSpeed: (float) maxSpeed
duration: (OOTimeDelta) duration
baseColor: (GLfloat[4]) baseColor 

Definition at line 48 of file OOParticleSystem.m.

48 :(HPVector)pos
49 velocity:(Vector)vel
50 count:(unsigned)count
51 minSpeed:(float)minSpeed
52 maxSpeed:(float)maxSpeed
53 duration:(OOTimeDelta)duration
54 baseColor:(GLfloat[4])baseColor
55{
56 NSParameterAssert(count <= kFragmentBurstMaxParticles);
57
58 if ((self = [super init])) {
59 _count = count;
60 [self setPosition:pos];
61
62 velocity = vel;
63 _duration = duration;
65
66 for (unsigned i = 0; i < count; i++) {
67 GLfloat speed = minSpeed + 0.5f * (randf() + randf()) * (maxSpeed - minSpeed); // speed tends toward middle of range
69
70 Vector color = make_vector(baseColor[0] * 0.1f * (9.5f + randf()), baseColor[1] * 0.1f * (9.5f + randf()), baseColor[2] * 0.1f * (9.5f + randf()));
71 color = vector_normal(color);
72 _particleColor[i][0] = color.x;
73 _particleColor[i][1] = color.y;
74 _particleColor[i][2] = color.z;
75 _particleColor[i][3] = baseColor[3];
76
78 }
79
80 [self setStatus:STATUS_EFFECT];
81 scanClass = CLASS_NO_DRAW;
82 }
83
84 return self;
85}
@ kFragmentBurstMaxParticles
float maxSpeed
GLfloat baseColor[4]
double OOTimeDelta
Definition OOTypes.h:193
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
Vector OORandomUnitVector(void)
Definition OOVector.m:76
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
OOScanClass scanClass
Definition Entity.m:743
Vector velocity
Definition Entity.m:708
double speed()
Definition Entity.m:713
Vector _particleVelocity[kFragmentBurstMaxParticles]
OOTimeDelta _duration
float randf(void)
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References _count, _duration, _maxSpeed, _particleColor, _particleSize, _particleVelocity, baseColor, count, init, kFragmentBurstMaxParticles, make_vector(), maxSpeed, OORandomUnitVector(), randf(), Entity::scanClass, Entity::setPosition:, Entity::setStatus:, Entity::speed, vector_multiply_scalar(), vector_normal(), Entity::velocity, Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ isEffect

- (BOOL) isEffect
implementation

Reimplemented from Entity.

Definition at line 225 of file OOParticleSystem.m.

226{
227 return YES;
228}

References isEffect.

Referenced by isEffect.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ texture

- (OOTexture *) texture

Reimplemented in OOExplosionCloudEntity.

Definition at line 230 of file OOParticleSystem.m.

References OOLightParticleEntity::defaultParticleTexture, and texture.

Referenced by drawImmediate:translucent:, and texture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update:

- (void) update: (OOTimeDelta) delta_t
implementation

Reimplemented from Entity.

Reimplemented in OOBigFragmentBurstEntity, OOExplosionCloudEntity, and OOSmallFragmentBurstEntity.

Definition at line 104 of file OOParticleSystem.m.

104 :(OOTimeDelta)delta_t
105{
106 [super update:delta_t];
107
108 _timePassed += delta_t;
109 collision_radius += delta_t * _maxSpeed;
110
111 unsigned i, count = _count;
112 Vector* particlePosition = _particlePosition;
113 Vector* particleVelocity = _particleVelocity;
114
115 for (i = 0; i < count; i++) {
116 particlePosition[i] = vector_add(particlePosition[i], vector_multiply_scalar(particleVelocity[i], delta_t));
117 }
118
119 // disappear eventually.
121 [UNIVERSE removeEntity:self];
122}
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOTimeDelta _timePassed

References _count, _duration, _maxSpeed, _particlePosition, _particleVelocity, _timePassed, Entity::collision_radius, count, Entity::update:, vector_add(), and vector_multiply_scalar().

Referenced by OOBigFragmentBurstEntity::update:, OOExplosionCloudEntity::update:, and OOSmallFragmentBurstEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _count

◆ _duration

◆ _maxSpeed

- (double) _maxSpeed
protected

◆ _particleColor

◆ _particlePosition

- (Vector _particlePosition[kFragmentBurstMaxParticles])
protected

Definition at line 40 of file OOParticleSystem.h.

Referenced by drawImmediate:translucent:, and update:.

◆ _particleSize

◆ _particleType

- (unsigned) _particleType
protected

Definition at line 46 of file OOParticleSystem.h.

◆ _particleVelocity

- (Vector _particleVelocity[kFragmentBurstMaxParticles])
protected

◆ _timePassed


The documentation for this class was generated from the following files: