Problems with cameras

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
giacomo986
Posts: 5
Joined: Fri Feb 27, 2015 5:31 pm

Problems with cameras

Post by giacomo986 »

Hello everyone,

I modified tutorial 18 SplitScreen to show you a problem that I can't solve:

I want to make sure that a camera moves as a fps camera is connected to, so i modified the example:

to connect camera[2] (normal camera) to camera[3] (fps camera) I added:

Code: Select all

camera[2]->bindTargetAndRotation(true);
to:

Code: Select all

    camera[0] = smgr->addCameraSceneNode(0, vector3df(50,0,0), vector3df(0,0,0));
    //Top
    camera[1] = smgr->addCameraSceneNode(0, vector3df(0,50,0), vector3df(0,0,0));
    //Left
    camera[2] = smgr->addCameraSceneNode(0, vector3df(0,0,50), vector3df(0,0,0));
    camera[2]->bindTargetAndRotation(true);
    //User-controlled
    camera[3] = smgr->addCameraSceneNodeFPS();
    // don't start at sydney's position
    if (camera[3])
        camera[3]->setPosition(core::vector3df(-50,0,-50));
 
Then in the loop I added

Code: Select all

            camera[2]->setPosition(camera[3]->getPosition() + core::vector3df(0,300,0));
            camera[2]->setRotation(camera[3]->getRotation());
to update position and rotation of camera[2] like camera[3]

here is the loop:

Code: Select all

while(device->run())
    {
        //Set the viewpoint to the whole screen and begin scene
        driver->setViewPort(rect<s32>(0,0,ResX,ResY));
        driver->beginScene(true,true,SColor(255,100,100,100));
        //If SplitScreen is used
        if (SplitScreen)
        {
            //Activate camera1
            smgr->setActiveCamera(camera[0]);
            //Set viewpoint to the first quarter (left top)
            driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
            //Draw scene
            smgr->drawAll();
            //Activate camera2
            smgr->setActiveCamera(camera[1]);
            //Set viewpoint to the second quarter (right top)
            driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2));
            //Draw scene
            smgr->drawAll();
            //Activate camera3
 
            camera[2]->setPosition(camera[3]->getPosition() + core::vector3df(0,300,0));
            camera[2]->setRotation(camera[3]->getRotation());
 
            smgr->setActiveCamera(camera[2]);
            //Set viewpoint to the third quarter (left bottom)
            driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY));
            //Draw scene
            smgr->drawAll();
            //Set viewport the last quarter (right bottom)
            driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY));
        }
        //Activate camera4
        smgr->setActiveCamera(camera[3]);
        //Draw scene
        smgr->drawAll();
        driver->endScene();
Now I link the video of the result:
https://youtu.be/55onpDY11UE

The problem is if i move only the mouse there is no problem, when I use arrow keys the camera moves in wrong ways.

I don't understand where is my mistake.

Can anybody help me?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problems with cameras

Post by CuteAlien »

Between the setPosition and setRotation you have to add an camera[2]->updateAbsolutePosition().
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
giacomo986
Posts: 5
Joined: Fri Feb 27, 2015 5:31 pm

Re: Problems with cameras

Post by giacomo986 »

That works nicely, thank you.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Problems with cameras

Post by Seven »

if you made camera 1 and 2 children of camera 3, then you wouldnt have to update them at all, they would automagically move with camera 3
giacomo986
Posts: 5
Joined: Fri Feb 27, 2015 5:31 pm

Re: Problems with cameras

Post by giacomo986 »

Seven wrote:if you made camera 1 and 2 children of camera 3, then you wouldnt have to update them at all, they would automagically move with camera 3
My needs are different. The transformations of the cameras are complex:

https://youtu.be/7UOVn3XjmnM
Post Reply