Oolite
Loading...
Searching...
No Matches
OOExhaustPlumeEntity.m
Go to the documentation of this file.
1/*
2
3OOExhaustPlumeEntity.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#import "MyOpenGLView.h"
29#import "OOMacroOpenGL.h"
30#import "PlayerEntity.h"
31#import "ShipEntity.h"
32#import "Universe.h"
33
35#import "OOTexture.h"
36
37#define kOverallAlpha 1.0f
38#define kTimeStep 0.05f
39#define kFadeLevel1 0.4f
40#define kFadeLevel2 0.2f
41#define kFadeLevel3 0.02f
42#define kScaleLevel1 1.0f
43#define kScaleLevel2 0.8f
44#define kScaleLevel3 0.6f
45
47
48@interface OOExhaustPlumeEntity (Private)
49
50- (void)saveToLastFrame;
51- (Frame)frameAtTime:(double)t_frame fromFrame:(Frame)frame_zero; // t_frame is relative to now ie. -0.5 = half a second ago.
52
53@end
54
55@implementation OOExhaustPlumeEntity
56
57+ (id)exhaustForShip:(ShipEntity*)ship withDefinition:(NSArray*)definition andScale:(float)scale
58{
59 return [[[self alloc] initForShip:ship withDefinition:definition andScale:(float)scale] autorelease];
60}
61
62- (id)initForShip:(ShipEntity*)ship withDefinition:(NSArray*)definition andScale:(float)scaleFactor
63{
64 if ([definition count] == 0) {
65 [self release];
66 return nil;
67 }
68
69 if ((self = [super init])) {
70 [self setOwner:ship];
71 HPVector pos = { [definition oo_floatAtIndex:0] * scaleFactor, [definition oo_floatAtIndex:1] * scaleFactor, [definition oo_floatAtIndex:2] * scaleFactor };
72 [self setPosition:pos];
73 // scale.z is special and *not* multiplied by scaleFactor
74 Vector scale = { [definition oo_floatAtIndex:3] * scaleFactor, [definition oo_floatAtIndex:4] * scaleFactor, [definition oo_floatAtIndex:5] };
75 [self setScale:scale];
76 }
77
78 return self;
79}
80
82{
83 return _exhaustScale;
84}
85
86- (void)setScale:(Vector)scale
87{
89 if (scale.z < 0.5 || scale.z > 2.0) {
90 _exhaustScale.z = 1.0;
91 }
92}
93
94- (BOOL)isExhaust
95{
96 return YES;
97}
98
100{
101 return collision_radius;
102}
103
104- (void)update:(OOTimeDelta)delta_t
105{
106 // Profiling: this function and subfunctions are expensive - CIM
107
108 // don't draw if there's no ship, or if we're just jumping out of witchspace/docked at a station!
109 ShipEntity* ship = [self owner];
110 // also don't draw if the ship isn't visible
111 if (EXPECT_NOT(ship == nil || ![ship isVisible] || ([ship isPlayer] && [ship suppressFlightNotifications])))
112 return;
113
114 OOTimeAbsolute now = [UNIVERSE getTime];
115 if ([UNIVERSE getTime] > _trackTime + kTimeStep) {
116 [self saveToLastFrame];
117 _trackTime = now;
118 }
119
120 // GLfloat ex_emissive[4] = {0.7f, 0.9, 1.0f, 0.9f * kOverallAlpha}; // pale blue - old definition
122 GLfloat length;
123 HPVector vertex;
124 GLfloat ex_emissive[4];
125 [[ship exhaustEmissiveColor] getRed:&ex_emissive[0] green:&ex_emissive[1] blue:&ex_emissive[2] alpha:&ex_emissive[3]];
126 const GLfloat s1[8] = { 0.0, M_SQRT1_2, 1.0, M_SQRT1_2, 0.0, -M_SQRT1_2, -1.0, -M_SQRT1_2 };
127 const GLfloat c1[8] = { 1.0, M_SQRT1_2, 0.0, -M_SQRT1_2, -1.0, -M_SQRT1_2, 0.0, M_SQRT1_2 };
128
129 Quaternion shipQrotation = [ship normalOrientation];
130
131 Frame zero = {
132 .timeframe = [UNIVERSE getTime],
133 .orientation = shipQrotation,
134 .k = [ship forwardVector]
135 };
136 int dam = [ship damage];
137
138 GLfloat speed = [ship speedFactor];
139 // don't draw if not moving.
140 if (EXPECT_NOT(speed <= 0.001f))
141 return;
142
143 GLfloat hyper_fade = 8.0f / (8.0f + speed * speed * speed);
144
145 GLfloat flare_factor = fmaxf(speed, 1.0) * ex_emissive[3] * hyper_fade;
146 GLfloat red_factor = speed * ex_emissive[0] * (ranrot_rand() % 11) * 0.1f; // random fluctuations
147 GLfloat green_factor = speed * ex_emissive[1] * hyper_fade;
148
149 if (speed > 1.0f) // afterburner!
150 {
151 red_factor = 1.5;
152 }
153
154 if ((int)(ranrot_rand() % 50) < dam - 50) // flicker the damaged engines
155 red_factor = 0.0;
156 if ((int)(ranrot_rand() % 40) < dam - 60)
157 green_factor = 0.0;
158 if ((int)(ranrot_rand() % 25) < dam - 75)
159 flare_factor = 0.0;
160
161 HPVector currentPos = ship->position;
162 Vector vfwd = [ship forwardVector];
163 GLfloat spd = 0.5f * [ship flightSpeed];
164 vfwd = vector_multiply_scalar(vfwd, spd);
165 Vector master_i = [ship rightVector];
166 Vector vi, vj, vk;
167 vi = master_i;
168 vj = [ship upVector];
169 vk = [ship forwardVector];
170 zero.position = make_HPvector(currentPos.x + vi.x * position.x + vj.x * position.y + vk.x * position.z,
171 currentPos.y + vi.y * position.x + vj.y * position.y + vk.y * position.z,
172 currentPos.z + vi.z * position.x + vj.z * position.y + vk.z * position.z);
173
174 GLfloat speedScale = fminf(1.0f, speed * 5.0f);
175
176 GLfloat exhaust_factor = _exhaustScale.z;
177 GLfloat i01 = -0.00f * hyper_fade;
178 GLfloat i03 = -0.12f * exhaust_factor;
179 GLfloat i06 = -0.25f * exhaust_factor;
180 GLfloat i08 = -0.32f * exhaust_factor;
181 GLfloat i10 = -0.40f * exhaust_factor;
182 GLfloat q01 = i01 / i10; // factor for trail
183 GLfloat q03 = i03 / i10;
184 GLfloat q06 = i06 / i10;
185 GLfloat q08 = i08 / i10;
186 GLfloat r01 = 1.0f - q01; // factor for jet
187 GLfloat r03 = 1.0f - q03;
188 GLfloat r06 = 1.0f - q06;
189 GLfloat r08 = 1.0f - q08;
190 Frame f01 = [self frameAtTime:i01 fromFrame:zero];
191 Vector b01 = make_vector(r01 * i01 * vfwd.x, r01 * i01 * vfwd.y, r01 * i01 * vfwd.z);
192 Frame f03 = [self frameAtTime:i03 fromFrame:zero];
193 Vector b03 = make_vector(r03 * i03 * vfwd.x, r03 * i03 * vfwd.y, r03 * i03 * vfwd.z);
194 Frame f06 = [self frameAtTime:i06 fromFrame:zero];
195 Vector b06 = make_vector(r06 * i06 * vfwd.x, r06 * i06 * vfwd.y, r06 * i06 * vfwd.z);
196 Frame f08 = [self frameAtTime:i08 fromFrame:zero];
197 Vector b08 = make_vector(r08 * i08 * vfwd.x, r08 * i08 * vfwd.y, r08 * i08 * vfwd.z);
198 Frame f10 = [self frameAtTime:i10 fromFrame:zero];
199
200 int ci = 0;
201 int iv = 0;
202 int i;
203 float r1;
204
205 // f01.position = vector_subtract(zero.position, vk); // 1m out from zero
206 f01.position = zero.position;
207
208 ex_emissive[3] = flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust
209 ex_emissive[1] = green_factor; // diminish green part towards rear of exhaust
210 ex_emissive[0] = red_factor; // diminish red part towards rear of exhaust
211 vertex = HPvector_add(f01.position, vectorToHPVector(b01));
212 collision_radius = HPmagnitude(HPvector_subtract(vertex, currentPos));
213 _vertices[iv++] = vertex.x; // + zero.k.x * flare_factor * 4.0;
214 _vertices[iv++] = vertex.y; // + zero.k.y * flare_factor * 4.0;
215 _vertices[iv++] = vertex.z; // + zero.k.z * flare_factor * 4.0;
216 _exhaustBaseColors[ci++] = ex_emissive[0];
217 _exhaustBaseColors[ci++] = ex_emissive[1];
218 _exhaustBaseColors[ci++] = ex_emissive[2];
219 _exhaustBaseColors[ci++] = ex_emissive[3];
220
221 Vector k1 = f01.k;
222 Vector j1 = cross_product(master_i, k1);
223 Vector i1 = vector_multiply_scalar(cross_product(j1, k1), _exhaustScale.x * speedScale);
224 j1 = vector_multiply_scalar(j1, _exhaustScale.y * speedScale);
225
226 for (i = 0; i < 8; i++) {
227 vertex = HPvector_add(f01.position,
230 vector_multiply_scalar(j1, c1[i])))));
231 length = HPmagnitude(HPvector_subtract(vertex, currentPos));
232 if (length > collision_radius) {
233 collision_radius = length;
234 }
235 _vertices[iv++] = vertex.x;
236 _vertices[iv++] = vertex.y;
237 _vertices[iv++] = vertex.z;
238 _exhaustBaseColors[ci++] = ex_emissive[0];
239 _exhaustBaseColors[ci++] = ex_emissive[1];
240 _exhaustBaseColors[ci++] = ex_emissive[2];
241 _exhaustBaseColors[ci++] = ex_emissive[3];
242 }
243
244 ex_emissive[3] = kFadeLevel1 * flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust
245 ex_emissive[1] = kFadeLevel1 * green_factor; // diminish green part towards rear of exhaust
246 ex_emissive[0] = kFadeLevel1 * red_factor; // diminish red part towards rear of exhaust
247
248 k1 = f03.k;
249 i1 = vector_multiply_scalar(cross_product(j1, k1), _exhaustScale.x * kScaleLevel1 * speedScale);
250 j1 = vector_multiply_scalar(cross_product(master_i, k1), _exhaustScale.y * kScaleLevel1 * speedScale);
251 for (i = 0; i < 8; i++) {
252 r1 = randf();
253 vertex = HPvector_add(f03.position,
257 vector_multiply_scalar(k1, r1))))));
258 length = HPmagnitude(HPvector_subtract(vertex, currentPos));
259 if (length > collision_radius) {
260 collision_radius = length;
261 }
262 _vertices[iv++] = vertex.x;
263 _vertices[iv++] = vertex.y;
264 _vertices[iv++] = vertex.z;
265 _exhaustBaseColors[ci++] = ex_emissive[0];
266 _exhaustBaseColors[ci++] = ex_emissive[1];
267 _exhaustBaseColors[ci++] = ex_emissive[2];
268 _exhaustBaseColors[ci++] = ex_emissive[3];
269 }
270
271 ex_emissive[3] = kFadeLevel2 * flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust
272 ex_emissive[1] = kFadeLevel2 * green_factor; // diminish green part towards rear of exhaust
273 ex_emissive[0] = kFadeLevel2 * red_factor; // diminish red part towards rear of exhaust
274
275 k1 = f06.k;
276 i1 = vector_multiply_scalar(cross_product(j1, k1), 0.8f * _exhaustScale.x * kScaleLevel2 * speedScale);
277 j1 = vector_multiply_scalar(cross_product(master_i, k1), 0.8f * _exhaustScale.y * kScaleLevel2 * speedScale);
278 for (i = 0; i < 8; i++) {
279 r1 = randf();
280 vertex = HPvector_add(f06.position,
284 vector_multiply_scalar(k1, r1))))));
285 length = HPmagnitude(HPvector_subtract(vertex, currentPos));
286 if (length > collision_radius) {
287 collision_radius = length;
288 }
289 _vertices[iv++] = vertex.x;
290 _vertices[iv++] = vertex.y;
291 _vertices[iv++] = vertex.z;
292 _exhaustBaseColors[ci++] = ex_emissive[0];
293 _exhaustBaseColors[ci++] = ex_emissive[1];
294 _exhaustBaseColors[ci++] = ex_emissive[2];
295 _exhaustBaseColors[ci++] = ex_emissive[3];
296 }
297
298 ex_emissive[3] = kFadeLevel3 * flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust
299 ex_emissive[1] = kFadeLevel3 * green_factor; // diminish green part towards rear of exhaust
300 ex_emissive[0] = kFadeLevel3 * red_factor; // diminish red part towards rear of exhaust
301 k1 = f08.k;
302 i1 = vector_multiply_scalar(cross_product(j1, k1), 0.5f * _exhaustScale.x * kScaleLevel3 * speedScale);
303 j1 = vector_multiply_scalar(cross_product(master_i, k1), 0.5f * _exhaustScale.y * kScaleLevel3 * speedScale);
304 for (i = 0; i < 8; i++) {
305 r1 = randf();
306 vertex = HPvector_add(f08.position,
310 vector_multiply_scalar(k1, r1))))));
311 length = HPmagnitude(HPvector_subtract(vertex, currentPos));
312 if (length > collision_radius) {
313 collision_radius = length;
314 }
315 _vertices[iv++] = vertex.x;
316 _vertices[iv++] = vertex.y;
317 _vertices[iv++] = vertex.z;
318 _exhaustBaseColors[ci++] = ex_emissive[0];
319 _exhaustBaseColors[ci++] = ex_emissive[1];
320 _exhaustBaseColors[ci++] = ex_emissive[2];
321 _exhaustBaseColors[ci++] = ex_emissive[3];
322 }
323
324 ex_emissive[3] = 0.0; // fade alpha towards rear of exhaust
325 ex_emissive[1] = 0.0; // diminish green part towards rear of exhaust
326 ex_emissive[0] = 0.0; // diminish red part towards rear of exhaust
327 length = HPmagnitude(HPvector_subtract(vertex, currentPos));
328 if (length > collision_radius) {
329 collision_radius = length;
330 }
331 _vertices[iv++] = f10.position.x;
332 _vertices[iv++] = f10.position.y;
333 _vertices[iv++] = f10.position.z;
334 _exhaustBaseColors[ci++] = ex_emissive[0];
335 _exhaustBaseColors[ci++] = ex_emissive[1];
336 _exhaustBaseColors[ci++] = ex_emissive[2];
337 _exhaustBaseColors[ci++] = ex_emissive[3];
338
339 (void)iv;
340 (void)ci; // Suppress Clang static analyzer warnings.
341}
342
343static GLuint tfan1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 1 }; // initial fan 0..9
344
345// normal polys
346static GLuint tstr1[9] = { 1, 5, 9, 13, 17, 21, 25, 29, 33 };
347static GLuint tstr2[9] = { 2, 6, 10, 14, 18, 22, 26, 30, 33 };
348static GLuint tstr3[9] = { 3, 7, 11, 15, 19, 23, 27, 31, 33 };
349static GLuint tstr4[9] = { 4, 8, 12, 16, 20, 24, 28, 32, 33 };
350
351// aft-view special polys
352static GLuint afttstr1[4] = { 1, 5, 25, 29 };
353static GLuint afttstr2[4] = { 2, 6, 26, 30 };
354static GLuint afttstr3[4] = { 3, 7, 27, 31 };
355static GLuint afttstr4[4] = { 4, 8, 28, 32 };
356
357static GLfloat pA[6] = { 0.01, 0.0, 2.0, 4.0, 6.0, 10.0 }; // phase adjustments
358
359- (void)drawSubEntityImmediate:(bool)immediate translucent:(bool)translucent
360{
361 if (!translucent)
362 return;
363
364 ShipEntity* ship = [self owner];
365 if ([ship speedFactor] <= 0.001f)
366 return; // don't draw if not moving according to 'update' calculation
367
370
373 // GLTranslateOOVector(vector_flip([self cameraRelativePosition]));
374 HPVector cam = [PLAYER viewpointPosition];
375 for (unsigned n = 0; n < 34 * 3; n++) {
376 switch (n % 3) {
377 case 0: // x coordinates
378 _glVertices[n] = (GLfloat)(_vertices[n] - cam.x);
379 break;
380 case 1: // y coordinates
381 _glVertices[n] = (GLfloat)(_vertices[n] - cam.y);
382 break;
383 case 2: // z coordinates
384 _glVertices[n] = (GLfloat)(_vertices[n] - cam.z);
385 break;
386 }
387 }
388
389 OOGL(glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT));
390
391 OOGL(glDisable(GL_LIGHTING));
392 OOGL(glEnable(GL_BLEND));
393 OOGL(glDepthMask(GL_FALSE));
394 OOGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
395 OOGL(glEnable(GL_TEXTURE_2D));
396 [[self texture] apply];
397
398 // OOGL(glDisable(GL_CULL_FACE)); // face culling
399 OOGL(glShadeModel(GL_SMOOTH));
400
401 OOGL(glEnableClientState(GL_COLOR_ARRAY));
402 OOGL(glVertexPointer(3, GL_FLOAT, 0, _glVertices));
403 OOGL(glColorPointer(4, GL_FLOAT, 0, _exhaustBaseColors));
404
405 double intpart, dphase = 1.0 - modf((double)[UNIVERSE getTime] * 2.5, &intpart);
406 GLfloat phase = (GLfloat)dphase;
407
408 GLfloat texCoords[68] = {
409 0.5,
410 phase + pA[0],
411
412 0.1,
413 phase + pA[1],
414 0.1,
415 phase + pA[1],
416 0.1,
417 phase + pA[1],
418 0.1,
419 phase + pA[1],
420 0.9,
421 phase + pA[1],
422 0.9,
423 phase + pA[1],
424 0.9,
425 phase + pA[1],
426 0.9,
427 phase + pA[1],
428
429 0.1,
430 phase + pA[2],
431 0.1,
432 phase + pA[2],
433 0.1,
434 phase + pA[2],
435 0.1,
436 phase + pA[2],
437 0.9,
438 phase + pA[2],
439 0.9,
440 phase + pA[2],
441 0.9,
442 phase + pA[2],
443 0.9,
444 phase + pA[2],
445
446 0.1,
447 phase + pA[3],
448 0.1,
449 phase + pA[3],
450 0.1,
451 phase + pA[3],
452 0.1,
453 phase + pA[3],
454 0.9,
455 phase + pA[3],
456 0.9,
457 phase + pA[3],
458 0.9,
459 phase + pA[3],
460 0.9,
461 phase + pA[3],
462
463 0.1,
464 phase + pA[4],
465 0.1,
466 phase + pA[4],
467 0.1,
468 phase + pA[4],
469 0.1,
470 phase + pA[4],
471 0.9,
472 phase + pA[4],
473 0.9,
474 phase + pA[4],
475 0.9,
476 phase + pA[4],
477 0.9,
478 phase + pA[4],
479
480 0.5,
481 phase + pA[5],
482 };
483 OOGL(glTexCoordPointer(2, GL_FLOAT, 0, texCoords));
484
485 // reduced detail for internal view to avoid rendering artefacts
486 if ([[self owner] isPlayer] && [UNIVERSE viewDirection] != VIEW_CUSTOM) {
487 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, afttstr1));
488 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, afttstr2));
489 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, afttstr3));
490 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, afttstr4));
491 } else {
492 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 9, GL_UNSIGNED_INT, tstr1));
493 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 9, GL_UNSIGNED_INT, tstr2));
494 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 9, GL_UNSIGNED_INT, tstr3));
495 OOGL(glDrawElements(GL_TRIANGLE_STRIP, 9, GL_UNSIGNED_INT, tstr4));
496 }
497
498 /* Need a different texture and color array for this segment */
499 GLfloat fanTextures[18] = {
500 0.5f, 0.0f + phase,
501 0.2f, 0.0f + phase,
502 0.2f, 0.1f + phase,
503 0.2f, 0.2f + phase,
504 0.2f, 0.3f + phase,
505 0.2f, 0.4f + phase,
506 0.2f, 0.3f + phase,
507 0.2f, 0.2f + phase,
508 0.2f, 0.1f + phase
509 };
510 OOGL(glTexCoordPointer(2, GL_FLOAT, 0, fanTextures));
511
512 GLfloat fanColors[36];
513 GLfloat fr = _exhaustBaseColors[0], fg = _exhaustBaseColors[1], fb = _exhaustBaseColors[2];
514 unsigned i = 0;
515 fanColors[i++] = fr;
516 fanColors[i++] = fg;
517 fanColors[i++] = fb;
518 fanColors[i++] = 1.0;
519 for (; i < 36;) {
520 fanColors[i++] = fr;
521 fanColors[i++] = fg;
522 fanColors[i++] = fb;
523 fanColors[i++] = 0.5;
524 }
525 OOGL(glColorPointer(4, GL_FLOAT, 0, fanColors));
526
527 OOGL(glDrawElements(GL_TRIANGLE_FAN, 10, GL_UNSIGNED_INT, tfan1));
528
529 OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
530 OOGL(glDisable(GL_TEXTURE_2D));
531
532 OOGL(glDisableClientState(GL_COLOR_ARRAY));
533
534 OOGL(glPopAttrib());
535
537}
538
539#define PREV(n) ((n + kExhaustFrameCount - 1) % kExhaustFrameCount)
540#define NEXT(n) ((n + 1) % kExhaustFrameCount)
541
543{
544 ShipEntity* ship = [self owner];
545
546 // Absolute position of self
547 // normally this would use the transformation matrix, but that
548 // introduces inaccuracies
549 // so just use the rotation matrix, then translate using HPVectors
550 HPVector framePos = OOHPVectorMultiplyMatrix([self position], [ship drawRotationMatrix]);
551 framePos = HPvector_add(framePos, [ship position]);
552 Frame frame = { [UNIVERSE getTime], framePos, [ship normalOrientation], [ship upVector] };
553
554 _track[_nextFrame] = frame;
555 _nextFrame = (_nextFrame + 1) % kExhaustFrameCount;
556}
557
558- (Frame)frameAtTime:(double)t_frame fromFrame:(Frame)frame_zero // t_frame is relative to now ie. -0.5 = half a second ago.
559{
560 if (t_frame >= 0.0)
561 return frame_zero;
562
563 Frame frame_one;
564
565 int t1 = PREV(_nextFrame);
566 double moment_in_time = frame_zero.timeframe + t_frame;
567 double period, f0;
568
569 if (moment_in_time > _trackTime) // between the last saved frame and now
570 {
571 frame_one = _track[t1]; // last saved moment
572 period = (moment_in_time - t_frame) - _trackTime;
573 f0 = 1.0 + t_frame / period;
574 } else if (moment_in_time < _track[_nextFrame].timeframe) // more than kExhaustFrameCount frames back
575 {
576 return _track[_nextFrame];
577 } else {
578 while (moment_in_time < _track[t1].timeframe) {
579 t1 = PREV(t1);
580 }
581 int t0 = NEXT(t1);
582
583 frame_zero = _track[t0];
584 frame_one = _track[t1];
585 period = frame_zero.timeframe - frame_one.timeframe;
586 f0 = (moment_in_time - _track[t1].timeframe) / period;
587 }
588
589 // interpolate
590 double f1 = 1.0 - f0;
591
592 HPVector posn;
593 posn.x = f0 * frame_zero.position.x + f1 * frame_one.position.x;
594 posn.y = f0 * frame_zero.position.y + f1 * frame_one.position.y;
595 posn.z = f0 * frame_zero.position.z + f1 * frame_one.position.z;
596 Quaternion qrot;
597 qrot.w = (float)f0 * frame_zero.orientation.w + (float)f1 * frame_one.orientation.w;
598 qrot.x = (float)f0 * frame_zero.orientation.x + (float)f1 * frame_one.orientation.x;
599 qrot.y = (float)f0 * frame_zero.orientation.y + (float)f1 * frame_one.orientation.y;
600 qrot.z = (float)f0 * frame_zero.orientation.z + (float)f1 * frame_one.orientation.z;
601
602 Frame result;
603 result.position = posn;
604 result.orientation = qrot;
605 result.timeframe = moment_in_time;
606 result.k = vector_forward_from_quaternion(qrot);
607 return result;
608}
609
611{
612 /*ShipEntity *ship = [self owner];
613
614 // Absolute position of self
615 Vector framePos = OOVectorMultiplyMatrix([self position], [ship drawTransformationMatrix]);
616 Frame frame = { [UNIVERSE getTime], framePos, [ship normalOrientation], [ship upVector] };
617
618 _track[_nextFrame] = frame;
619 _nextFrame = (_nextFrame + 1) % kExhaustFrameCount;*/
620 _nextFrame = 0;
622 uint8_t i;
623 for (i = 0; i < kExhaustFrameCount; i++) {
624 _track[i].timeframe = 0.0;
625 _track[i].position = framePos;
626 _track[i].orientation = kIdentityQuaternion;
627 _track[i].k = kZeroVector;
628 }
629}
630
631- (void)rescaleBy:(GLfloat)factor
632{
634}
635
636- (void)rescaleBy:(GLfloat)factor writeToCache:(BOOL)writeToCache
637{
638 /* Do nothing; this is only needed because of OOEntityWithDrawable
639 implementation requirements */
640}
641
646
648{
649 if (sPlumeTexture == nil) {
650 sPlumeTexture = [[OOTexture textureWithName:@"oolite-exhaust-blur.png"
651 inFolder:@"Textures"
652 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask | kOOTextureRepeatT | kOOTextureRepeatS
653 anisotropy:kOOTextureDefaultAnisotropy / 2.0
654 lodBias:0.0] retain];
655 [[OOGraphicsResetManager sharedManager] registerClient:(id<OOGraphicsResetClient>)[OOExhaustPlumeEntity class]];
656 }
657}
658
660{
661 if (sPlumeTexture == nil)
662 [self setUpTexture];
663 return sPlumeTexture;
664}
665
667{
668 [sPlumeTexture release];
670}
671
672@end
673
674@implementation Entity (OOExhaustPlume)
675
677{
678 return NO;
679}
680
681@end
@ kExhaustFrameCount
static GLuint afttstr3[4]
static GLfloat pA[6]
#define kFadeLevel1
#define kScaleLevel2
static GLuint tstr4[9]
#define kScaleLevel3
static GLuint tfan1[10]
static GLuint tstr2[9]
static GLuint afttstr2[4]
#define PREV(n)
static GLuint tstr3[9]
#define kTimeStep
static GLuint tstr1[9]
#define NEXT(n)
#define kFadeLevel2
#define kFadeLevel3
static GLuint afttstr4[4]
static OOTexture * sPlumeTexture
#define kOverallAlpha
static GLuint afttstr1[4]
#define kScaleLevel1
#define EXPECT_NOT(x)
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
#define OO_ENTER_OPENGL()
#define M_SQRT1_2
Definition OOMaths.h:75
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m) CONST_FUNC
Definition OOMatrix.m:137
void OOGLPushModelView(void)
OOMatrix OOGLPopModelView(void)
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
unsigned count
return nil
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
const Quaternion kIdentityQuaternion
double OOTimeDelta
Definition OOTypes.h:193
double OOTimeAbsolute
Definition OOTypes.h:192
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
const Vector kZeroVector
Definition OOVector.m:27
OOINLINE Vector cross_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:294
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
void setOwner:(Entity *ent)
Definition Entity.m:542
OOMatrix drawTransformationMatrix()
Definition Entity.m:819
unsigned isPlayer
Definition Entity.m:145
BOOL isVisible()
Definition Entity.m:1028
HPVector position
Definition Entity.m:576
Quaternion normalOrientation()
Definition Entity.m:687
double speed()
Definition Entity.m:713
id init()
Definition Entity.m:64
id owner()
Definition Entity.m:548
void setPosition:(HPVector posn)
Definition Entity.m:608
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
GLfloat _exhaustBaseColors[34 *4]
Frame frameAtTime:fromFrame:(double t_frame, [fromFrame] Frame frame_zero)
void setScale:(Vector scale)
Frame _track[kExhaustFrameCount]
OOHPScalar _vertices[34 *3]
void registerClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
void apply()
Definition OOTexture.m:258
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:132
Vector forwardVector()
Vector upVector()
GLfloat flightSpeed
GLfloat speedFactor()
OOColor * exhaustEmissiveColor()
Vector rightVector()
float randf(void)
#define ranrot_rand()
Quaternion orientation
HPVector position
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38
OOScalar w
OOScalar x
OOScalar y
OOScalar z
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34