Esempio n. 1
0
void BallNode::Update(float msec) {
	msec = msec * 0.01f;
	if(!atRest){
		Vector3 acceleration = (m_force+m_gravity)*m_invMass;
		m_linearVelocity = m_linearVelocity + acceleration*msec;
		m_position = m_position + m_linearVelocity*msec;	
		m_force = Vector3(0,0,0);

		Vector3 AngularAcceleration = m_invInertia.GetScalingVector()*m_torque;		
		m_angularVelocity = m_angularVelocity + AngularAcceleration * msec;
		m_orientation = m_orientation * Quaternion::EulerAnglesToQuaternion(m_angularVelocity.x,m_angularVelocity.y,m_angularVelocity.z);
		m_torque = Vector3(0,0,0);
	
		s1->radius = m_colli_radius;	
		collBox->halfdims = Vector3(m_colli_radius);
		
		s1->pos = m_position;
		collBox->pos = m_position;	
			
		m_linearVelocity = Vector3(0.9999)*m_linearVelocity;
		m_angularVelocity = Vector3(0.9999)*m_angularVelocity;
					
		//Sleep Hack		
		float sleepSpeed = 1.0f;
		if(m_linearVelocity.x < sleepSpeed && m_linearVelocity.x > -sleepSpeed){
			if(m_linearVelocity.y < sleepSpeed && m_linearVelocity.y > -sleepSpeed){
				if(m_linearVelocity.z < sleepSpeed && m_linearVelocity.z > -sleepSpeed){
					atRest = true;
				}
			}
		}

		//Bounderies - The Walls!
		if(true){
			if(m_position.y > 4096){
				m_linearVelocity.y = -abs(m_linearVelocity.y);
			}
			if(m_position.x < 0){
				m_linearVelocity.x = abs(m_linearVelocity.x);
			}
			if(m_position.x > 4096){
				m_linearVelocity.x = -abs(m_linearVelocity.x);
			}
			if(m_position.z < 0){
				m_linearVelocity.z = abs(m_linearVelocity.z);
			}
			if(m_position.z >4096){
				m_linearVelocity.z = -abs(m_linearVelocity.z);
			}
			if(m_position.y < -500){
				m_linearVelocity.y = abs(m_linearVelocity.y);
				//m_position.y = 50;
			}
		}		
	}
	if(target) { target->SetTransform(BuildTransform());}
}
Esempio n. 2
0
//You will perform your per-object physics integration, here!
//I've added in a bit that will set the transform of the
//graphical representation of this object, too.
void	PhysicsNode::Update(float msec){
	//FUN GOES HERE

	if (!m_rest && !fixed){

		//Need to involve inverse mass here...
		m_linearVelocity += ((m_force * m_invMass * msec) + (m_constantAccel * msec)) * DAMPING_FACTOR;

		m_position += (m_linearVelocity * msec);

		m_angularVelocity += ( (m_invInertia * m_torque) * msec) * DAMPING_FACTOR;
		m_orientation = m_orientation + (m_orientation * (m_angularVelocity * msec * 0.5f));
		m_orientation.Normalise();

		m_linearVelocity *= VELOCITY_DAMPING;
		m_angularVelocity *= VELOCITY_DAMPING;

		m_force = Vector3(0,0,0);
		m_torque = Vector3(0,0,0);

		//TODO: Should update collision volumes here if an object gets set to rest...
		// otherwise they could be mistakenly woken up! ... Very unlikely though!
		if (abs(m_linearVelocity.x) < REST_TOLERANCE &&
			abs(m_linearVelocity.y) < REST_TOLERANCE &&
			abs(m_linearVelocity.z) < REST_TOLERANCE &&
			abs(m_force.x) < REST_TOLERANCE &&
			abs(m_force.y) < REST_TOLERANCE &&
			abs(m_force.z) < REST_TOLERANCE &&
			abs(m_constantAccel.x) < REST_TOLERANCE &&
			abs(m_constantAccel.y) < REST_TOLERANCE &&
			abs(m_constantAccel.z) < REST_TOLERANCE)
			m_rest = true;

	}

	if(target) {
		target->SetTransform(BuildTransform());
		target->SetModelScale(m_scale);
	}
}
Esempio n. 3
0
void PhysicsNode::UpdateTransform()
{
	if(target) {
		target->SetTransform(BuildTransform());
	}
}