Newton 2.0 and Irrlicht 1.7
Posted: Thu Nov 04, 2010 6:29 am
So I've been messing around with some old Newton tutorials. I've gotten a lot of them working but none of them really do any kind of physics that I can see. I can't really do anything on my own because I do not understand everything that is going on. I was hoping someone could shed some light on what this code is doing step by step, I've added in some comments of what I think is going on:
I have the world creation and I drop the newton world at the end, but this tutorial doesn't make any sense to me. I get a cube rotating on the y axis, which I understand why its doing that (last little part of the code above). But all the matrices and things like that are throwing me off.
Any help is appreciated! If anyone could help me write a simple example, such as creating a floor object and a single cube object that is created above it, would be most helpful. All I really need is a bare-bones basic little example to get started, most of the ones I have found simply do not work with the new version of newton.
One thing I noticed is that there are a lot of NULL arguments that I cannot initialize that way. Like the world creation line:
In the new version there aren't any arguments for that call, so I initialized it like this:
And it worked...but there have been other instances of NULL in which I just replaced it with 0. Such as:
Again, any info/help is most appreciated!!!
Code: Select all
//Create Newton World
NewtonWorld* nWorld=NewtonCreate();
Code: Select all
//In the Main
//Create Timer Variable
unsigned int lasttick=0;
//Create a cube node
ISceneNode* boxNode=smgr->addCubeSceneNode();
//Create collision manager
NewtonCollision *collision=NewtonCreateBox(nWorld,0,0,0,0,0);
//Create the newton body for the boxNode irrlicht node
NewtonBody* body=NewtonCreateBody(nWorld,collision);
//Release the collision node
NewtonReleaseCollision(nWorld,collision);
//No idea here
NewtonBodySetUserData(body,boxNode);
//set mass of cube?
NewtonBodySetMassMatrix(body,100.0,1.0,1.0,1.0);
//No idea
matrix4 mat;
mat.setTranslation(vector3df(0,0,0));
NewtonBodySetMatrix(body,&mat.pointer()[0]);
//No idea
float omega[3]={1.0,2.0,1.0};
NewtonBodySetOmega(body,&omega[0]);
Code: Select all
//In the main draw while loop
//update newton world in a timely fashion
if (device->getTimer()->getTime() > lasttick + 10)
{
lasttick = device->getTimer()->getTime();
NewtonUpdate(nWorld, 0.01f);
}
//No Idea
float matrix[4][4];
NewtonBodyGetMatrix(body, &matrix[0][0]);
//Not sure, but rotating the cube?
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
boxNode->setPosition(mat.getTranslation());
boxNode->setRotation(mat.getRotationDegrees());
Any help is appreciated! If anyone could help me write a simple example, such as creating a floor object and a single cube object that is created above it, would be most helpful. All I really need is a bare-bones basic little example to get started, most of the ones I have found simply do not work with the new version of newton.
One thing I noticed is that there are a lot of NULL arguments that I cannot initialize that way. Like the world creation line:
Code: Select all
NewtonWorld* nWorld=NewtonCreate(NULL,NULL);
Code: Select all
NewtonWorld* nWorld=NewtonCreate();
Code: Select all
NewtonCollision *collision=NewtonCreateBox(nWorld,0,0,0,0,NULL);
Code: Select all
NewtonCollision *collision=NewtonCreateBox(nWorld,0,0,0,0,0);