Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Let's say I have a sprite, drawn like this:

spriteBatch.Draw(levelCannons[i].texture, levelCannons[i].position, null, alpha, levelCannons[i].rotation, Vector2.Zero, scale, SpriteEffects.None, 0);

Picture levelCannon as being a laser beam that goes across the entire screen. I need to see if my 3d model intersects with the screen space inhabited by the sprite. I managed to dig up Viewport.Unproject, but that seems to only be useful when dealing with a single point in 2d space, rather than an area. What can I do in my case?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Did you mean Viewport.Unproject? This method is used to covert a point from screen space into world space. You can follow the instructions on the MSDN page on how to convert a 2D screen space point into two separate 3D points that form a ray going into the screen.

From what I understand, you have a 2D line going across the screen and want to see what 3D objects are intersected by that line, like this?

enter image description here

I think what you can do is use Viewport.Unproject four times: on the left side of the screen for the far and near plane, then the right side of the screen for the far and near plane (really you only need three of these points). With these points you can create a Plane which you should use with your collision detection to see which objects fall on that plane.

share|improve this answer
    
Yes, I edited the question to fix that mistake. This should do nicely. –  Fibericon Sep 7 '12 at 16:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.