MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdateSyncronous

Method UpdateSyncronous

trinity/Eve/SpaceObject/EveMissile.cpp:111–212  ·  view source on GitHub ↗

-------------------------------------------------------------------------------- Description: Main update method called every frame. Here we do all sorts of things: get the position/orientation of the underlying ball and the target ball (if there is any: bombs don't have targets!), update each warheads state and position and calculate the bounding sphere surrounding all warheads on this missile. A

Source from the content-addressed store, hash-verified

109// time - current game time
110// --------------------------------------------------------------------------------
111void EveMissile::UpdateSyncronous( const EveUpdateContext& updateContext )
112{
113 EveSpaceObject2::UpdateSyncronous( updateContext );
114 Be::Time time = updateContext.GetTime();
115 float deltaT = updateContext.GetDeltaT();
116
117 // get inv ball rotation, is needed for update of each warhead
118 Matrix invBallRotationMatrix = IdentityMatrix();
119 if( m_ballRotation )
120 {
121 Quaternion quat( 0.f, 0.f, 0.f, 1.f );
122 // get rotation quaternion of our ball
123 m_ballRotation->Update( &quat, time );
124 // we may need the ball rotation matrix
125 // inverse it to get inverse!
126 quat = Inverse( quat );
127 // turn it into the matrix we need
128 invBallRotationMatrix = RotationMatrix( quat );
129 }
130
131 // time goes on
132 m_time += deltaT;
133
134 // get data from destiny
135 Vector3 myPosition( 0.f, 0.f, 0.f );
136 Vector3 myVelocity( 0.f, 0.f, 0.f );
137 if( m_ballPosition && m_target )
138 {
139 // Estimate the time to target each frame, this INCLUDES delay and eject time
140 m_ballPosition->GetValueAt( &myPosition, time );
141 m_ballPosition->GetValueDotAt( &myVelocity, time );
142 Vector3 targetPositionWS;
143 m_target->GetDamageLocatorPosition( &targetPositionWS, -1, true );
144
145 // calc speed
146 float speed = Length( myVelocity );
147
148 // is speed of zero is dangerous
149 if( speed > 0.f )
150 {
151 // update the total alive time based on time already passed and distance / speed of missile ball to target
152 Vector3 dir( myPosition - targetPositionWS );
153 m_estimatedTotalAliveTime = m_time + ( Length( dir ) - m_targetRadius ) / speed;
154 m_lastValidSpeed = speed;
155 }
156 else if( m_lastValidSpeed > 0.f )
157 {
158 // This means the ball has hit the target, but the warhead may still on the way to the target
159 Vector3 dir( myPosition - targetPositionWS );
160 myVelocity = Normalize( dir );
161 myVelocity *= m_lastValidSpeed;
162 }
163 }
164
165 Vector3 worldPos = GetWorldPosition();
166
167 // update the submissiles aka warheads
168 for( EveMissileWarheadVector::const_iterator it = m_warheads.begin(); it != m_warheads.end(); ++it )

Callers

nothing calls this directly

Calls 15

LengthFunction · 0.85
GetDeltaTMethod · 0.80
GetTargetLocatorMethod · 0.80
UpdateEndTransformMethod · 0.80
UpdateWarheadMethod · 0.80
GetOriginShiftMethod · 0.80
CheckImpactMethod · 0.80
GetWarheadIDMethod · 0.80
GetTimeMethod · 0.45
UpdateMethod · 0.45
GetValueAtMethod · 0.45
GetValueDotAtMethod · 0.45

Tested by

no test coverage detected