Bonjour,
Je débute avec Newton et je voudrais gérer une collision de deux cubes.
Je mets donc ce code là trouvé avec un tuto:
#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 ApplyForce(const NewtonBody *nbody)
{
float mass, ixx, iyy, izz;
NewtonBodyGetMassMatrix(nbody, &mass, &ixx, &iyy, &izz);
float force[3] = {0, mass * -90.82, 0};
NewtonBodyAddForce(nbody, force);
}
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 // ----------
body1 = NewtonCreateBody(world,NewtonCreateBox(world,1,1,1,0)) ;
// On lui assigne une matrice // -----
matrix4 mat1 ;
mat1.setTranslation(vector3df(0.52,3,0));
NewtonBodySetMatrix(body1,&mat1.M[0]);
// Configurer la mass et l'inertie //-
NewtonBodySetMassMatrix(body1,10,2,2,2);
// Force de gravité // -----------------
NewtonBodySetForceAndTorqueCallback(body1, ApplyForce);
// Initialisation Irr pour le cube1 // --------
ISceneNode*cube1 = scene->addCubeSceneNode(1);
cube1->setMaterialTexture(0, driver->getTexture("t351sml.jpg"));
// Créer le corp2 // ------------------
NewtonBody*body2 ;
// On Initialise le corp2 // ----------
body2 = NewtonCreateBody(world,NewtonCreateBox(world,1,1,1,0)) ;
// On lui assigne une matrice // -----
matrix4 mat2 ;
NewtonBodySetMatrix(body2,&mat2.M[0]);
// Configurer la mass et l'inertie //-
NewtonBodySetMassMatrix(body2,0,0,0,0);
// Initialisation Irr pour le cube2 // --------
ISceneNode*cube2 = scene->addCubeSceneNode(1);
cube2->setMaterialTexture(0, driver->getTexture("t351sml.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 ;
}
Mais le débugeur trouve des bugs:
error C2248: 'irr::core::CMatrix4<T>::M' : impossible d'accéder à private membre déclaré(e) dans la classe 'irr::core::CMatrix4<T>'
1> with
1> [
1> T=irr::f32
1> ]
voir la déclaration de 'irr::core::CMatrix4<T>::M'
1> with
1> [
1> T=irr::f32
1> ]
error C2664: 'NewtonBodySetForceAndTorqueCallback' : impossible de convertir le paramètre 2 de 'void (__cdecl *)(const NewtonBody *)' en 'NewtonApplyForceAndTorque'
1> Aucune fonction ayant ce nom dans la portée ne correspond au type de la cible
error C2660: 'NewtonCreateBox' : la fonction ne prend pas 5 arguments
error C2248: 'irr::core::CMatrix4<T>::M' : impossible d'accéder à private membre déclaré(e) dans la classe 'irr::core::CMatrix4<T>'
1> with
1> [
1> T=irr::f32
1> ]
voir la déclaration de 'irr::core::CMatrix4<T>::M'
1> with
1> [
1> T=irr::f32
1> ]
error C2882: 'scene' : utilisation non conforme d'un identificateur d'espace de noms dans l'expression
error C2227: la partie gauche de '->addCubeSceneNode' doit pointer vers un type class/struct/union/générique
error C2248: 'irr::core::CMatrix4<T>::M' : impossible d'accéder à private membre déclaré(e) dans la classe 'irr::core::CMatrix4<T>'
1> with
1> [
1> T=irr::f32
1> ]
voir la déclaration de 'irr::core::CMatrix4<T>::M'
1> with
1> [
1> T=irr::f32
1> ]
error C2248: 'irr::core::CMatrix4<T>::M' : impossible d'accéder à private membre déclaré(e) dans la classe 'irr::core::CMatrix4<T>'
1> with
1> [
1> T=irr::f32
1> ]
voir la déclaration de 'irr::core::CMatrix4<T>::M'
1> with
1> [
1> T=irr::f32
1> ]