I have 2 questions.
First is a doubt about the code i will post next. I am using Irrlicht and Newton. When i create a body i draw it graphically and then among many other things i do this:
....
- Code: Select all
NewtonBodySetTransformCallback(p_body, setObjectTransformCallback);
NewtonBodySetForceAndTorqueCallback(p_body, applyForceTorqueCallback);
....
- Code: Select all
void vehi_hdRepresentation::setObjectTransformCallback(const NewtonBody* body, const float* matrix)
{
vehi_hdRepresentation* hdRep = (vehi_hdRepresentation *)NewtonBodyGetUserData(body);
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
if(p_irrSceneNode)
{
p_irrSceneNode->setPosition(mat.getTranslation());
p_irrSceneNode->setRotation(mat.getRotationDegrees());
}
}
I saw this in some tutorial. So, as i can understand what is happening is that Newton knows when there is some transformation made to an object, and call the function that i defined : setObjectTransformCallback. this function as one argument called matrix, that i believe that is Newton body matrix, am i right ?? Because of that all i need to do in my function is to change the position in the graphical way, since Newton make that automatically, its correct ??
Now, my second question:
I want to control one object with a haptic device, but let's just think that i am controlling one object with the keyboard. So every time i press a key the object make so moves. When this happen i guess that what i need to do is update graphically but also Physically, something that in the first question was made automatically by Newton. So what i did was something like:
- Code: Select all
void vehi_hdRepresentation::hapticTransformMatrixChanged(const matrix4& mat)
{
if(p_irrSceneNode)
p_irrSceneNode->setPosition(vector3df(p_pos.X,p_pos.Y, p_pos.Z));
if(p_body)
{
/** First solution **/
matrix4 matTemp;
NewtonBodyGetMatrix(p_body, matTemp.pointer());
matTemp.setTranslation(p_pos);
NewtonBodySetMatrix(p_body, matTemp.pointer());
/** Second solution **/
NewtonBodySetMatrix(p_body, mat.pointer());
}
Notice that p_pos is the actual position of the object that i am controlling (is obtained with haptic device API). The matrix passed as argument in this function is the matrix that gives the actual position of the object (also obtained with haptic device API). I try out both solutions and in both happens the same thing...the application crash's !!! What i am doing wrong? Anyone have any idea why application crashs?
Thanks,
Telmo