Newton & irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
m4tricol
Posts: 11
Joined: Thu Nov 29, 2007 9:18 am

Newton & irrlicht

Post by m4tricol »

Hi, can someone help to code this function with irrlicht...
I tried with CMatrix4<float>, and vector3df, but there is something that i don't get it.

thanks

Code: Select all

void BallCharacterApplyForceAndTorque (const NewtonBody* body)
{
	dFloat mass;
	dFloat Ixx;
	dFloat Iyy;
	dFloat Izz;


	NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
	dVector force (0.0f, mass * GRAVITY, 0.0f);
	NewtonBodySetForce (body, &force.m_x);


	// calculate a rotation matrix from the camera heading
	dMatrix matrix (GetIdentityMatrix()); 
	dVector lateralDir (cameraDir * dVector (0.0f, 1.0f, 0.0f));
	matrix.m_right = lateralDir.Scale (1.0f / (lateralDir % lateralDir));
	matrix.m_front = matrix.m_up * matrix.m_right;


	if (forceMode) {
		// this is the flight mode
		dVector force;
		dVector velocity;

		// rotate the force direction to align with the camera
		dVector forceDir (matrix.RotateVector (cameraTorqueVector));
 		forceDir = dgYawMatrix(-3.1416f * 0.5f).RotateVector (forceDir);
		forceDir.m_y = 1.0f;

		
		NewtonBodyGetForce(body, &force.m_x);
		NewtonBodyGetVelocity(body, &velocity.m_x);

		force += (forceDir.Scale (mass * 30.0f) - forceDir.Scale (5.0f * (velocity % forceDir))); 
		NewtonBodySetForce (body, &force.m_x);
	} else {
		// this is the rolling mode
		dVector omega;

		// rotate the torque direction to align with the camera
		dVector torqueDir (matrix.RotateVector (cameraTorqueVector));
		NewtonBodyGetOmega(body, &omega.m_x);
		dVector torque (torqueDir.Scale (Ixx * 75.0f) - torqueDir.Scale (2.0f * Ixx * (omega % torqueDir))); 
		NewtonBodySetTorque (body, &torque.m_x);
	}
}
Post Reply