My game is pretty simple. The world has a static object in the center of the scene and another static object that represents the haptic device in the scene.
Only two major tasks are performed:
- 1) When I move the haptic device, the object represented by it is only changed its position and rotation.
2) When the object (represented by the haptic device) touches the object that stands at the center of the scene, a collision is detected, and a return force is calculated for the haptic device, with the intention of the user feel that the two objects were touched.
No animation physics is shown. There is no gravity, there is no mass of objects, no object is changed dynamically, all are static. I just change the position (translation) and rotation of the object of the haptic device according to the matrix of the device.
I am using the Newton engine just for the two objects have a physical body and when they collide I can receive information such as point of contact, normal and penetration. Because with this information I can calculate the force feedback.
My problem is the opposite of what usually happens in games that use a physics engine, where when the physical objects are changed (moving dynamically), I need to change the position and rotation in the graphics engine. That is, the method SetTransformCallback is used to receive the NewtonBody body and Matrix and changes the position and rotation in the graphics engine.
In my case is different. First, I get the the position and rotation of my haptic device (joystick 3D) through it Matrix, and thus I change the Matrix of my newton body with the new positions and rotations.
I'm using the graphics engine Irrlicht.
My methods are:
- Code: Select all
void CObject::setPosition(const vector3df& position)
{
if(m_node)
{
m_node->setPosition(position);
m_node->updateAbsolutePosition();
}
if(m_body)
{
core::matrix4 mat;
NewtonBodyGetMatrix(m_body, mat.pointer());
mat.setTranslation(position);
NewtonBodySetMatrix(m_body, mat.pointer());
}
}
- Code: Select all
void CObject::setRotation(const vector3df& rotation)
{
if(m_node)
{
m_node->setRotation(rotation);
//m_node->updateAbsolutePosition();
}
if(m_body)
{
core::matrix4 mat;
NewtonBodyGetMatrix(m_body, mat.pointer());
mat.setsetRotationDegree(rotation);
NewtonBodySetMatrix(m_body, mat.pointer());
}
}
The problem is the rotation just does not happen!
When I move my device, my object is usually translated (graphically and physically)
But when the object rotates through the device, it is rotated only graphically, the physical body it remains the same position. That is, the rotation in Irrlicht engine is correctly, but when I try to rotate the newton body, it does not rotate!
Is there something wrong with rotate this way?
- Code: Select all
core::matrix4 mat;
NewtonBodyGetMatrix(m_body, mat.pointer());
mat.setRotationDegree(rotation);
NewtonBodySetMatrix(m_body, mat.pointer());