A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by FSA » Fri Aug 02, 2013 3:03 pm
Why does Newton crash on NewtonUpdate when I have set an own ForceAndTorque function? My code is the following:
- Code: Select all
class Foo
{
private:
virtual void PhysicBodyCallbackIntern(const NewtonBody* body, dFloat timestep, int threadIndex);
public:
typedef void(Foo::*CallbackFunc)(const NewtonBody*, dFloat, int);
//...
};
Foo::Init()
{
Foo::CallbackFunc pCallB = &Foo::PhysicBodyCallbackIntern;
NewtonBodySetForceAndTorqueCallback(m_pPhysicBody, (NewtonApplyForceAndTorque)&pCallB);
}
pCallb is not NULL. The Body is created.
-

FSA
-
- Posts: 322
- Joined: Wed Dec 21, 2011 9:47 am
by Julio Jerez » Fri Aug 02, 2013 3:13 pm
- Code: Select all
private:
virtual void PhysicBodyCallbackIntern(const NewtonBody* body, dFloat timestep, int threadIndex);
};
PhysicBodyCallbackIntern must be a static function
here is an exampel of hwo to set that up, from the dNewton class
- Code: Select all
class dNewtonDynamicBody: public dNewtonBody
{
public:
CNEWTON_API dNewtonDynamicBody(dNewton* const world)
{
....
NewtonBodySetForceAndTorqueCallback(m_body, OnForceAndTorque);
}
CNEWTON_API virtual ~dNewtonDynamicBody();
CNEWTON_API virtual void OnForceAndTorque (dFloat timestep, int threadIndex) = 0;
private:
CNEWTON_API static void OnForceAndTorque (const NewtonBody* body, dFloat timestep, int threadIndex)
{
dNewtonDynamicBody* const me = (dNewtonDynamicBody*) NewtonBodyGetUserData(body);
dAssert (me);
me->OnForceAndTorque (timestep, threadIndex);
}
};
-
Julio Jerez
- Moderator

-
- Posts: 12478
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by FSA » Sun Aug 04, 2013 10:56 am
Ah thank you! Works now.
-

FSA
-
- Posts: 322
- Joined: Wed Dec 21, 2011 9:47 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests