Tu m'excuseras, mais ça me dérange un peu de passer mes fichiers 3DS, comme ca ...
Du coup, je reviendrais plus tard sur le rendu de la map.
J'ai ajouter une caméra attacher à la voiture, qui la suit en translation, et rotation comme sur le jeu trackmania.
Il me reste juste à mettre l'apect physique.
J'ai commencé à faire une gestion de collision avec irrlicht, et j'ai eu quelques soucis avec c'est qu'un moteur 3D.
Du coup, j'ai attaqué la gestion de collision avec Newton.
Mais j'ai un petit soucis sur une ligne car elle met 20minutes à s'éxécuter, et en plus ca plante lol
NewtonTreeCollisionEndBuild(g_newtonmap, 1);
Voici le code de ma classe:
#include "StdAfx.h"
#include "Collision.h"
#include "Trace.hpp"
CCollision::CCollision(void)
{
selectedSceneNode = 0;
lastSelectedSceneNode = 0;
// Init newton
nWorld = NewtonCreate(NULL, NULL);
// Set up default material properties for newton
int i = NewtonMaterialGetDefaultGroupID(nWorld);
NewtonMaterialSetDefaultFriction (nWorld, i, i, 0.8f, 0.4f);
NewtonMaterialSetDefaultElasticity (nWorld, i, i, 0.3f);
NewtonMaterialSetDefaultSoftness (nWorld, i, i, 0.05f);
NewtonMaterialSetCollisionCallback (nWorld, i, i, NULL, NULL, NULL, NULL);
}
CCollision::~CCollision(void)
{
}
void CCollision::GestionCollision(void)
{
}
void CCollision::InitNewton(void)
{
nWorld = NewtonCreate (NULL, NULL); // On initialise nWorld
}
void CCollision::InitCollisionMap()
{
g_newtonmap = NewtonCreateTreeCollision(nWorld, NULL);
NewtonTreeCollisionBeginBuild(g_newtonmap);
int cMeshBuffer, j;
int v1i, v2i, v3i;
IMeshBuffer *mb;
float vArray[9]; // vertex array (3*3 floats)
int tmpCount = 0;
for (cMeshBuffer=0; cMeshBuffer<meshpiste->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
{
mb = meshpiste->getMesh(0)->getMeshBuffer(cMeshBuffer);
video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();
u16* mb_indices = mb->getIndices();
// add each triangle from the mesh
for (j=0; j<mb->getIndexCount(); j+=3)
{
v1i = mb_indices[j];
v2i = mb_indices[j+1];
v3i = mb_indices[j+2];
vArray[0] = mb_vertices[v1i].Pos.X;
vArray[1] = mb_vertices[v1i].Pos.Y;
vArray[2] = mb_vertices[v1i].Pos.Z;
vArray[3] = mb_vertices[v2i].Pos.X;
vArray[4] = mb_vertices[v2i].Pos.Y;
vArray[5] = mb_vertices[v2i].Pos.Z;
vArray[6] = mb_vertices[v3i].Pos.X;
vArray[7] = mb_vertices[v3i].Pos.Y;
vArray[8] = mb_vertices[v3i].Pos.Z;
std::cout << "\
";
NewtonTreeCollisionAddFace(g_newtonmap, 3, (float*)vArray, 12, 1);
}
}
NewtonTreeCollisionEndBuild(g_newtonmap, 1);
g_newtonmapbody = NewtonCreateBody(nWorld, g_newtonmap);
// set the newton world size based on the bsp size
float boxP0[3];
float boxP1[3];
float matrix[4][4];
NewtonBodyGetMatrix (g_newtonmapbody, &matrix[0][0]);
NewtonCollisionCalculateAABB (g_newtonmap, &matrix[0][0], &boxP0[0], &boxP1[0]);
// you can pad the box here if you wish
//boxP0.y -= somevalue;
//boxP1.y += somevaluef;
NewtonSetWorldSize (nWorld, (float*)boxP0, (float*)boxP1);
}
void CCollision::InitCollisionCar()
{
NewtonCube *tmp = new NewtonCube;
tmp->mesh = meshvoiture;
tmp->node = nodevoiture;
// Create a box primitive. 38 is just an estimated value of the size of the model,
tmp->collision = NewtonCreateBox(nWorld, 38, 38, 38, NULL);
tmp->body = NewtonCreateBody(nWorld, tmp->collision);
// Set user data pointer to the scene node
NewtonBodySetUserData(tmp->body, tmp->node);
// Set body mass & inertia matrix
NewtonBodySetMassMatrix (tmp->body, 10.0f, 150.0f, 150.0f, 150.0f);
// Set the freeze threshhold to 1 unit (default is 0.01 but irrlight uses a large unit scale)
NewtonBodySetFreezeTreshold(tmp->body, 1.0, 1.0, 1.0);
// Set callback functions for the body
NewtonBodySetTransformCallback(tmp->body, SetMeshTransformEvent);
NewtonBodySetForceAndTorqueCallback(tmp->body, ApplyForceAndTorqueEvent);
// Set the position of the body
matrix4 mat;
mat.setTranslation(nodevoiture->getPosition());
NewtonBodySetMatrix(tmp->body, mat.pointer());
}
//////////////////////////////////////////////////////////////////////////
//
// The last 2 functions are callbacks from newton
//
//////////////////////////////////////////////////////////////////////////
void _cdecl CCollision::SetMeshTransformEvent(const NewtonBody* body, const float* matrix)
{
// copy the matrix into an irrlicht matrix4
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
// Retreive the user data attached to the newton body
ISceneNode *tmp = (ISceneNode *)NewtonBodyGetUserData(body);
if (tmp)
{
// Position the node
tmp->setPosition(mat.getTranslation()); // set position
tmp->setRotation(mat.getRotationDegrees()); // and rotation
}
}
void _cdecl CCollision::ApplyForceAndTorqueEvent (const NewtonBody* body)
{
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] = NEWTON_GRAVITY * mass;
force[2] = 0.0f;
torque[0] = 0.0f;
torque[1] = 0.0f;
torque[2] = 0.0f;
NewtonBodyAddForce (body, force);
NewtonBodyAddTorque (body, torque);
}
Si vous avez des idées pour m'aider ca serai cool !!!
merci d'avance
@+
Julien