Sign in to follow this  
xegoth

How do you know if something is on screen in 3d space

Recommended Posts

Alright I draw 2d sprites as textured quads in world space. when the sprite leaves the screen I want it to appear on the opposite side.. The problem is, I represent my sprites in world coordinates not screen coordinates. Is there an elegant way to know when they've left the screen, and where I need to put them so they'll come back on the opposite side? Thanks in adance,

Share this post


Link to post
Share on other sites
It depends on your camera setup. Does your camera rotate, move around, etc? Or is it stuck in one place while objects (sprites) move around in the Z buffer?

If your camera doesn't rotate, you can probably get away with calculating distance rather than using a view frustum. The farther an object is from the camera, the more space it has to move up, left, right, and down. The distance from the camera is directly proportional to the scale of the screen. You just need to determine how much an object scales down as it traverses a single z value (1.0). Multiply that with the screen size, for each sprite.

If your camera rotates, I recommend [google]
This one looks pretty good.

Share this post


Link to post
Share on other sites
from what your explanation sounds like, it seems to me that you should first ask the question: "do i really need to store my quads in worldspace?".

putting them into worldspace is just a headache and should be avoided unless its truly nessicary for some type of effect your doing.

now assuming its not nessicary, and your using the fixed function pipeline. i recommend storing the quads for your sprites in RHW coordinates. these are pretransformed and are already stored in screen space coordinates. so your x and y coordinates are in pixels, and your z coordinate is from 0 to 1 (how far back from the screen it is), and your rhw component which should always be 1.

check out tutorial # 2 in the directx sdk. this will show you how to draw a triangle in screen space in this manner.

from here it should then be very straight forward to check if your quad has gone offscreen.

good luck!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this