Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOExplosionCloudEntity(OOPrivate) Category Reference

Instance Methods

(id) - initExplosionCloudWithEntity:size:andSettings:
 

Detailed Description

Definition at line 52 of file OOExplosionCloudEntity.m.

Method Documentation

◆ initExplosionCloudWithEntity:size:andSettings:

- (id) initExplosionCloudWithEntity: (Entity *) entity
size: (float) size
andSettings: (NSDictionary *) settings 

Extends class OOExplosionCloudEntity.

Definition at line 49 of file OOExplosionCloudEntity.m.

58 :(Entity *)entity size:(float)size andSettings:(NSDictionary *)settings
59{
60 unsigned i;
61 unsigned maxCount = [UNIVERSE detailLevel] <= DETAIL_LEVEL_SHADERS ? 10 : 25;
62 HPVector pos = [entity position];
63 Vector vel = [entity velocity];
64
65 if (settings == nil) {
66 _settings = [[NSDictionary dictionary] retain];
67 } else {
68 _settings = [settings retain];
69 }
70
71 unsigned count = [_settings oo_unsignedIntForKey:kExplosionCount defaultValue:25];
72 if (count > maxCount) {
73 count = maxCount;
74 }
75
76 if (size == 0.0) {
77 size = [entity collisionRadius]*[_settings oo_floatForKey:kExplosionSize defaultValue:kExplosionDefaultSize];
78 }
79
80 _growthRate = [_settings oo_floatForKey:kExplosionGrowth defaultValue:kGrowthRateFactor] * size;
81 _alpha = [_settings oo_floatForKey:kExplosionAlpha defaultValue:kExplosionCloudAlpha];
82 _brightnessMult = [_settings oo_floatForKey:kExplosionBrightness defaultValue:kExplosionBrightnessMult];
83 if (_brightnessMult < 1.0f) _brightnessMult = 1.0f;
84 _cloudDuration = [_settings oo_doubleForKey:kExplosionDuration defaultValue:kExplosionCloudDuration];
85
86 GLfloat spread = [_settings oo_floatForKey:kExplosionSpread defaultValue:1.0];
87
88 NSString *textureFile = [_settings oo_stringForKey:kExplosionTexture defaultValue:@"oolite-particle-cloud2.png"];
89
90 _texture = [[OOTexture textureWithName:textureFile
91 inFolder:@"Textures"
92 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
93 anisotropy:kOOTextureDefaultAnisotropy
94 lodBias:0.0] retain];
95 if (_texture == nil)
96 {
97 [self release];
98 return nil;
99 }
100
101 GLfloat baseColor[4] = {1.0,1.0,1.0,1.0};
102
103 if (magnitude2(vel) > 1000000)
104 {
105 // slow down rapidly translating explosions
106 vel = vector_multiply_scalar(vector_normal(vel),1000);
107 }
108
109 if ((self = [super initWithPosition:pos velocity:vel count:count minSpeed:size*0.8f*spread maxSpeed:size*1.2f*spread duration:_cloudDuration baseColor:baseColor]))
110 {
111 NSString *color_order = [_settings oo_stringForKey:kExplosionColors defaultValue:@"rgb"];
112
113 for (i=0;i<count;i++)
114 {
115 if ([color_order isEqualToString:@"white"]) {
116 // grey
117 _particleColor[i][0] = _particleColor[i][1] = _particleColor[i][2] = randf();
118 } else {
119 float c1 = randf();
120 float c2 = randf();
121 float c3 = randf();
122 if (c2 > c1) {
123 c2 = c1;
124 }
125 if (c3 > c2) {
126 c3 = c2;
127 }
128 if ([color_order isEqualToString:@"rgb"])
129 {
130 _particleColor[i][0] = c1;
131 _particleColor[i][1] = c2;
132 _particleColor[i][2] = c3;
133 }
134 else if ([color_order isEqualToString:@"rbg"])
135 {
136 _particleColor[i][0] = c1;
137 _particleColor[i][1] = c3;
138 _particleColor[i][2] = c2;
139 }
140 else if ([color_order isEqualToString:@"grb"])
141 {
142 _particleColor[i][0] = c2;
143 _particleColor[i][1] = c1;
144 _particleColor[i][2] = c3;
145 }
146 else if ([color_order isEqualToString:@"gbr"])
147 {
148 _particleColor[i][0] = c3;
149 _particleColor[i][1] = c1;
150 _particleColor[i][2] = c2;
151 }
152 else if ([color_order isEqualToString:@"brg"])
153 {
154 _particleColor[i][0] = c2;
155 _particleColor[i][1] = c3;
156 _particleColor[i][2] = c1;
157 }
158 else if ([color_order isEqualToString:@"bgr"])
159 {
160 _particleColor[i][0] = c3;
161 _particleColor[i][1] = c2;
162 _particleColor[i][2] = c1;
163 }
164
165 }
166
167 _particleColor[i][0] *= _brightnessMult;
168 _particleColor[i][1] *= _brightnessMult;
169 _particleColor[i][2] *= _brightnessMult;
170 _particleColor[i][3] = _alpha;
171 }
172 }
173 return self;
174}
float maxSpeed
GLfloat baseColor[4]
unsigned count
return nil
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:246
GLfloat collisionRadius()
Definition Entity.m:905
HPVector position
Definition Entity.h:112
Vector velocity
Definition Entity.h:140
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:134
voidpf void uLong size
Definition ioapi.h:134
float randf(void)

The documentation for this category was generated from the following file: