1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Camera problem

Discussion in 'C++' started by Bubba, Aug 31, 2010.

  1. Bubba

    Bubba New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page