Historique des modifications - Message

Message #10638

Sujet: Test de gravité - Irrlicht + Newton


Type Date Auteur Contenu
Création du message 10-08-2012 15:38:36 Kaze
Bonjour à tous,

comme le titre vous l'explique, j'essaye de créer une gravité avec Newton et le moteur Irrlicht. J'ai créer, grâce au tutos que j'ai pu trouver sur internet, un code qui est censé modélisé un cube et le soumettre a la gravité. Mais mon code ne fonctionne pas, il m'affiche un cube mais il est immobile. Voici mon code :

main.hpp :

#ifndef MAIN_HPP
#define MAIN_HPP

#include <irr/Irrlicht.h>
#include <iostream>
#include "newton.h"

void drawScene();
void force(NewtonBody *body);
void initScene();

#endif

main.cpp :

#include "main.hpp"

static NewtonWorld* world;
static NewtonBody* body;

irr::IrrlichtDevice *device = 0;
irr::video::IVideoDriver *driver = 0;
irr::scene::ISceneManager *sceneManager = 0;

irr::scene::ISceneNode *cubeNode = 0;
irr::scene::ISceneNode *cam = 0;
unsigned int lasttick;

void initScene()
{
device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::u32>(640,480), false);
driver = device->getVideoDriver();
sceneManager = device->getSceneManager();
sceneManager->addSkyBoxSceneNode(driver->getTexture("data/irrlicht2_up.bmp"),driver->getTexture("data/irrlicht2_dn.bmp"),driver->getTexture("data/irrlicht2_rt.bmp"),driver->getTexture("data/irrlicht2_lf.bmp"),driver->getTexture("data/irrlicht2_ft.bmp"),driver->getTexture("data/irrlicht2_bk.bmp"));


world = NewtonCreate (NULL, NULL);

irr::scene::IMesh* cubeMesh = sceneManager->getMesh("data/smallcube.3ds");
cubeNode = sceneManager->addMeshSceneNode(cubeMesh);
cubeNode->setMaterialTexture(0, driver->getTexture("data/crate.jpg"));
cubeNode->setMaterialFlag(irr::video::EMF_LIGHTING, false);

NewtonCollision *collision;
collision = NewtonCreateBox(world, 0, 0, 0, NULL);
body = NewtonCreateBody (world, collision);
NewtonReleaseCollision (world, collision);

NewtonBodySetUserData(body, cubeNode);

float masse = 100.0;
NewtonBodySetMassMatrix(body, masse, 1.0f, 1.0f, 1.0f);

irr::core::matrix4 mat;
mat.setTranslation(irr::core::vector3df(0.0,0.0,0.0));
NewtonBodySetMatrix(body, mat.pointer());

irr::scene::ICameraSceneNode* cam = sceneManager->addCameraSceneNode();
cam->setPosition(irr::core::vector3df(200,100,0));
cam->setTarget(irr::core::vector3df(0,0,0));

irr::core::vector3df inertie;
irr::core::vector3df taille = irr::core::vector3df(10,10,10);
inertie.X = (masse/12)*(pow(taille.Y,2)+pow(taille.Z,2));
inertie.Y = (masse/12)*(pow(taille.X,2)+pow(taille.Z,2));
inertie.Z = (masse/12)*(pow(taille.X,2)+pow(taille.Y,2));
NewtonBodySetMassMatrix (body, masse, inertie.X, inertie.Y, inertie.Z);
force(body);
}

void force(NewtonBody *body){

float masse;
irr::core::vector3df inertie;
float force[3];

NewtonBodyGetMassMatrix (body, &masse, &inertie.X, &inertie.Y, &inertie.Z);

force[0] = 0.0f;
force[1] = -9.81 * masse;
force[2] = 0.0f;

NewtonBodyAddForce(body, force);
}

void drawScene(){

if (device->getTimer()->getTime() > lasttick + 10)
{
lasttick = device->getTimer()->getTime();
NewtonUpdate(world, 0.01f);
}

irr::core::matrix4 mat;
NewtonBodyGetMatrix(body, mat.pointer());
cubeNode->setPosition(mat.getTranslation());
cubeNode->setRotation(mat.getRotationDegrees());
}

int main()
{
initScene();

while(device->run())
{
drawScene();
driver->beginScene(true, true, irr::video::SColor(255,255,255,255));
sceneManager->drawAll();
driver->endScene();
}

NewtonDestroy(world);
device->drop();
return 0;
}

Mais je ne comprend pas où plante le code. Pourriez vous m'aider ?

Merci d'avance.

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
529 invités en ligne
membre en ligne: -
RSS Feed