I have Succesfully INSTALLED NEWTOn!! Problem, where do i get information on using it with irrlicht. That tutorial is so out of date. I have also succesfully configured it to my system does anyone have any spare source code of showing it working with irrlicht for dev C++ even just pasting it would be cool.
Or a link to it in use? .exe
Irrlicht And Newton Examples Please
Irrlicht And Newton Examples Please
Programming Blog: http://www.uberwolf.com
O_o
http://irrlicht.sourceforge.net/tut_newton.html
(to make this tut work you have to change mat.M to mat.pointer())
http://irrlicht.sourceforge.net/tut_newton.html
(to make this tut work you have to change mat.M to mat.pointer())
i used just mat instead of mat.M and it worked good too. BTW this way was suggested in irrlicht 1.3 changelogWyszo wrote:O_o
http://irrlicht.sourceforge.net/tut_newton.html
(to make this tut work you have to change mat.M to mat.pointer())
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
Ok here goes, I'll be very nice and write a little example:
Code: Select all
#include <irrlicht.h>
#include <newton.h>
//the irrlicht namespaces
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
//the newton callbacks
void applyForceAndTorque(const NewtonBody* body);
void setTransform(const NewtonBody* body, const float* matrix);
int main()
{
/*
create the irrlicht device and
pointers to the scene manager and video driver
*/
IrrlichtDevice* device = createDevice();
ISceneManager* smgr = device->getSceneManager();
IVideoDriver* driver = device->getVideoDriver();
//create the newton world
NewtonWorld* nWorld = NewtonCreate(NULL, NULL);
//create a scene node to represent the newton body
ISceneNode *node = smgr->addCubeSceneNode(10);
//create a box collision of the dimensions 10x10x10 (like the scene node)
NewtonCollision* collision = NewtonCreateBox(nWorld, 10, 10, 10, NULL);
//create a newton body from the collision
NewtonBody* body = NewtonCreateBody(nWorld, collision);
//set up the body
float mass = 10;
float Ixx = 1; //this isn't the right value look up inertia on
float Iyy = 1; //the net and you'll find how to calculate
float Izz = 1; //the accurate inertia
NewtonBodySetMassMatrix(body, mass, Ixx, Iyy, Izz);
//assign the callbacks
NewtonBodySetForceAndTorqueCallback(body, applyForceAndTorque);
NewtonBodySetTransformCallback(body, setTransform);
//assign the scene node as user data in the newton body
NewtonBodySetUserData(body, node);
//add a camera to the scene
ICameraSceneNode *cam = smgr->addCameraSceneNodeMaya();
//create some valuables to keep tract of time
float currentTime = 0;
float timeAccumulator = 0;
float dt = 10; //update every 10 milliseconds
//the main loop
while(device->run())
{
//the usual irrlicht stuff
driver->beginScene(true, true, SColor(100,100,100,100));
smgr->drawAll();
driver->endScene();
//update the newton world
//get the time from the device
f32 newTime = device->getTimer()->getTime();
//calculate the time step
f32 deltaTime = newTime - currentTime;
//update CurrentTime
currentTime = newTime;
//add the time step to the time accumulator
timeAccumulator += deltaTime;
//update when the TimeAccumulator is big enough
while(timeAccumulator >= dt)
{
//update
NewtonUpdate(nWorld, dt/1000); //convert to seconds
timeAccumulator -= dt;
}
}
return 0;
}
// add force and torque to rigid body
void applyForceAndTorque(const NewtonBody* body)
{
//some floats to hold the information of the body
float Ixx;
float Iyy;
float Izz;
float mass;
//get the indo at put it in the above floats
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
//create a force vector with gravity
float force[3] = {0.0f, -mass * 9.8f, 0.0f};
//apply the force
NewtonBodySetForce(body, force);
}
// set the transformation of a rigid body
void setTransform(const NewtonBody* body, const float* matrix)
{
// get the scene node form the body
ISceneNode* node = (ISceneNode*)NewtonBodyGetUserData(body);
//copy the transform matrix to a irrlicht matrix
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
//move the scene node according to the matrix
node->setPosition(mat.getTranslation());
node->setRotation(mat.getRotationDegrees());
}
WoW Thanks for all the effort you guys put in to helping me
But chaning that mat thing does not help the compiler has a problem with the first line...
nWorld = NewtonCreate(NULL, NULL);
But chaning that mat thing does not help the compiler has a problem with the first line...
nWorld = NewtonCreate(NULL, NULL);
Programming Blog: http://www.uberwolf.com
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Who said there was actually A probelm I justed needed some help finding some UP TO DATE Newton Information... Some basic tutorials Etc
Programming Blog: http://www.uberwolf.com