/*
*	\brief Update all simulation objects in the world
*/
void CSpaghettiRigidBody::UpdateVelocity( 
		const CSpaghettiWorld *world,
		const float deltaTime									//!< Delta time (The amount of time past since the last update)
	)
{
	// Nothing to update if he rigid body is static or disabled
	if (m_flags.isStatic || !m_flags.isEnabled)
		return;

	// add gravity
	AddForceAtPoint(world->GetGravity(), m_position);

	// update velocity
	m_velocity = m_velocity + (m_force * deltaTime);

	// update the position of the body
	m_lastPosition = m_position;
	m_position = m_position + (m_velocity * deltaTime);

	// update angular momentum
	m_angularMomentum = m_angularMomentum + (m_torque * deltaTime);
	m_angularMomentum *= 0.95f;

	UpdateInertiaTensor();
	UpdateAngularVelocity();

	// construct the skew matrix
	Ogre::Matrix3 skewMatrix;
	skewMatrix[0][0] = 0.0f;
	skewMatrix[0][1] = -m_angularVelocity.z * 0.17f;
	skewMatrix[0][2] = m_angularVelocity.y * 0.17f;

	skewMatrix[1][0] = m_angularVelocity.z * 0.17f;
	skewMatrix[1][1] = 0.0f;
	skewMatrix[1][2] = -m_angularVelocity.x * 0.17f;

	skewMatrix[2][0] = -m_angularVelocity.y * 0.17f;
	skewMatrix[2][1] = m_angularVelocity.x * 0.17f;
	skewMatrix[2][2] = 0.0f;

	// update rotation matrix
	m_rotation = m_rotation + ((skewMatrix * deltaTime) * m_rotation);

	// update and normalize the quaternion
	m_quaternion.FromRotationMatrix(m_rotation);
	m_quaternion.normalise();

	// stop it crashing...
	if (m_quaternion.isNaN())
	{
		m_quaternion = Ogre::Quaternion::IDENTITY;
		m_rotation = Ogre::Matrix3::IDENTITY;
	}
	
	// transform the bounding box data
	m_bounds->Transform(m_position, m_quaternion);

	// Zero out force and torque
	m_force = Ogre::Vector3::ZERO;
	m_torque = Ogre::Vector3::ZERO;
}
Example #2
0
	void RigidBody::AddForceAtBodyPoint(const Vector3& force, const Point3& point)
	{
		Point3 pointInWorldSpace;
		GetPointInWorldSpace(point, &pointInWorldSpace);
		AddForceAtPoint(force, pointInWorldSpace);
	}