Newton and Irrlicht, slightly less complecated tutorials...
Newton and Irrlicht, slightly less complecated tutorials...
I was wondering, would it be possible for someone expierence with c++ programming to write a better understandable tutorial on integrating Newton with Irrlicht. Because I'm sorry but the ones they have now require so many models to be loaded and so many scene nodes to be set, and I can't understand it and it blows my mind. I have been coding c++ and messing with Irrlicht for 1-2 years, and I can't understand Newton with Irrlicht.
Thanks.
"im going crazy"
heh
Thanks.
"im going crazy"
heh
hmm, when you are coding for more than 1year with irrlicht this should be no problem - otherwise you should read the newton manual or general docs on physics in games. I checked that newton tutorial on the day I downloaded irrlicht and I understood everything.... (also remember that these are tutorials on how to combine both APIs.. it doesnt teach you how to use these APIs with all their features, so you should first learn both APIs and then read the tutorial on how to use both)
-
- Posts: 370
- Joined: Mon Aug 29, 2005 10:54 pm
- Location: http://web.utk.edu/~pfox1
Honestly, I thought about writing some better Newton tutorials from what I learned from the SDK examples, but I would just be re-inventing the wheel. If you sit down with them, you will learn, I promise you. It might take longer depending on your knowledge of programming, math and physics, but you will learn. If you look in the FAQ section of this forum, I posted how to do Newton drag and drop, it's almost identical to the source from the Newton example. So why make a tutorial out of that?
Re: Newton and Irrlicht, slightly less complecated tutorials
This is the easiest way i think, I hope it help.
The first thing you need is to understand the way physic engine work.
In Newton yow can create:
NewtonWorld: Is the place where you are goin to place physic bodies and where everything will happend.
NewtonBody: Are objects with mass, that can interact with other NewtonBody-es. They have position, rotation and a shape.
NewtonCollision: Is the shape of a NewtonBody. In Newton you create a NewtonCollision, and then assign it to a NewtonBody.
NewtonJoint: They are not physic objects, they just let you specify the way objects are joined.
Vehicles, Ragdolls, etc. are complex types of Joints.
Undestanding Newton Algorithm
Algorithm #1 -Very easy-
So, let start it.
At this point, you have Newton working well. Objects exist, but they will not get transformed (Moved, rotated, etc).
PART II
A.
To get objects moving you have to tell newton you want to apply some forces to bodies.
in step 2.c. you add this line
NewtonBodySetForceAndTorqueCallback(myBody, setForceAndTorque);
Now newton will call your function setForceAndTorque each time body is affected by forces.
B. NEWTON - IRRLICHT Integration.
Let think you have created a graphical object like this
IAnimatedMeshSceneNode* mySceneNode = smgr->addAnimatedMeshSceneNode(Mesh, ...);
To link the physic object with your graphical object you need two things.
First: Add this line in step 2.c.
NewtonBodySetUserData(myBody, (void*) mySceneNode); //with this you are sending your graphic pointer to Newton.
Second:
To see this objects moving you need a Transform Callback Function.
Soon you will tell Newton "I need you call this function each simulation step"
Now is time to tell newton "I need you call this function each simulation step"
In step 2.c. add the line:
NewtonBodySetTransformCallback(myBody, setTransform);
have fun!
Then i could try to talk about materials, joints and others.
I edited this line: Now newton will call your function setForceAndTorque each time body is affected by forces. Thanks Xaron
The first thing you need is to understand the way physic engine work.
In Newton yow can create:
NewtonWorld: Is the place where you are goin to place physic bodies and where everything will happend.
NewtonBody: Are objects with mass, that can interact with other NewtonBody-es. They have position, rotation and a shape.
NewtonCollision: Is the shape of a NewtonBody. In Newton you create a NewtonCollision, and then assign it to a NewtonBody.
NewtonJoint: They are not physic objects, they just let you specify the way objects are joined.
Vehicles, Ragdolls, etc. are complex types of Joints.
Undestanding Newton Algorithm
Algorithm #1 -Very easy-
Code: Select all
1. Create NewtonWorld
2. Create objects
a. Define NewtonCollision
b. Create NewtonBody
c. Set Body Properties
- You have to repeat step 2 for each body you are creating
3. Update Simulation
4. Destroy NewtonWorld
So, let start it.
Code: Select all
// 1. Create NewtonWorld
NewtonWorld nWorld = NewtonCreate(NULL, NULL);
// 2. Create Objects
//a. Define NewtonCollision
NewtonCollision* myShape = NewtonCreateBox(nWorld, 10,10,10, NULL);
//b. Create NewtonBody
NewtonBody* myBody = NewtonCreateBody(nWorld, myShape);
//c. Set Body Properties
NewtonBodySetMassMatrix(myBody, 1.0f, 1.0f, 1.0f, 1.0f);
// 3. Update Simulation
// inside your while{} loop
while (Looping==true)
{
NewtonUpdate(nWorld, 0.01);
}
// 4. Destroy World
NewtonDestroy(nWorld);
PART II
A.
To get objects moving you have to tell newton you want to apply some forces to bodies.
Code: Select all
static void setForceAndTorque(const NewtonBody* body)
{
float mass;
float Ixx;
float Iyy;
float Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
core::vector3df force(0, -mass * 9.8, 0.0);
core::vector3df torque(0, 0, 0);
NewtonBodyAddForce(body, &force.X);
NewtonBodyAddTorque(body, &torque.X);
}
NewtonBodySetForceAndTorqueCallback(myBody, setForceAndTorque);
Now newton will call your function setForceAndTorque each time body is affected by forces.
B. NEWTON - IRRLICHT Integration.
Let think you have created a graphical object like this
IAnimatedMeshSceneNode* mySceneNode = smgr->addAnimatedMeshSceneNode(Mesh, ...);
To link the physic object with your graphical object you need two things.
First: Add this line in step 2.c.
NewtonBodySetUserData(myBody, (void*) mySceneNode); //with this you are sending your graphic pointer to Newton.
Second:
To see this objects moving you need a Transform Callback Function.
Soon you will tell Newton "I need you call this function each simulation step"
Code: Select all
static void setTransform(const NewtonBody* body, const float* matrix)
{
//get graphic object
ISceneNode* node = (ISceneNode*) NewtonBodyGetUserData(body);
//copy matrix to an irrlicht matrix
core::matrix4 mat;
memcpy(mat.M, matrix, sizeof(float)*16);
//set transformation
node->setPosition(mat.getTranslation() * NewtonToIrr); //Adjust scales, NewtonToIrr = 32. You can find why in the Newton forum.
}
In step 2.c. add the line:
NewtonBodySetTransformCallback(myBody, setTransform);
have fun!
Then i could try to talk about materials, joints and others.
I edited this line: Now newton will call your function setForceAndTorque each time body is affected by forces. Thanks Xaron
Last edited by MarcoTMP on Fri Dec 16, 2005 12:30 pm, edited 1 time in total.
I've seen this a lot in these examples , but have no clue where it is comming from. What file has this in it?
Code: Select all
NewtonToIrr
If it exists in the real world, it can be created in 3d
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
MikeR wrote:I've seen this a lot in these examples, but have no clue where it is comming from. What file has this in it?Code: Select all
NewtonToIrr
You have to supply it the value is 32. Kind of like the answer to the utlimate question of the universe, but - 10.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
Here is the code associated with my tutorial. See if this helps and let me know what questions you have, so I can put answers into the pdf file that I will write for it
http://s-fonline.com/webhosting/dhenton ... csteer.zip
http://s-fonline.com/webhosting/dhenton ... csteer.zip
Re: Newton and Irrlicht, slightly less complecated tutorials
Well this is a point which drived me crazy a while ago.MarcoTMP wrote:in step 2.c. you add this line
NewtonBodySetForceAndTorqueCallback(myBody, setForceAndTorque);
Now newton will call your function setForceAndTorque each time you call NewtonUpdate().
setForceAndTorque will not be called each time you call NewtonUpdate()! It gets only called if the related body is affected by some force, which saves a lot of time.
If you want to use this for things like player movement (ships etc.), ensure you add the following lines when you create your player newton body:
Code: Select all
NewtonBodySetAutoFreeze( body, 0 );
NewtonWorldUnfreezeBody( nWorld, body );
Regards - Xaron