Problems creating a moving camera. Camera spins 180 degrees.

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
Locien
Posts: 25
Joined: Wed Jul 10, 2013 2:43 am

Problems creating a moving camera. Camera spins 180 degrees.

Post by Locien »

Hi. I'm trying to create a first person camera. I've only used higher level game engines before so all of this stuff is a bit new to me.

When I change the camera's position vector in just one dimension it flips 180 degrees after I've moved a while either forward or backward, and when I move it in the side directions it starts spinning around. I have the coordinates displayed so I know that it moves in a straight line. I'm not even touching the rotation of the camera, I'm only using getPosition() and setPosition(). There must be something I'm not taking into account.

Can someone explain why it happens and how to make it not do so? I would be very grateful!
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: Problems creating a moving camera. Camera spins 180 degr

Post by trollger »

I believe you have to change what the camera is looking at

ICameraSceneNode::setTarget

With set position you are changing where the camera is at, but it will keep looking at the same thing, so it will rotate to face it. If you don't want it to behave like that then call

ICameraSceneNode::bindTargetAndRotation(false);
Locien
Posts: 25
Joined: Wed Jul 10, 2013 2:43 am

Re: Problems creating a moving camera. Camera spins 180 degr

Post by Locien »

trollger wrote:I believe you have to change what the camera is looking at

ICameraSceneNode::setTarget

With set position you are changing where the camera is at, but it will keep looking at the same thing, so it will rotate to face it. If you don't want it to behave like that then call

ICameraSceneNode::bindTargetAndRotation(false);
I tried both bindTargetAndRotation() set to true and false but nothing changed. This time I also displayed the camera's rotation, and the weird thing is that it doesn't change at all, but still the camera flips 180 degrees or to the sides. There must be something I'm missing, because the position vector is doing exactly what it's supposed to do and so is the rotation vector, which is staying at 0 at all times.

When I use getTarget() and setTarget() the screen becomes black when I don't use the WASD keys. I have no idea why.
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: Problems creating a moving camera. Camera spins 180 degr

Post by trollger »

hmmm. Could you please post all relavant code so I can get a better idea of whats going on.
Gawaboumga
Posts: 11
Joined: Sun Jul 14, 2013 3:06 pm

Re: Problems creating a moving camera. Camera spins 180 degr

Post by Gawaboumga »

Look at how it's corrected in the maya camera.
Locien
Posts: 25
Joined: Wed Jul 10, 2013 2:43 am

Re: Problems creating a moving camera. Camera spins 180 degr

Post by Locien »

trollger wrote:hmmm. Could you please post all relavant code so I can get a better idea of whats going on.
Basically:

Code: Select all

 
        vector3df pos = IrrCam->getPosition();
        pos.Z += 0.01*deltatime;
        IrrCam->setPosition(pos);
        IrrCam->updateAbsolutePosition();
 
When I move the camera in the Z dimension it flips 180 degrees at a certain point. When I move the camera in the X direction it spins around in circles. I have both the camera position and rotation displayed. The z position of the camera changes just as it's supposed to, but it appears as if the camera is rotating 180 degrees at a certain point when I move in the z dimension. The relative rotation(getRotation()) is 0 for x, y and z at all times.

Here's how it looks at X: 0, Y: 0, Z: 0.
Image

Here's how it looks at X: 0, Y:0, Z: 102.
Image

The camera is obviously rotating for some reason, but it doesn't show up when you call getRotation().

Here's the function I use for the position and rotation details in case you think I did something wrong:

Code: Select all

    s32 FPS = IrrDriver->getFPS();
    vector3df CurrentPos = IrrCam->getPosition();
    vector3df CurrentRot = IrrCam->getRotation();
    
            stringw temp(L"Irrlicht Engine [FPS: ");
            temp += FPS;
            temp += L"]";
            temp += " X: ";
            temp += CurrentPos.X;
            temp += " Y: ";
            temp += CurrentPos.Y;
            temp += " Z: ";
            temp += CurrentPos.Z;
            temp += " Rot(XYZ): ";
            temp += CurrentRot.X;
            temp += " ";
            temp += CurrentRot.Y;
            temp += " ";
            temp += CurrentRot.Z;
            IrrDevice->setWindowCaption(temp.c_str());
Gawaboumga wrote:Look at how it's corrected in the maya camera.
Can you point out exactly which part? I have no idea what the problem is and what's causing it.
Locien
Posts: 25
Joined: Wed Jul 10, 2013 2:43 am

Re: Problems creating a moving camera. Camera spins 180 degr

Post by Locien »

Okay. After reading this I understand how cameras work in Irrlicht by default. So you have to set a target of the camera either by using a vector or binding it to an invisble scene node. I understand why this could be very nice for certain applications, but I don't really see the need for it in an FPS camera. Apparently you can set your camera to bindTargetAndRotation(true) to change the behavior to what I want to use. But the thing is that it doesn't make a difference whether I set it to false or true. Is this a bug or am I doing something wrong?

I called it from the only camera I have like this: IrrCam->bindTargetAndRotation(true). I also tried false. Neither of them change anything.

Edit: Okay I understand how it works now. I'm sure I can get it to work for all directions and multiple directions at the same time if I look at the FPS camera that comes with Irrlicht.

Code: Select all

 
        vector3df pos = IrrCam->getPosition();
        pos.Z += 0.01*deltatime;
        IrrCam->setPosition(pos);
        pos.Z += 1;
        IrrCam->setTarget(pos);
        IrrCam->updateAbsolutePosition();
 
Still though. If there is an option to not do it this way I'd rather do that. I only want the camera to face the direction it's moving in so I can change the rotation manually with the mouse coordinates.
Post Reply