I think I have found a bug with this Camera, I have asked 2 other people incase I was being stupid but I dont think i am.
I have followed the collisionDetection tutorial example in the irrlicht folder and the code compiles - runs just fine.
Problem is, I can still quite happily float through the mesh of the terrain using the RTSCamera.
I have here the main.cpp file I am using and the RTSCamera files are simply the most up to date ones in the 1st page.
Code: Select all
#include "main.h"
#include "Buster.h"
// Irrlicht Namespaces
using namespace irr;
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
int main()
{
/////SETUP CORE DEVICE AND DRIVER SCENE MANAGER AND GUIENV AND EVENT RECEIVERS/////
device = createDevice(EDT_DIRECT3D8,dimension2d<s32>(512, 512),16,false,false,0);
MainEventReceiver receiver;
HandleKeyEvents keyEvents;
receiver.AddEventReceiver(&keyEvents);
device->setEventReceiver(&receiver);
device->setWindowCaption(L"Valley Attack - Irrlicht engine");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
//ENDING SETUP OF CORE THINGS
Buster bust(smgr,driver,"Bob",50,1,5);
bust.hurt(5000);
////////SETUP HEIGHTMAP TERRAIN
IAnimatedMesh* terrain = smgr->addTerrainMesh("Main_Ground",driver->createImageFromFile("resources/terrain-texture.jpg"),driver->createImageFromFile("heightMaps/heightmap512x512.bmp"),core::dimension2d< f32 >(20.0f, 20.0f),1000.0f,core::dimension2d< s32 >(64, 64));
scene::IAnimatedMeshSceneNode* terrainNode = smgr->addAnimatedMeshSceneNode(terrain);
terrainNode->setMaterialFlag(video::EMF_LIGHTING, false);
terrainNode->setScale(core::vector3df(10,10,10));
terrainNode->setMaterialFlag(video::EMF_WIREFRAME, true);
terrainNode->setMaterialTexture(1, driver->getTexture("resources/detailmap3.jpg"));
//DONE SETTING UP HEIGHTMAP TERRAIN
///////SETUP CAMERA AND STARTING POSITIONS
RTSCamera* camera = new RTSCamera(device,smgr->getRootSceneNode(),smgr,-1,1000.0f,10.0f,10.0f);
camera->setTarget(vector3df(2352,2862,-1317));
camera->setROTX(91); //setup camera to show a nice angle on things!
camera->setROTY(-330);
camera->setTranslateSpeed(50);//speed of cam
////DONE SETTING UP CAMERA STUFF
//camera->setTarget(bust.node->getPosition());
guienv->addStaticText(L"Hello World! This is the Irrlicht software engine running Valley Attacks first trial!",rect<int>(10,10,200,30), true, true, 0, -1);
//////////TRIAL SETTING UP collision detection bellow
scene::ITriangleSelector* selector = 0;
if (terrainNode)
{
//q3node->setPosition(core::vector3df(-1370,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(
terrain->getMesh(0), terrainNode,256);
terrainNode->setTriangleSelector(selector);
}
printf("\nTRIANGLE COUNT IS :%i\n",selector->getTriangleCount());
core::aabbox3d<f32> box = camera->getBoundingBox();
core::vector3df radius = box.MaxEdge - box.getCenter();
scene::ISceneNodeAnimator* anim =smgr->createCollisionResponseAnimator(
selector, camera, radius,
core::vector3df(0,0,0),
core::vector3df(0,0,0));
camera->addAnimator(anim);
selector->drop();
anim->drop();
if(anim){
printf("\nCOEM ON PLEASE DISPLAY");
}
scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture(
"resources/particle.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));
//collision detection end
scene::ISceneNode* selectedSceneNode = 0;
scene::ISceneNode* lastSelectedSceneNode = 0;
core::line3d<f32> line;
core::vector3df intersection;
core::triangle3df tri;
while(device->run())
{
int fps = driver->getFPS();
core::stringw str =fps;
device->setWindowCaption(str.c_str());
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
//HIGHLIGHT THE SELECTED NODE
//test
line.start = camera->getPosition();
printf("\nIT THINKS CAMERA IS AT :%i",line.start.X);
line.end = line.start +
((camera->getTarget() - line.start).normalize() * 1000.0f).normalize();
if (smgr->getSceneCollisionManager()->getCollisionPoint(
line, selector, intersection, tri))
{
bill->setPosition(intersection);
driver->setTransform(video::ETS_WORLD, core::matrix4());
//driver->setMaterial(material);
driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
}
//end test
selectedSceneNode = smgr->getSceneCollisionManager()->
getSceneNodeFromCameraBB(camera);
if (lastSelectedSceneNode)
lastSelectedSceneNode->setMaterialFlag(
video::EMF_LIGHTING, true);
if (selectedSceneNode == terrainNode)
selectedSceneNode = 0;
if (selectedSceneNode)
selectedSceneNode->setMaterialFlag(
video::EMF_LIGHTING, false);
lastSelectedSceneNode = selectedSceneNode;
//END OF HIGHLIGHTED
guienv->drawAll();
driver->endScene();
printf("Camera x:%i, y:%i, z:%i",(int)camera->getAbsolutePosition().X,(int)camera->getAbsolutePosition().Y,(int)camera->getAbsolutePosition().Z);
//printf("Field of view : %i",(int)camera->getROTX()) ;
}
device->drop();
return(0);
}
I really need this one cleared up! Also the triangles are not highlighted when mouse is over them meaning something is messed up their too.
I am fairly sure the selector is created fine, reports 517811 triangles or something and the anim seems to be made fine also.
Thanks in advance,
Andy