Thread: Camera problem

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    Camera problem

    The camera I'm working on has a few special requirements that I'm having problems meeting:

    • Camera always moves the direction of the mouse (top of screen - moves forward, bottom - backwards, etc., etc.
    • Camera can be rotated and tilted...but this does not affect it's y plane motion
    • Camera can be zoomed in/out


    The problem I'm having is that when the camera is pitched 90 degrees to look straight down there is no forward motion. As the camera pitch changes the forward motion increases to a maximum when the camera is pitched 0 degrees.

    How do I cause the camera to move forward when looking straight down? I've seen other sites and their suggestions about FPS cameras but this is not really an FPS camera. It is for a strategy game and the camera needs to be able to move across the battlefield according to mouse position regardless of camera pitch.

    Right now for strafing and walking (X motion and Z motion) I'm simply zeroing out the Y component of the vector. This keeps it on the same plane but the disadvantage is when the camera is straight down it will not move forward since forward is down the Y axis at that point.

    Code:
    void Camera::MoveForward(float Dist)
    {
        if (m_cameraType == LAND_OBJECT)
        {
            m_Position += D3DXVECTOR3(m_LookAt.x,0.0f,m_LookAt.z) * Dist;
        }
        else
        {
            m_Position += m_LookAt * Dist;
        }
    
        m_bChanged = true;
    }
    
    void Camera::MoveRight(float Dist)
    {
        if (m_cameraType == LAND_OBJECT)
        {
            m_Position += D3DXVECTOR3(m_Right.x,0.0f,m_Right.z) * Dist;
        }
        else
        {
            m_Position += m_Right * Dist;
        }
    
        m_bChanged = true;
    }
    This is a variation of the common 3 axis camera all of us have seen in countless books. LAND_OBJECT is supposed to act like a land object - no Y motion and it does until you realize that when you look straight down you cannot move forward or backward. Somehow I need to camera forward direction to be disconnected from the camera Z axis...until the camera is pitched so that you move along the Z correctly. I guess the camera I'm sort of going for here is like the one in City Life 2008 and Tropico 3. I think The Sims 2 and The Sims 3 also use a similar camera setup.

    I think I will have to use two orientations. One for where the camera is oriented and one that never pitches which the camera translates along. If the second orientation never pitches and only yaws then it should always be able to move forward as long as the axes are rotated the same amount around the up as the camera is.
    Last edited by VirtualAce; 08-14-2010 at 12:40 PM.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    SOLVED: I added 2 vectors specifically for the motion of the camera - motionLook and motionRight. I transform these when the camera yaws but do not transform them in roll or pitch. I then added two specific functions called MoveForward() and MoveRight() and those translate along the motion vectors. Perfect RTS camera.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Model orientations in 3D
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 12:21 AM
  4. directx problem with camera , nothing happens
    By Anddos in forum Game Programming
    Replies: 1
    Last Post: 04-10-2006, 03:14 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM