I've entered the code, the land2.obj file is the one who has no collision, the other: land1.obj works perfect. Anyone who knows how to put collision on the second mesh? (Whitout losing the collision of the first mesh)
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
// let user select driver type
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL
1.5\n"\
" (d) Software Renderer\n (e) Burning's Software
Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_SOFTWARE2;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
// create device
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<s32>(640,
480), 16, false);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMesh* q3levelmesh =
smgr->getMesh("../../media/land2.obj");
scene::ISceneNode* q3node = 0;
if (q3levelmesh)
q3node =
smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
scene::ITriangleSelector* selector = 0;
if (q3node)
{
q3node->setPosition(core::vector3df(-10,-10,-10));
q3node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
selector =
smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node,
128);
q3node->setTriangleSelector(selector);
selector->drop();
}
scene::IAnimatedMesh* q4levelmesh =
smgr->getMesh("../../media/land1.obj");
scene::ISceneNode* q4node = 0;
if (q4levelmesh)
q4node =
smgr->addOctTreeSceneNode(q4levelmesh->getMesh(0));
if (q4node)
{
q4node->setPosition(core::vector3df(0,0,0));
q4node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
selector =
smgr->createOctTreeTriangleSelector(q4levelmesh->getMesh(0), q4node,
128);
q4node->setTriangleSelector(selector);
selector->drop();
}
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0,
0, true);
camera->setPosition(core::vector3df(-100,50,-150));
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();
// disable mouse cursor
device->getCursorControl()->setVisible(false);
// add billboard
scene::IBillboardSceneNode * bill =
smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0,
driver->getTexture("../../media/particle.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZBUFFER, false);
bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));
// Add a light
smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
video::SColorf(1.0f,1.0f,1.0f,1.0f),
600.0f);
scene::ISceneNode* selectedSceneNode = 0;
scene::ISceneNode* lastSelectedSceneNode = 0;
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
smgr->drawAll();
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() -
line.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df tri;
if
(smgr->getSceneCollisionManager()->getCollisionPoint(
line, selector, intersection, tri))
{
bill->setPosition(intersection);
driver->setTransform(video::ETS_WORLD,
core::matrix4());
driver->draw3DTriangle(tri,
video::SColor(0,255,0,0));
}
selectedSceneNode =
smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);
if (selectedSceneNode == q3node || selectedSceneNode ==
bill)
selectedSceneNode = 0;
if (selectedSceneNode == q4node || selectedSceneNode == bill)
selectedSceneNode = 0;
if (selectedSceneNode)
selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
lastSelectedSceneNode = selectedSceneNode;
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Collision detection example -
Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}