Irrlicht And Newton Examples Please

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Irrlicht And Newton Examples Please

Post by dejai »

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
Programming Blog: http://www.uberwolf.com
Wyszo
Posts: 49
Joined: Sun Jun 24, 2007 8:44 am

Post by Wyszo »

O_o

http://irrlicht.sourceforge.net/tut_newton.html
(to make this tut work you have to change mat.M to mat.pointer())
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

Wyszo wrote:O_o

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 changelog
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Uhm, no, in case you want the pointer you should use the method. Only when replaceing mat.M[x] you should use mat[x].
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

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.
there are 3 wrappers for newton and you look for source code example :lol:
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

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());

}
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

WoW Thanks for all the effort you guys put in to helping me :D
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
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

are they getting lazier?... just stop responding after the first time.. maybe they'll learn.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

would help to know what the problem was.
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

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
Post Reply