I'm trying to creating a field of view for the camera I'm making for a game. It rotates around a circle for 180 degrees while the head moves accordingly. I'm going to bound the field of view within an isosceles triangle using the method described on this website.

The problem I'm having is that I don't know how I'm going to detect if the field of view has intersected with the character as seen in this link.

Any help with this would be greatly appreciated.


sorry I meant an asset in game representing a camera much like the enemy in the second link, not an actual camera class in XNA(really sorry)


Check out Linear Algebra for Game Developers

See the section titled Do Product. It has a tutorial for the math to determine whether an object is in the field of view of another object. Should get you started.

  • \$\begingroup\$ Thanks for that, this seems to be exactly what I'm looking for \$\endgroup\$ – dbomb101 Apr 7 '11 at 8:21

Check out the BoundingFrustum.Contains() function. You give it the view and projection and it builds the frustum. If you're going 2d, then you can add bounding boxes to a custom sprite class - example is here.

Edit: Check here for two different techniques for determining if a point is inside a triangle.

I think the bounding frustum could still work, but might be a bit more work. You can use the BoundingFrustum for things other than cameras. Each NPC would have to have a local view and projection to get their frustum and you can use that to check against a Vector3 (just set Z = 0 for Vector2). If you wanted to draw the frustum for debugging, you can get the points of the box and project them back to 2D just by setting the Z to 0.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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