| 152 | } |
| 153 | |
| 154 | void PhysicsForce::processTick( const Move * ) |
| 155 | { |
| 156 | if ( isMounted() ) |
| 157 | { |
| 158 | MatrixF test( true ); |
| 159 | test.setPosition( Point3F( 0, 4, 0 ) ); |
| 160 | AssertFatal( test != mMount.xfm, "Error!" ); |
| 161 | |
| 162 | MatrixF mat( true ); |
| 163 | mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat ); |
| 164 | setTransform( mat ); |
| 165 | } |
| 166 | |
| 167 | // Nothing to do without a body or if physics hasn't ticked. |
| 168 | if ( !mBody || !mPhysicsTick ) |
| 169 | return; |
| 170 | |
| 171 | mPhysicsTick = false; |
| 172 | |
| 173 | // If we lost the body then release it. |
| 174 | if ( !mBody->isDynamic() || !mBody->isSimulationEnabled() ) |
| 175 | { |
| 176 | detach(); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | // Get our distance to the body. |
| 181 | Point3F cMass = mBody->getCMassPosition(); |
| 182 | Point3F vector = getPosition() - cMass; |
| 183 | |
| 184 | // Apply the force! |
| 185 | F32 mass = mBody->getMass(); |
| 186 | Point3F impulse = ( mass * vector ) / TickSec; |
| 187 | |
| 188 | // Counter balance the linear impulse. |
| 189 | Point3F linVel = mBody->getLinVelocity(); |
| 190 | Point3F currentForce = linVel * mass; |
| 191 | |
| 192 | // Apply it. |
| 193 | mBody->applyImpulse( cMass, impulse - currentForce ); |
| 194 | } |
| 195 | |
| 196 | DefineEngineMethod( PhysicsForce, attach, void, ( Point3F start, Point3F direction, F32 maxDist ),, |
| 197 | "@brief Attempts to associate the PhysicsForce with a PhysicsBody.\n\n" |
nothing calls this directly
no test coverage detected