I removed the sphere and replace it with the faerie and also removed the plane and instead placed the quake3 map file
Everything works fine and i also tweaked the camera settings and it works fine.
But the real problem started when i implemented collision.Before collision the camera movement was correct but after collision the camera movement in wrong and also there is no collision taking place
Code: Select all
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////Including Headers///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
bool up = false;
bool down = false;
bool right = false;
bool left = false;
int speed=1;
#pragma comment(lib, "Irrlicht.lib")
/////////////////////////////////////////////////////////////////////////////////
/////////////////////Keyboard Input Handling////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
up = event.KeyInput.PressedDown;
break;
case KEY_KEY_S:
down = event.KeyInput.PressedDown;
break;
case KEY_KEY_A:
left = event.KeyInput.PressedDown;
break;
case KEY_KEY_D:
right = event.KeyInput.PressedDown;
break;
}
//return true;
}
return false;
}
};
//////////////////////////////////////////////////////////////////////////////////
////////////////////////********Main Funtion********/////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
MyEventReceiver receiver;
IrrlichtDevice *device =
createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 16,
false, false, false, &receiver);
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
//////////////////////////////////////////////////////////////////////
//////////////////////////Player//////////////////////////////////////
/////////////////////////////////////////////////////////////////////
IAnimatedMeshSceneNode* hero = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../media/faerie.md2"));
if( hero )
{
hero->setPosition(core::vector3df(50,-20,70));
hero->setMaterialFlag(video::EMF_LIGHTING, false);
hero->setMaterialTexture(0, driver->getTexture("../media/faerie5.bmp"));
device->getCursorControl()->setVisible(false);
}
/////////////////////////////////////////////////////////////////////
///////////////////////////Level Map////////////////////////////////
////////////////////////////////////////////////////////////////////
IAnimatedMesh * map;
device->getFileSystem()->addZipFileArchive("../media/map-20kdm2.pk3");
map = smgr->getMesh("20kdm2.bsp");
ISceneNode* node = 0;
if(map)
node= smgr->addOctTreeSceneNode(map->getMesh(0));
if(node)
node->setPosition(vector3df(-1300,-144,-1249));
ITriangleSelector* selector = 0;
if (node)
{
node->setPosition(core::vector3df(-1370,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(
map->getMesh(0), node, 128);
node->setTriangleSelector(selector);
}
/////////////////////////////////////////////////////////////////////////
///////////////////////////Camera and game loop/////////////////////////
////////////////////////////////////////////////////////////////////////
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,50,0));
selector->drop();
camera->addAnimator(anim);
anim->drop();
while(device->run())
{
vector3df c = hero->getPosition();
vector3df d= hero->getRotation();
float diry = ((d.Y+90)*3.14)/180;
if (up)
{
c.X += speed * cos((d.Y) * 3.14/ 180);
c.Z -= speed * speed *sin((d.Y) * 3.14 / 180);
}
if (down)
{
c.X -= speed * cos((d.Y) * 3.14 / 180);
c.Z += speed * sin((d.Y) * 3.14 / 180);
}
if (left)
{
d.Y -= 0.3;
}
if (right)
{
d.Y += 0.3;
}
hero->setRotation(d);
int xf = (c.X-sin(diry)*100);
int yf =(c.Z-cos(diry)*100);
int zf =50;
hero->setPosition(c);
camera->setTarget(c);
c.Y +=200.f;
c.Z -= 150.f;
camera->setPosition(vector3df(xf,zf,yf));
driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
} //device->drop();
return 0;
}