Jump to content
  • Advertisement
Sign in to follow this  
slikrik

determine if object is in view

This topic is 4852 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

Greetings, I'm looking for a quick (can be crude) way to determine if an object (a point in space) is in my current view projection. I'm sure there's some nifty process involving the current projection matrix, but I'm not aware of it. In other words, I don't want to render an object if it's behind the camera. Any help is greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Use a frustum (6 planes surrounding your view frustum) and test them against spheres or axis aligned boxes surrounding your objects.

Share this post


Link to post
Share on other sites
I wrote a Wolf3D style game years ago that had a 90 degree view (-45 to +45). After translating all position of the objects, I first made sure that their position on the Z-axis was greater than my clipping point. Then, to see if they were on-screen, I simply checked that their X position was less than their Z position and greater than the negative of their Z position. I allowed a little more slack than that so objects could be partially off-screen but that's the jist of it.

Hey, you wanted crude =b

Share this post


Link to post
Share on other sites
Jan-Lieuwe, is there a simple way of creating the 6 sides of my frustum? Would I have to create the frustum (6 quads), and then apply the current MODELVIEW_MATRIX to these quads, then test against this translated frustum, or is there a simpler way?

Share this post


Link to post
Share on other sites
Quote:
Original post by slikrik
Jan-Lieuwe, is there a simple way of creating the 6 sides of my frustum? Would I have to create the frustum (6 quads), and then apply the current MODELVIEW_MATRIX to these quads, then test against this translated frustum, or is there a simpler way?
This article describes a straightforward method for extracting the frustum planes from the modelview and projection matrices. (It does require a little matrix math though...)

Share this post


Link to post
Share on other sites
If you just want to know wether an object is behind your camera, just one plane of the frustum will do (the near clipping plane).

Share this post


Link to post
Share on other sites
If you are really talking about points (or don't mind it being a bit crude), then it's usually enough to know the width/height of your frustum for some z (usually you should know it for the near plane, as that's what you set the projection up with.. unless using some helper function).

Then it comes down to transforming the point to camera space (can be done coordinate by coordinate), compare z to the near/far plane and x (y) to width (height)*z. Or do it with the six planes, as you will probably find countless tutorials about that ,-)

Share this post


Link to post
Share on other sites
Trienco:

To use your method, wouldn't I need to transform the point in question by the *inverse* of the projection/modelview matrix to obtain the Z coordinate relative to the camera?

Share this post


Link to post
Share on other sites
If you have front, right and up for your camera, you can dot the vector from camera to object center with those three. If depth is negative (more than radius) your object is behind camera. Else take the absolute of right and up dot products; subtract objet radius; divide each by depth dot product; if this projects less than your field of view, the object is likely visible. The "field of view" is the atan value for your sideways and upways half-viewing-angles.

This is generally quicker than doing the six planes test (assuming you pre-calculate your atan and camera values once each frame), and about as accurate.

Share this post


Link to post
Share on other sites
hplus0603: could you please clarify the steps you're referring to? By "front, right and up" do you mean "near, right, and top" planes? You then refer to "depth" but I'm not sure how you're calculating depth. Your "else" portion then doesn't make sense-- I'm sorry if I am missing something obvious. I can't tell exactly what you're referring to with the right and top dot products...

Thanks!

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!