Oolite
Loading...
Searching...
No Matches
OOExhaustPlumeEntity(Private) Category Reference

Instance Methods

(void) - saveToLastFrame
(Frame) - frameAtTime:fromFrame:

Detailed Description

Definition at line 48 of file OOExhaustPlumeEntity.m.

Method Documentation

◆ frameAtTime:fromFrame:

- (Frame) frameAtTime: (double) t_frame
fromFrame: (Frame) frame_zero 

Extends class OOExhaustPlumeEntity.

Definition at line 558 of file OOExhaustPlumeEntity.m.

558 :(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}
#define PREV(n)
#define NEXT(n)
struct HPVector HPVector
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
struct Quaternion Quaternion
float y
float x
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

References Frame::k, NEXT, Frame::orientation, Frame::position, PREV, Frame::timeframe, vector_forward_from_quaternion(), Quaternion::w, HPVector::x, Quaternion::x, HPVector::y, Quaternion::y, HPVector::z, and Quaternion::z.

Referenced by OOExhaustPlumeEntity::update:.

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

◆ saveToLastFrame

- (void) saveToLastFrame

Extends class OOExhaustPlumeEntity.

Definition at line 542 of file OOExhaustPlumeEntity.m.

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}
@ kExhaustFrameCount
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m) CONST_FUNC
Definition OOMatrix.m:137
Quaternion normalOrientation()
Definition Entity.m:687
Vector upVector()

References HPvector_add(), kExhaustFrameCount, Entity::normalOrientation, OOHPVectorMultiplyMatrix(), Entity::owner, saveToLastFrame, and ShipEntity::upVector.

Referenced by saveToLastFrame, and OOExhaustPlumeEntity::update:.

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

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