How to properly operate a camera?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Wodzu
Posts: 27
Joined: Wed May 07, 2014 5:41 pm

How to properly operate a camera?

Post by Wodzu »

Camera, action! ;)

Guys, I have a camera that is looking at the center (0,0,0). I have triangle in that position. Now, when I try to rotate camera along z-axis by 45 degrees I would expected that my triangle will be still visible in a viewport but it will be rotated.
However, after performing a rotation I am loosing triangle from a viewport. I am totally lost here, I do not know what am I doing wrong?

Code: Select all

 
    ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(0, 0, 200), vector3df(0, 0, 0));
    camera->bindTargetAndRotation(true);
    while (device->run())
    {
        driver->beginScene(true, true, SColor(255, 100, 101, 140));
        camera->setRotation(vector3df(0, 0, 45)); //I want to rotate camera by 45 degrees along z axis but the result is not I would expected.
        smgr->drawAll();
        guienv->drawAll();
 
        driver->endScene();
    }
 
Even setting camera->setRotation(vector3df(0, 0, 0)); will cause that my triangle dissapears from a viewport.

Could you explaine me how to operate camera properly?
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: How to properly operate a camera?

Post by Foaly »

First of all you should set the rotation once and not inside the loop. But that should not cause a problem in this case.

But if you remove the camera->setRotation(vector3df(0, 0, 0)); call, you see your triangle?
Maybe the initial rotation of the camera is different to vector3df(0, 0, 0), so you could try to add the rotation like this:
camera->setRotation(camera->getRotation() + vector3df(0, 0, 45)); //this code must be outside the loop, since it would add the rotation every frame
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: How to properly operate a camera?

Post by Asimov »

Hi Wodzu,

I might be reading it wrong, as I am an amateur myself. But say for instance you rotated a camera you would lose site of the target.
I believe you should rotate the camera around the target.

I needed to do something like this a long time ago in XNA. I can't remember the formula now but if you look up quaternion rotation it might put you on the right track.

Asimov
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to properly operate a camera?

Post by CuteAlien »

Please post enough code so we can compile and test it directly. The problem is likely not in the part of the code you have posted. You might have for example the target position and target on the same place so the camera tries to look at itself. But can't tell if you do that from the code above.
One note - you don't rotate along an axis but around an axis (maybe you meant that, just making sure you don't confuse what Irrlicht does here).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply