Thread: 2D camera viewing volume

Hybrid 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
    Oh okay :-).

    Thanks guys.

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    68
    Are you sure that you are using the correct order of operation on your matrix'? Open gl uses a left handed coordinate system, so you have to do your matrix multiplication as Projection * View * Translation * Scaling * Rotation.


    But, if it works, then keep going.

    Onto your question.

    There are many ways.. The first one that comes to mind is you can transform the vertex by the ModelViewProjection, then make sure to divide the vertex by its w component and then make sure all the components of the vertex are greater than or equal to -1 AND less than or equal to 1. If its true, then the vertex is within the cameras viewing bounds;

    Code:
    bool InCamerasBounds(Vertex testpoint){
    
    testpoint*=ModelViewProjection;// transform the point
    testpoint.x/=testpoint.w;
    testpoint.y/=testpoint.w;
    testpoint.z/=testpoint.w;
    if((testpoint.x <-1.0) | (testpoint.x >1)) return false;// outside the frustum
    if((testpoint.y <-1.0) | (testpoint.y >1)) return false;// outside the frustum
    // the z tests for 0 and positive 1 
    if((testpoint.z <0.0) | (testpoint.z >1)) return false;// outside the frustum
    return true;// inside the frustum
    }

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