Hello
The wow camera i had before was really sloppy, i have since then cleaned it us into one camera class. Basically, all you need to do is instantiate it, and it would just work.
So this is a third person camera that you attach a sceneNode to, once it is attached you can press s d f e to move it , w and r to rotate it, the camera would follow, you can also zoom in and out by scrolling the wheel, the right mouse button would rotate the sceneNode and the left would move the camera in a spherical fashion around the sceneNode,
the camera is called IamarCamera since I am building it for my newly found company Iamar , there are no animation bindings so the object doesn't animate it only translates, this is mainly because we have so many different mesh formats , in the future I will write one for MD2 format. You can find it now on my personal website
http://www.freewebs.com/juliusctw/
This is done in linux, so you might have to tweek it a little for window users, the following is how the main.cpp would look like using IamarCamera
//*******************************
#include <irrlicht.h>
#include "IamarCamera.h"
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::ISceneNode* terrain)
{
}
bool OnEvent(SEvent event)
{
return false;
}
private:
scene::ISceneNode* Terrain;
};
//* you don't really need the receiver, the camer would work with out it
int main()
{
// create device
IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024, 768));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// add Iamar logo
env->addImage(driver->getTexture("logo.png"),
core::position2d<s32>(-40,-40));
// add some help text
gui::IGUIStaticText* text = env->addStaticText(
L"Press 's d f e w r' for movement",
core::rect<s32>(10,453,200,475), true, true, 0, -1, true);
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../../media/sydney.md2"));
if (anms)
{
anms->setMaterialFlag(video::EMF_LIGHTING, false);
anms->setMD2Animation(scene::EMAT_RUN);
anms->setFrameLoop(320, 367);
anms->setAnimationSpeed(80);
anms->setPosition(core::vector3df(1900*2,255*2,3700*2));
anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}
// add camera
// This is the only part required to use this camera
// besides the headers.
// important ::::::::::::::::::::::::::::::::::::::::::::::
//
//
//
scene::IamarCamera* Icamera;
Icamera = new scene::IamarCamera((scene::ISceneNode*)anms, smgr, -1);
smgr->setActiveCamera(Icamera);
// important ::::::::::::::::::::::::::::::::::::::::::::::
// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../../media/terrain-heightmap.bmp");
terrain->setScale(core::vector3df(40, 4.4f, 40));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("../../media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("../../media/detailmap3.jpg"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(10.0f, 20.0f);
// create triangle selector for the terrain
scene::ITriangleSelector* selector
= smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);
selector->drop();
// create event receiver
MyEventReceiver receiver(terrain);
device->setEventReceiver(&receiver);
// create skybox
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
smgr->addSkyBoxSceneNode(
driver->getTexture("../../media/irrlicht2_up.jpg"),
driver->getTexture("../../media/irrlicht2_dn.jpg"),
driver->getTexture("../../media/irrlicht2_lf.jpg"),
driver->getTexture("../../media/irrlicht2_rt.jpg"),
driver->getTexture("../../media/irrlicht2_ft.jpg"),
driver->getTexture("../../media/irrlicht2_bk.jpg"));
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
/*
That's it, draw everything. Now you know how to use terrain in Irrlicht.
*/
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );
smgr->drawAll();
env->drawAll();
driver->endScene();
// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}