Jump to content
  • Advertisement
Sign in to follow this  
gamaral

2D camera - visibility rect

This topic is 2642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

So I'm trying to do some 2d map culling and I need a way to get a rect of what is visible by the camera (after translation, rotation and/or scaling). The way I got around it for now is to manually scale and translate the base orthographic coordinates (I totally ignore rotation for now), I'm sure there must be a better way... any hints?

Cheers!

Share this post


Link to post
Share on other sites
Advertisement
You can use gluProject to translate 3d coordinates to 2d screen coordinates. Imagine an object is bounded by a box. find screen coordinates of all corner of that box. If they all on the same side of screen don't draw the object

I don't know what project exactly returns, let's assume it returns 0<x<1 and 0<y<1 if pixel is on screen. If all points returned x<0 or x>1 or y<0 or y>1 then it will not be on the screen. you can use also depth value which will be returned from gluproject to find which objects are behind the camera or too far away

Share this post


Link to post
Share on other sites
Yep a friend just pointed out I could use device coordinates, you just gave me how :D thanks, I will give it a try and report back.

Share this post


Link to post
Share on other sites
got glProject to work, but I would love to get glUnProject to work so I won't have to keep checking every single point... just store the top-left and bot-right coordinates but it seems to fail for some reason. I will try to reimplement it and see what goes wrong.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!