A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by roy844 » Mon May 10, 2010 6:31 pm
hi,
i tryed to find out why the transformation callback is not triggered. i used code from the tutorial that does work, but it is still a mystery why my code is not working. The object has a mass and the transformcallback is set.
the ForceAndTorqueCallback function is triggered and a force is added (gravity)
code below :
- Code: Select all
NewtonBodySetTransformCallback(body, SetTransformCallback); // register the transformation callback
NewtonBodySetForceAndTorqueCallback (body, ApplyForceAndTorqueCallback);
// Transform callback to set the matrix of a the visual entity
void SetTransformCallback (const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
c_Object* ent;
// Get the position from the matrix
dVector posit (matrix[12], matrix[13], matrix[14], 1.0f);
dQuaternion rotation;
// we will ignore the Rotation part of matrix and use the quaternion rotation stored in the body
NewtonBodyGetRotation(body, &rotation.m_q0);
// get the entity associated with this rigid body
ent = (c_Object*) NewtonBodyGetUserData(body);
// since this tutorial run the physics and a different fps than the Graphics
// we need to save the entity current transformation state before updating the new state.
ent->m_prevPosition = ent->m_curPosition;
ent->m_prevRotation = ent->m_curRotation;
if (ent->m_curRotation.DotProduct (rotation) < 0.0f) {
ent->m_prevRotation.Scale(-1.0f);
}
// set the new position and orientation for this entity
ent->m_curPosition = posit;
ent->m_curRotation = rotation;
}
// callback to apply external forces to body
void ApplyForceAndTorqueCallback (const NewtonBody* body, dFloat timestep, int threadIndex)
{
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dFloat mass;
// for this tutorial the only external force in the Gravity
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
dVector gravityForce (0.0f, mass * GRAVITY, 0.0f, 1.0f);
NewtonBodySetForce(body, &gravityForce[0]);
}
-
roy844
-
- Posts: 13
- Joined: Mon Mar 03, 2008 3:36 am
by JernejL » Tue May 11, 2010 3:46 am
Is the body actually moving? you tried debug rendering to see if it moves?
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by roy844 » Tue May 11, 2010 12:48 pm
i did debuged and noticed the body is not moving, but i did noticed a force vector is added 100 y direction.
mass(10) * gravity(10) = 100, but no movement and no transformation callback.
-
roy844
-
- Posts: 13
- Joined: Mon Mar 03, 2008 3:36 am
by Julio Jerez » Tue May 11, 2010 1:35 pm
Is the body resting on the floor?
when the body is in equlibrium they do not get transform callback.
try making the body active by setting auto sleep off and see if it works.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by roy844 » Tue May 11, 2010 2:08 pm
the object is the only object so it can not rest on the floor.
could it be that it is outside of the newtonworld or so ?
and i did set the body to active with code below no result.
- Code: Select all
NewtonBodySetFreezeState(box,0);
-
roy844
-
- Posts: 13
- Joined: Mon Mar 03, 2008 3:36 am
by Julio Jerez » Tue May 11, 2010 2:23 pm
if you have there is not floor to rest then objects will fall for ever and it they will hit the world bounday. when that happen the body is forzed frozen.
if you set the NetwonOnBodyLeaveWorld callback you will see that the body hit a world edge, and after that not more transform updates.
you need to add a solid floor or make a weightless space when gravity is zero an dteh body will.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by roy844 » Tue May 11, 2010 3:09 pm
ok i am trying to set
NewtonSetBodyLeaveWorldEvent but i get an error:
error C2664: 'NewtonSetBodyLeaveWorldEvent' : cannot convert parameter 2 from 'void (__cdecl *)(const NewtonBody *)' to 'NewtonBodyLeaveWorld'- Code: Select all
static void LeaveWorldCallback(const NewtonBody* body);
void LeaveWorldCallback(const NewtonBody* body)
{
int test = 3;
}
NewtonSetBodyLeaveWorldEvent(world, LeaveWorldCallback);
-
roy844
-
- Posts: 13
- Joined: Mon Mar 03, 2008 3:36 am
by roy844 » Tue May 11, 2010 4:27 pm
i looked some more and i thought maybe these warnings is causing the problem ?
- Code: Select all
Compiling...
CollisionShapeUtil.cpp
main.cpp
object.cpp
PhysicsEngine.cpp
RigidBodyUtil.cpp
SceneManager.cpp
stdafx.cpp
Generating Code...
Linking...
[b]LINK : C:\Documents and Settings\Ontwikkel\Mijn documenten\Visual Studio 2008\Projects\game\Debug\game.exe not found or not built by the last incremental link; performing full link
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
dMath.lib(dMatrix.obj) : warning LNK4204: 'C:\Documents and Settings\Ontwikkel\Mijn documenten\Visual Studio 2008\Projects\game\Debug\vc90.pdb' is missing debugging information for referencing module; linking object as if no debug info
dMath.lib(dQuaternion.obj) : warning LNK4204: 'C:\Documents and Settings\Ontwikkel\Mijn documenten\Visual Studio 2008\Projects\game\Debug\vc90.pdb' is missing debugging information for referencing module; linking object as if no debug info[/b]Embedding manifest...
-
roy844
-
- Posts: 13
- Joined: Mon Mar 03, 2008 3:36 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest