Absolutely from scratch tutorial

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Absolutely from scratch tutorial

Postby wahmo » Fri Feb 11, 2011 8:11 pm

Hi,
I'm going to integrate Newton into my project and need a totally from-scratch guide on how to initialize it. The only tutorials around seem to be on the wiki, which makes me use a framework that has zero explanation on how to start up newton. Also, I don't seem to have the "docs" directory that everyone says you should have, so is there anywhere i could get an API reference? Thanks
wahmo
 
Posts: 2
Joined: Fri Feb 11, 2011 7:53 pm

Re: Absolutely from scratch tutorial

Postby Julio Jerez » Fri Feb 11, 2011 8:37 pm

The wiki tutorial are meant to be funtional, and for that you need a graphics API.
My guess tha simple initalization you can make would be something like this

Code: Select all
void ApplyForceAndTorque (const NewtonBody* body, dFloat timestep, int threadIndex)
{
   float gravity[3] = {0, -1, 0};
   NewtonBodySetGravity (body, gravity);
}
void NewtonSetTransform (const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
   VisualEnt* ent = (VisualEnt*) NewtonBodyGetUserData(body) ;

   // set the traform to teh visual entity
}


void main ()
{
   NewtonWorld* const world = NewtonCreate();

   NewtonCollision *box = NewtonCreateBox(world, 1, 1, 1, 0, NULL);

   float matrix [4][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}];
   NewtonBody *body = NewtonCreateBody(world, box, matrix);

   NewtonBodySetUserData(body, visualEntity);
   NewtonBodySetMassMatrix (body, 1, 1, 1, 1);
   NewtonBodySetForceAndTorqueCallback(body, ApplyForceAndTorque);
   NewtonBodySetTransformCallback(body, NewtonSetTransform);

   while (1)
   {

      NewtonUpdate (1.0/60);
      // Do the graphics rendering and oteh stuff
   }

   NewtonDestroy(world);
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest