How to make a working camera integrated with Newton ?
Posted: Thu Apr 22, 2004 6:04 pm
Hello,
I managed to get the newton engine up and running - a cube colliding
with a 3ds surface - , but I'm having problems doing the same thing with the camera. It falls on the ground and I can rotate it but can't move.
The callbacks:
Thanks in advance,
Robert
I managed to get the newton engine up and running - a cube colliding
with a 3ds surface - , but I'm having problems doing the same thing with the camera. It falls on the ground and I can rotate it but can't move.
Code: Select all
camera = smgr->addCameraSceneNodeFPS(0,350,1500);
camera ->setFarValue(20000.0f);
NewtonBody * cbody;
NewtonCollision * ccoll;
ccoll = NewtonCreateBox(nWorld,38,100,38,NULL);
cbody = NewtonCreateBody(nWorld,ccoll);
NewtonBodySetUserData(cbody, camera);
NewtonBodySetMassMatrix (cbody, 10.0f, 150.0f, 150.0f, 150.0f);
NewtonBodySetFreezeTreshold(cbody, 1.0, 1.0, 1.0, 1.0);
NewtonBodySetTransformCallback(cbody, SetMeshTransformEvent2);
NewtonBodySetForceAndTorqueCallback(cbody, ApplyForceAndTorqueEvent);
matrix4 cmat;
cmat.setTranslation(vector3df(1300 ,8044 ,1249));
NewtonBodySetMatrix(cbody, &cmat.M[0]);
NewtonBodySetAutoFreeze (cbody , 0);
NewtonWorldUnfreezeBody(nWorld, cbody);
NewtonReleaseCollision(nWorld, ccoll);
Code: Select all
static void _cdecl SetMeshTransformEvent2(const NewtonBody* cbody, const float* matrix)
{
// copy the matrix into an irrlicht matrix4
matrix4 cmat;
memcpy(cmat.M, matrix, sizeof(float)*16);
// Retreive the user data attached to the newton body
ICameraSceneNode *camera = (ICameraSceneNode *)NewtonBodyGetUserData(cbody);
if (camera)
{
// Position the node
camera->setPosition(cmat.getTranslation()); // set position
// camera->setRotation(cmat.getRotationDegrees()); // and rotation
}
}
static void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body)
{
float mass;
float Ixx;
float Iyy;
float Izz;
float force[3];
float torque[3];
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
force[0] = 0.0f;
force[1] = mass * -800.0f;
force[2] = 0.0f;
torque[0] = 0.0f;
torque[1] = 0.0f;
torque[2] = 0.0f;
NewtonBodyAddForce (body, force);
NewtonBodyAddTorque (body, torque);
}
Robert