/// Applies target impulse at specified position to this entity. Impulse in Ns (kg*m/s) void PhysicsProperty::ApplyImpulse(const Vector3f & impulse, const Vector3f & position) { /// Static objects don't apply anything anyway. if (inverseMass == 0) return; // Remove IN_REST flag. state &= ~CollisionState::IN_REST; /// Give it an increase to the linear momentum. /// Impulses translate directory into change in linear momentum. Vector3f deltaLinearMomentum = impulse; linearMomentum += deltaLinearMomentum; if (!useForces) velocity += impulse; if (!obb) return; assert(obb); // lol.. /// Give it an increase to the angular momentum. Vector3f centerToPosition = position - obb->position; Vector3f crossProduct = -centerToPosition.CrossProduct(impulse); /// Try only cross product..? // Vector3f deltaAngularMomentum = inertiaTensorInverted.product(crossProduct); angularMomentum += crossProduct; /// Testing: /// Impulseive torque (u), Inertiatensor (I) and angularVelocity (Ó): /// u = IÓ /// delta(Ó) = I^-1 * u /// Where the inertia tensor is in world-coordinates. /// Also, where p = point of application, and g is the impulse. /// u = p x g Vector3f impulsiveTorque = centerToPosition.CrossProduct(impulse); Vector3f deltaAngularVelocity = inertiaTensorInverted.product(impulsiveTorque); }