Thread: 2D camera viewing volume

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

    2D camera viewing volume

    Hi Guys,

    I'm working on implementing a 2D camera in OpenGL 3.0. I'm currently stuck with determining the "viewing volume" of the camera, so I can perform culling on world coordinates that are outside the camera.

    The final matrix used to process verticies is calculated manually by:
    Code:
    Matrix2D ModelViewProjection = ModelMatrix * ViewMatrix * ProjectionMatrix;
    The ModelViewProjection matrix is then passed to the GLSL vertex shaders.

    The ViewMatrix and ProjectionMatrix both come from the camera.

    When the camera is created, ViewMatrix is loaded to the identity matrix and the ProjectionMatrix is loaded with an orthographic projection matrix from 0 to viewportWidth for x, and 0 to viewportHeight for y. The ViewMatrix is then updated to "move the world" based on camera movements, negative translation, negative rotation and then scaling (in that order). The translations of the camera are kept in the camera class (so I have the rotation, translation, etc) -- these don't need to be extracted from the matrix.

    My question is, how do I determine if a given world coordinate is visible by the camera? (i.e. it should be drawn)? How do I convert the "camera viewing volume" to world coordinates, it's not the inverse of the ViewMatrix? If I can do that, I can simply check if the given world coordinate is in the camera's "world coordinate viewing volume".

    For reference, calculating the ViewMatrix:
    Code:
    void Camera::UpdateViewMatrix()
    {
       myViewMatrix.LoadIdentity();
    
       // we're really moving the 'world', hence negative
       myViewMatrix.Translate(-myPosition.GetX(), -myPosition.GetY());
    
       myViewMatrix.Rotate(-myRotation);
    
       myViewMatrix.Scale(myZoomFactor, myZoomFactor);
    }
    And calculating the ModelViewProjection matrix that is passed to the GL shaders:
    Code:
    void Camera::CalculateModelViewProjectionMatrix(Matrix2D & aModelMatrix) const
    {
       // model -> eye
       aWorldMatrix.Multiply(GetViewMatrix());
    
       // eye -> clip
       aWorldMatrix.Multiply(GetProjectionMatrix());
    }
    Thanks for any input,
    Zac
    Last edited by zacs7; 01-08-2011 at 08:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Camera problem
    By VirtualAce in forum Game Programming
    Replies: 1
    Last Post: 08-14-2010, 01:23 PM
  2. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. sizing problem
    By beene in forum Game Programming
    Replies: 5
    Last Post: 11-14-2006, 03:38 AM
  5. Camera rotation/movement in 3D world
    By tegwin in forum Game Programming
    Replies: 11
    Last Post: 01-24-2003, 01:43 PM