Results 1 to 4 of 4

Thread: Visibility testing woes

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    3

    Visibility testing woes

    Hi guys, I've been trying to find out how to do some simple visibility testing/culling for a tilemap I'm working on, I've been searching for over a month with no success - I keep finding example involving 3D stuff and such but I'm working in 2D with glortho.

    This is what I'm trying to do (pardon me if I don't use the correct terminology).

    I'm trying to find the top-left and bottom-right visible coordinates in object coordinates (or what ever you call them) in order to perform some basic visibility testing.

    I have been doing the math manually, but it doesn't take rotation into account for example.

    Any help will be greatly appreciated.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Visibility testing woes

    Do you have anu images you could post of what you are trying to achieve?
    If it's just a regular 2D grid then I don't see the problem since it's a fixed size? ... and because of such, you know what you have to draw to each cell therefore it's easy to only draw the 'current cells' within the coordinate range of the window/camera.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    3

    Re: Visibility testing woes

    I want to use this not just for a simple tilemap, that's true, let's say I have this.

    glOrtho(-40, 40, -30, 30, -1.f, 1.f);

    So my visible range now is:

    topleft( -40, 30 )
    bottomright(40, -30)

    I easily test visibility while rendering my tilemap. But what happens if I move around and more importantly *rotate* my camera.

    * Camera moves to X position, Y zoom and Z rotation, let's say it's following something like a sprite on screen or something.

    glRotatef(camera.rotation(), .0f, .0f, 1.f);
    glScalef(camera.scale().x(), camera.scale().y(), 0.f);
    glTranslatef(camera.translation().x() * -1, camera.translation().y() * -1, 0.f);

    How do I get my topleft and bottomright now?

    I'm pretty sure I have to do some matrix magic, but what.

    I want to use this for not just tilemaps obviously, so I'm not really looking for a workaround, I need to figure out how to get the visible rect (if you will).

    If it's still not clear I can post some pictures.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    3

    Re: Visibility testing woes

    Mmm I might have just figured it out, after some playing around with my calculator. Tell me if this makes sense.

    Please bare with me, I might not use the proper nomenclature for most of this stuff.

    I multiplied the MODELVIEW and the PROJECTION matrices, I then use that (as I would if I wanted to test visibility using NDC) - but instead of multiplying the resulting matrix against object coordinates in order to get NDC (-1..1) - I invert the resulting matrix and multiply NDC coordinates instead (-1.0, 1.0) to get the visible object coordinates.

    Does it make sense to you more experienced folk?

    If it does, I guess I would just need to offset the resulting vector using the camera position.

Similar Threads

  1. Non Visibility while rotating
    By jowins in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-23-2004, 01:36 AM
  2. Box visibility
    By Catman in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 02-26-2003, 10:39 AM
  3. Fog (visibility)
    By Anthony moss in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-11-2002, 02:37 AM
  4. Visibility Algorithms
    By imported_Marcus in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-26-2001, 03:53 AM
  5. Test for visibility
    By Shayde in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 04-09-2000, 01:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean