5
\$\begingroup\$

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.

[EDIT]

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)

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

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.

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

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .