Skip to main content
gamedev.net
🔒 Locked

Object Visibility

Started by thekid 0 replies 250+ views
Original Post
thekid
thekid
How do I determine if an object is inside my view frustrum. D3D BTW. I have the Objects Matrix and the Camera View+World Positions. Thanx
Meduzza
Meduzza
Approximate your object to a sphere: pos + r.

Transform pos into camera coordinate system: VecMatMul( &pos, viewMatrix ).

Clip if in front of the "front clip" or behind of the "back clip": if( pos.z < frontClip || pos.z > backClip ) -= clipped =-
(That takes care of front and back frustrum planes)

It's not that easy with left/right/top/bottom planes, because they are not parallel to anything...

Easy-Cheesy way (not very precise):
1. Project pos (which is already in camera coordinate system) on screen:

posXScreen = ( ( pos.x / pos.z ) * focus ) + screenWidthHalf;
posYScreen = ( ( -pos.y / pos.z ) * focus ) + screenHeightHalf;

Where "focus" is focus distance - distance from camera to a projection plane:

focus = screenHeightHalf / tan( vertFOVHalf );

2. Project object radius on-screen:

screenR = ( r / pos.z ) * focus;

3. Now you have screenX, screenY - object position ON SCREEN and screenR - object radius ON SCREEN. So...

if( screenX + screenR < 0 || screenX - screenR > screenWidth || screenY + screenR < 0 || screenY - screenR > screenHeight ) -= clipped =-

Another way (more precise):
1. Take four normals from every frustrum plane (using cross products).
2.
if( VecDot( center, &frustrumNormals ) < -r ) -= clipped =-  


Yep, that requires some crazy math knowledge... I can give you code if you want.

------------

Cheers

Meduzza!


Edited by - Meduzza on September 14, 2000 10:33:32 AM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.