Newton-Irrlicht integration question with code , help !!

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
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

Newton-Irrlicht integration question with code , help !!

Post by chinanzio »

hello , i am trying to make an aplication with Newton-Irrlicht integration , i have investigated and i've got a question , i can not make work a treeCollision integrated when the file loaded is not a .bsp one , i want to use an .obj as mesh to be loaded in irrlicht and then load it into newton engine as in the code below, i've pasted the code summarized as well as i can , i hope to explain me well



#include <irrlicht.h>
#include <newton.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

void CleanUp(void);
void DrawScene(void);
static NewtonWorld* nWorld;
static NewtonBody* rigidBodyBox;
unsigned int lasttick;

IrrlichtDevice *device;

int main(){

//Irrlicht , this is not important
device = createDevice( video::EDT_DIRECT3D8,
dimension2d<s32>(640, 480),
16,
false, false, false,
0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, false);
camera->setPosition(core::vector3df(-100,90,100));
device->getCursorControl()->setVisible(false);

scene::IAnimatedMesh* g_map;
scene::ISceneNode* g_mapnode;
//here when i try with an .obj i get the problem
g_map = smgr->getMesh("physicstest.bsp");
g_mapnode = smgr->addOctTreeSceneNode(g_map->getMesh(0));
g_mapnode->setMaterialFlag(video::EMF_LIGHTING, false);



//Newton
nWorld = NewtonCreate (NULL, NULL);
atexit(CleanUp);

//I believe that here begins my prblem
NewtonCollision* g_newtonmap;
NewtonBody* g_newtonmapbody;

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<g_map->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
{
mb = g_map->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;

NewtonTreeCollisionAddFace(g_newtonmap, 3, (float*)vArray, 12, 1);
}

}

NewtonTreeCollisionEndBuild(g_newtonmap, 0);
g_newtonmapbody = NewtonCreateBody(nWorld, g_newtonmap);
//Here ends

while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));

smgr->drawAll();
guienv->drawAll();

driver->endScene();
}
device->drop();
return 0;
}

void CleanUp (){
NewtonDestroy (nWorld);
}
void DrawScene() {
if (device->getTimer()->getTime() > lasttick + 10) {
lasttick = device->getTimer()->getTime();
NewtonUpdate(nWorld, 0.01f);
}
}

The error that jumps is one of the sending reports to microsoft bla bla...
could someone help me ? :lol:
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

tryed that code with my map (.x) the same problem...

do u have some Newton collision toturial or example ??
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

simple....it is because of the following line...
video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();

obj meshes do not have S3DVertex2TCoords therefor it crashes. You need to implement some kind of check to determine the vertex format.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

This has been taked from the Mercior Demo tutorial I think. He states that he loads his collision vertex data from his lightmap texture coordinates.

Sudi is correct. I think he means to say that .obj nor .x files contain more than one set of texture coordinate data. You can sumply use the vertex coordinates, from S3DVertex.

Try replacing

Code: Select all

video::S3DVertex2TCoords* mb_vertices =(irr::video::S3DVertex2TCoords*)mb->getVertices();
with

Code: Select all

S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();
Signature? I ain't signin nuthin!
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

Post by chinanzio »

oldskoolPunk wrote:This has been taked from the Mercior Demo tutorial I think. He states that he loads his collision vertex data from his lightmap texture coordinates.

Sudi is correct. I think he means to say that .obj nor .x files contain more than one set of texture coordinate data. You can sumply use the vertex coordinates, from S3DVertex.

Try replacing

Code: Select all

video::S3DVertex2TCoords* mb_vertices =(irr::video::S3DVertex2TCoords*)mb->getVertices();
with

Code: Select all

S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();

YES !! this works very well , thank you !! are you a genius ?
Post Reply