A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by pHySiQuE » Thu Jul 12, 2012 11:09 am
I converted my fixed joint code to C++/Newton 300. The source is available here:
viewtopic.php?f=11&t=7336When the joint child falls asleep, the parent moves but the child stays asleep. NewtonUserBilateralCallBack() no longer gets called after this point:
http://www.leadwerks.com/post/jointbug.movThe parent is static (mass equals 0). The child has a mass of 1.
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Thu Jul 12, 2012 11:13 am
static bodies do not wake up joints. if yo umove then you need to hnadle that on your side.
static bodies in te engioen are represented by a defaul proxi the is conetetd to all bodes. it is called the sentinel body. if the engine keep track of every thong taht is connet to that it will be too slow
in your code when you move a static body you can use code liek this to make sure that joint coneted to that body are activated
- Code: Select all
void GetConectedBodiesByJoints (NewtonBody* const staticBody)
{
for (NewtonJoint* joint = NewtonBodyGetFirstJoint(staticBody); joint; joint = NewtonBodyGetNextJoint(staticBody, joint)) {
NewtonCustomJoint* const customJoint = (NewtonCustomJoint*) NewtonJointGetUserData(joint);
NewtonBody* const body0 = customJoint->GetBody0();
NewtonBody* const body1 = customJoint->GetBody1();
NewtonBody* const otherBody = (body0 == staticBody) ? body1 : body0;
// do whatever you need to do here
NewtonBodySetFreezeState (otherBody , 0);
}
}
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Thu Jul 12, 2012 11:36 am
Here is my code, which should hopefully handle all types of joints. Although my unfreeze function is being called below, the body stays asleep:
- Code: Select all
void NewtonDynamicsBody::NewtonStaticBodySetFreezeState(NewtonBody* const staticBody, const int& state)
{
NewtonBodySetFreezeState(staticBody, state);
for (NewtonJoint* joint = NewtonBodyGetFirstJoint(staticBody); joint; joint = NewtonBodyGetNextJoint(staticBody, joint))
{
NewtonBody* const body0 = NewtonJointGetBody0(joint);
NewtonBody* const body1 = NewtonJointGetBody1(joint);
if (body0!=staticBody) NewtonBodySetFreezeState(body0, state);
if (body1!=staticBody) NewtonBodySetFreezeState(body1, state);
}
}
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Thu Jul 12, 2012 1:01 pm
you nee to make sure state is 0
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Thu Jul 12, 2012 2:43 pm
It is.

-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Thu Jul 12, 2012 3:37 pm
Oh, I freeze is a very wrong function to call.
Basically the problems is that you are moving a static body, And the engine does not have a notion of static body moving.
The proper way to do that would be to set the velocity and angular velocity for the static body to the equivalent velocity you are using to move it. The engine will automatically since the body velocity and will do the best calculation to enforce the constrain forces at the joint. Then in the next frame to set it to zero again. That will be the correct and best way.
A less accurate way will be to simple read the matrix of the body and write again, of adding an zero impulse to the dynamics body,
this will delete all the internal cache data, this will prbable be the cheapest way
- Code: Select all
dVector linearImpulse(0,0,0,0)
dVector angularImpulse(0,0,0,0)
NewtonBodyApplyImpulsePair(bodyPtr, linearImpulse, angularImpulse);
this will invalidate the cache memory for that body.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Thu Jul 12, 2012 9:01 pm
Works perfectly, thanks.
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest