How to make a 3d rpg camera in 10 steps

A forum to store posts deemed exceptionally wise and useful
FigMan
Posts: 2
Joined: Wed Apr 04, 2007 6:54 pm

Post by FigMan »

thanks
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

i have updated the link if anywant want it but it is just the main.cpp and i didnt check it for errors so any errors report me!
cdrwolfe
Posts: 100
Joined: Thu Nov 15, 2007 5:38 pm
Location: Cranfield University

Post by cdrwolfe »

Has anyone tried this in C# successfully?

Regards Wolfe
cyberpunkpor
Posts: 9
Joined: Thu Oct 25, 2007 10:03 am

Working with 1.4 - Just copy and paste

Post by cyberpunkpor »

Working with 1.4 - Just copy and paste

Code: Select all

#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")
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;
   }

};
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();
ISceneNode* hero = smgr->addCubeSceneNode();
IAnimatedMesh * movingplane;
    
movingplane = smgr->addHillPlaneMesh("floor",
		core::dimension2d<f32>(20,20),
		core::dimension2d<u32>(40,40), 0, 0,
		core::dimension2d<f32>(0,0),
		core::dimension2d<f32>(10,10));


 IAnimatedMeshSceneNode *floor=smgr->addAnimatedMeshSceneNode(movingplane);
    if (hero)
    {
        hero->setMaterialFlag(EMF_LIGHTING, false);
    }
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
 while(device->run())
    {
core::vector3df c = hero->getPosition();
         core::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 * 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.1;
         }
         if (right)
         {
            d.Y += 0.1;
         }
hero->setRotation(d);
    int xf = (c.X-sin(diry)*125);
int yf =(c.Z-cos(diry)*125);
int zf =100;

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;
}
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

:) goood (just posting)
chaitanyaraghav
Posts: 12
Joined: Mon Jul 07, 2008 4:26 pm
Location: India

Post by chaitanyaraghav »

Thanks a ton cyberpunkpor for making it compiling in 1.4

and an excellent tutorial Omar
i was banging my head for days and now i perfectly how 3rd person rpg cam works!!
cheers! :lol:
Nobody is perfect!!
nd i am nobody!!
Pyritie
Posts: 120
Joined: Fri Jan 16, 2009 12:59 pm
Contact:

Post by Pyritie »

Is the OP still working on this?
Tannz0rz
Posts: 35
Joined: Fri May 08, 2009 12:25 am
Location: Orlando FL, USA

Post by Tannz0rz »

Wow, that's a cool approach to working with a 3rd person camera. Nice work.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

thanks all, i like to keep things simple, anyway i was just making another tutorial for camera special effects...but i have to finish with an equation i am developing. :P
Post Reply