Example #1
0
// setter
void RigidCylinder::SetHeight(real height)
{
	Cylinder::SetHeight(height);
	
	UpdateMass();
	UpdateInertiaTensor();
}
Example #2
0
void RigidCylinder::SetRadius(real radius)
{
	Cylinder::SetRadius(radius);
	
	UpdateMass();
	UpdateInertiaTensor();
}
Example #3
0
void RigidBody3::SetMass(real mass)
{
	if(mass == C_INF)
	{
		inverseMass = 0.0f;
	} 
	else 
	{
		inverseMass = 1.0f / mass;
	}

	UpdateInertiaTensor();
}
/*
*	\brief	Set a rigid bodies bounding box
*/
void CSpaghettiRigidBody::SetBounds( 
	CSpaghettiBounds *boundingBox								//!< The bounding box to set this bodies bounding box too
	)
{
	m_bounds = boundingBox;
	if (m_bounds != nullptr) 
	{
		m_bounds->SetBody(this);
		m_bounds->Transform(m_position, m_rotation);
	}

	CalculateInertiaBodyTensor();
	UpdateInertiaTensor();
	UpdateAngularVelocity();
}
Example #5
0
RigidBody3::RigidBody3(void) : Object3()
{
	// primary
	linearVelocity = vec3::Zero();
	forces = vec3::Zero();
	
	angularVelocity = vec3::Zero();
	torques = vec3::Zero();

	// constant
	elasticity = 0.8f;
	inverseMass = 1.0f;
	UpdateInertiaTensor();
	
	// derived
	UpdateWorldMatrix();
}
Example #6
0
RigidCylinder::RigidCylinder(const vec3& position, real height, real radius) : RigidBody3(), Cylinder(position, height, radius)
{
	UpdateMass();
	UpdateInertiaTensor();
}
Example #7
0
RigidCylinder::RigidCylinder(real x, real y, real z, real height, real radius) : RigidBody3(), Cylinder(vec3(x, y, z), height, radius)
{
	UpdateMass();
	UpdateInertiaTensor();
}
Example #8
0
// constructors
RigidCylinder::RigidCylinder(void) : RigidBody3(), Cylinder() 
{
	UpdateMass();
	UpdateInertiaTensor();
}
/*
*	\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;
}