Merci, maintenant, il n'y a aucun bug, cube1 "tombe", mais passe a travers cube2. Pourquoi?
Voici mon code actuel:
#include <cstdlib>
#include <iostream>
#include <IRR/irrlicht.h>
#include <Newton/Newton.h>
using namespace std;
using namespace irr;
using namespace core;
using namespace gui;
using namespace io;
using namespace scene;
using namespace video;
void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body,float timestep, int threadindex)
{
float mass;
float Ixx;
float Iyy;
float Izz;
float force[3];
float torque[3];
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
force[0] = 0.0f;
force[1] = -9.81 * mass;
force[2] = 0.0f;
torque[0] = 0.0f;
torque[1] = 0.0f;
torque[2] = 0.0f;
NewtonBodyAddForce (body, force);
NewtonBodyAddTorque (body, torque);
}
int main(int argc, char **argv)
{
// Initialisation Newtoniénne // ---------------------------------------------------------
NewtonWorld*world = NewtonCreate(0,0);
// Initialisation Irrlichiénne // ---------------------------------------------------------
IrrlichtDevice *irrDev = createDevice (EDT_OPENGL, dimension2d<s32>(800,600), 32, false, true, false, 0);
IVideoDriver* driver = irrDev->getVideoDriver ();
ISceneManager *scene = irrDev->getSceneManager ();
scene->addCameraSceneNode (0, core::vector3df (0,0,0), core::vector3df (5,0,0));
// Creation d'une lumiere ambiente // ----------------------------------------
driver->setAmbientLight(video::SColorf(1.0, 1.0, 1.0,0.0));
// Creation d'une camera FPS // ----------------------------------------------
ICameraSceneNode *camera = scene->addCameraSceneNodeFPS (0,100,10);
camera->setPosition(vector3df(0,1,-5));
// Créer le corp1 // ------------------
NewtonBody*body1 ;
// On Initialise le corp1 // ----------
NewtonCollision* colision= NewtonCreateBox(world,1000,1000,1000,0,0);
body1 = NewtonCreateBody(world,colision) ;
NewtonBodySetCollision(body1, colision);
NewtonReleaseCollision (world, colision);
// On lui assigne une matrice // -----
core::matrix4 mat1 ;
mat1.setTranslation(core::vector3df(0.52,3,0));
NewtonBodySetMatrix(body1,mat1.pointer());
// Configurer la mass et l'inertie //-
NewtonBodySetMassMatrix(body1,20,2,2,2);
// Force de gravité // -----------------
NewtonBodySetForceAndTorqueCallback(body1, ApplyForceAndTorqueEvent);
// Initialisation Irr pour le cube1 // --------
scene::ISceneNode*cube1 = smgr->addCubeSceneNode(10);
cube1->setMaterialTexture(0, driver->getTexture("metal.jpg"));
// Créer le corp2 // ------------------
NewtonBody*body2 ;
// On Initialise le corp2 // ----------
NewtonCollision* colision2= NewtonCreateBox(world,1000,1000,1000,0,0);
body2 = NewtonCreateBody(world,colision2);
NewtonBodySetCollision(body2, colision2);
NewtonReleaseCollision (world, colision2);
// On lui assigne une matrice // -----
core::matrix4 mat2 ;
NewtonBodySetMatrix(body2,mat2.pointer());
// Configurer la mass et l'inertie //-
NewtonBodySetMassMatrix(body2,0,0,0,0);
// Initialisation Irr pour le cube2 // --------
scene::ISceneNode *cube2 = smgr->addCubeSceneNode(10);
cube2->setMaterialTexture(0, driver->getTexture("carrelage.jpg"));
// La boucle principale du rendu // -----------------------------------------
while (irrDev->run ())
{
NewtonBodyGetMatrix(body1,&mat1.M[0]);
cube1->setRotation(mat1.getRotationDegrees());
cube1->setPosition(mat1.getTranslation());
NewtonBodyGetMatrix(body2,&mat2.M[0]);
cube2->setRotation(mat2.getRotationDegrees());
cube2->setPosition(mat2.getTranslation());
NewtonUpdate ( world, 1 / 60 ) ;
//On indique qu'on démarre la scène
driver->beginScene (true, true, video::SColor (255,255,255,255));
scene->drawAll ();
driver->endScene ();
}
return 0 ;
}