Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Moving a camera

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 KaiserJohan   Members   

2262
Like
1Likes
Like

Posted 07 January 2013 - 11:40 AM

So far I've used a static camera which simply sits at Vec3(0.0f) and stares down negative Z axis. I've got geometry like cubes to play correctly when translating, scaling, rotating etc, but now I want to try get the camera move correctly.

 

I am using glm, and to get a view matrix I am using the glm::lookAt method with the Vec3 data provided from my camera struct

 

Mat4 CreateViewMatrix(const Camera& camera)
    {
        return glm::lookAt(camera.CameraPosition, camera.TargetVector, camera.UpVector);
    }

 

 

Here is my camera definition:

 

/* Camera definition */
    struct Camera
    {
        Vec3 CameraPosition;
        Vec3 TargetVector;
        Vec3 UpVector;

        Camera();
    };


    /* Camera inlines */
    inline Camera::Camera() : CameraPosition(0.0f), TargetVector(0.0f, 0.0f, -1.0f), UpVector(0.0f, 1.0f, 0.0f)
    {
    }

 

 

I basically try to move it like this between the rendering:

 

 // move camera
            if (evnt.KeySymbol == LEFT)
                activeScene->GetSceneCamera().CameraPosition -= Vec3(0.1f, 0.0f, 0.0f);

            if (evnt.KeySymbol == RIGHT)
                activeScene->GetSceneCamera().CameraPosition += Vec3(0.1f, 0.0f, 0.0f);

            if (evnt.KeySymbol == UP)
                activeScene->GetSceneCamera().CameraPosition -= Vec3(0.0f, 0.0f, 0.1f);

            if (evnt.KeySymbol == DOWN)
                activeScene->GetSceneCamera().CameraPosition += Vec3(0.0f, 0.0f, 0.1f);

 

 

but this creates some strange results. For example, instead of the 'strafing' effect I would expect when moving the camera on the x-axis, it is as if I am rotating it, standing still. And when I try to move it in Z-axis, I really cant quite explain how it looks like, kinda like 'zooming' down the Z axis or something..

 

So I guess it's not as easy as I think?

 



#2 Zaoshi Kaba   Members   

8289
Like
1Likes
Like

Posted 07 January 2013 - 12:10 PM

Sounds like you're doing FPS/3rd person camera, in this case you need to offset both camera.CameraPosition and camera.TargetVector by same amount.

P.S. if player is holding RIGHT and DOWN he'll move (0.1f, 0.0f, 0.1f) which is longer distance than just (0.1f, 0.0f, 0.0f).

Edited by Zaoshi Kaba, 07 January 2013 - 12:11 PM.


#3 KaiserJohan   Members   

2262
Like
0Likes
Like

Posted 07 January 2013 - 04:25 PM

Ohhh yes makes sense. Works like a charm, thanks.



#4 Ravnock   Members   

317
Like
0Likes
Like

Posted 08 January 2013 - 09:10 AM

Ohhh yes makes sense. Works like a charm, thanks.

One suggestion: It's usual when you move something in a game, always make the movement depending on deltaTime (time increment between frames)






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.