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