CustomMultiBodyVehicle [SOLVED]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

CustomMultiBodyVehicle [SOLVED]

Postby S_W » Sun Aug 03, 2008 11:37 am

Hi!

I'm currently having trouble implementing the CustomMultiBodyVehicle. Basically I'm doing the following:

Code: Select all
// create the collision shape
NewtonCollision * collision = NewtonCreateBox( mWorld, 1.0f, 1.0f, 1.0f, NULL );

// create the rigid body
NewtonBody * body = NewtonCreateBody( mWorld, collision );

// destory collision shape
NewtonReleaseCollision( mWorld, collision );

// set the body mass and inertia
NewtonBodySetMassMatrix( body, 1000.0f, 1.0f, 1.0f, 1.0f );

// set initial position/quaternation
Ogre::Vector3 pos( 0, 10, 0 );
dFloat matrix[16];
PosOrientToMatrix( pos, Ogre::Quaternion::IDENTITY, matrix );
NewtonBodySetMatrix( body, matrix );

// set pointer to scene node
NewtonBodySetUserData( body, cubenode );

// setup callbacks
NewtonBodySetTransformCallback( body, newtonTransformCallback );
NewtonBodySetForceAndTorqueCallback( body, newtonForceTorqueCallback );


Ogre::Vector3 frontdir( 0, 1, 0 );
Ogre::Vector3 updir( 0, 0, 1 );

Ogre::Vector3 tireposFL( 0, 0, 0 );

// create vehicle
CustomJoint* vehicle = CreateCustomMultiBodyVehicle( &frontdir.x, &updir.x, body );

CustomMultiBodyVehicleAddTire( vehicle, NULL, &tireposFL.x, 35.0f, 0.5f, 0.3f, 0.1f, 75.0f, 10.0f );
//other tires here...

const NewtonBody * tire = CustomMultiBodyVehicleGetTireBody( vehicle, 0 );

NewtonBodySetTransformCallback( tire, tireTransformCallback );
NewtonBodySetForceAndTorqueCallback( tire, tireForceTorqueCallback );


I'm just applying simple gravity to the tire in the callback and I'm using a seperate callback for the body.

Now the problem is that the tire seems to rest at about this position(I'm reading the position in the tireTransformCallback):
(0, -1.0e+009, 0)

Maybe someone who has worked with the new vehicle has a hint what I'm doing wrong here.

Thanks for any advice!
S_W
Last edited by S_W on Sun Aug 03, 2008 3:02 pm, edited 1 time in total.
S_W
 
Posts: 4
Joined: Thu Jul 24, 2008 5:47 pm

Re: CustomMultiBodyVehicle

Postby Dave Gravel » Sun Aug 03, 2008 12:22 pm

I'm not so sure, make sure in the 3d modeler that your mesh is really centred.
Make sure to rotate the mesh correctly too.
Exemple you work with pin like (1,0,0) (0,1,0) in the modeler you place your mesh to work with this axis.
With this axis normally in the modeler you see the under part of the vehicle and the front bumper is on the right.

When it is place right in the modeler normally you have rarely problem to build the vehicle.

PS: If you have wrong side, if the mesh is on the wrong axis from the modeler you can get strange force result and the vehicle can behaving strange.

Good luck.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: CustomMultiBodyVehicle

Postby S_W » Sun Aug 03, 2008 12:33 pm

At the moment I'm just using debug meshes for the bodies, so I'm only seeing the actual bodies...is there maybe anything I'm missing when setting up the vehicle?

    1. Create a body for the vehicle
    2. NewtonBodySetTransformCallback( body, ... )
    3. NewtonBodySetForceAndTorqueCallback( body, ... )
    4. vehicle = CreateCustomMultiBodyVehicle( body, ... )
    5. CustomMultiBodyVehicleAddTire( vehicle, ... )
    6. tirebody = CustomMultiBodyVehicleGetTireBody( vehicle, ... )
    7. NewtonBodySetTransformCallback( tirebody, ... )
    8. NewtonBodySetForceAndTorqueCallback( tirebody, ... )

Might there be a problem if the body and the tirebody are in a positon that would cause them to intersect?
But maybe I've just forgotten a step?

Thanks again!

EDIT: It seems like the order in which the tires are added to the vehicle results in different tire positions? Is this true?
S_W
 
Posts: 4
Joined: Thu Jul 24, 2008 5:47 pm

Re: CustomMultiBodyVehicle

Postby S_W » Sun Aug 03, 2008 2:51 pm

I was able to figure it out by updating the world step by step. Turned out the vehicle just wasn't set up correctly so the wheels flew away very fast.
I also moved the vehicle body before attaching the tires...probably a bad idea ;)

Maybe someone else will find this helpful:

Image

Code: Select all
// create the collision shape, just a simple 1x1x1 box
NewtonCollision * collision = NewtonCreateBox( mWorld, 1.0f, 1.0f, 1.0f, NULL );

// create the rigid body
NewtonBody * body = NewtonCreateBody( mWorld, collision );

// destory collision shape
NewtonReleaseCollision( mWorld, collision );

// set the body mass and inertia
NewtonBodySetMassMatrix( body, 100.0f, 1.0f, 1.0f, 1.0f );

// set pointer to scene node
// NewtonBodySetUserData( body, cubenode );

// callbacks
NewtonBodySetTransformCallback( body, newtonTransformCallback );
NewtonBodySetForceAndTorqueCallback( body, newtonForceTorqueCallback );

Ogre::Vector3 frontdir ( 1, 0, 0 );
Ogre::Vector3 updir    ( 0, 1, 0 );

// front(+)/rear(-), height, left(-)/right(+)
Ogre::Vector3 tireposFL(  1, -0.5, -1 );
Ogre::Vector3 tireposFR(  1, -0.5,  1 );
Ogre::Vector3 tireposRL( -1, -0.5, -1 );
Ogre::Vector3 tireposRR( -1, -0.5,  1 );

vehicle = CreateCustomMultiBodyVehicle( &frontdir.x, &updir.x, body );

CustomMultiBodyVehicleAddTire( vehicle, NULL, &tireposFL.x, 10.0f, 0.3f, 0.2f, 0.1f, 75.0f, 10.0f );
CustomMultiBodyVehicleAddTire( vehicle, NULL, &tireposFR.x, 10.0f, 0.3f, 0.2f, 0.1f, 75.0f, 10.0f );
CustomMultiBodyVehicleAddTire( vehicle, NULL, &tireposRL.x, 10.0f, 0.3f, 0.2f, 0.1f, 75.0f, 10.0f );
CustomMultiBodyVehicleAddTire( vehicle, NULL, &tireposRR.x, 10.0f, 0.3f, 0.2f, 0.1f, 75.0f, 10.0f );


The code above creates a simple vehicle without any visual mesh, but this should be quite easy by using the transform callbacks:

Code: Select all
const NewtonBody * tire = CustomMultiBodyVehicleGetTireBody( vehicle, 0 );
NewtonBodySetTransformCallback( tire, tireTransformCallback );


S_W
S_W
 
Posts: 4
Joined: Thu Jul 24, 2008 5:47 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 27 guests

cron