• Advertisement
Sign in to follow this  

Character Eyes Vision in DirectX

This topic is 2113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to make the character see their enemies, so I thought about creating multiple boundary boxes and when the enemy collide with any of the vision boundary box it means they see their enemy, the problem I am having is that in 3D world everything can intersect anything unless physics programming is involved, I want this boundary box NOT to intersect with other buildings, like for example, if the character is inside a building, he cant see other people through the wall.

I would like to hear suggestion on how to make the character vision boundary boxes cant intersect with walls and other meshes.

Maybe there is another way to create character vision.

Share this post


Link to post
Share on other sites
Advertisement
Most games do it using ray-tracing techniques. They'll cast some rays starting from the character's eyes towards some object of interest, and see what the closest intersection is. If the closest intersection is the object of interest, then it's visible. If not, it's not visible.

Share this post


Link to post
Share on other sites
Ray tracing is a complex subject, and it's not something I can just explain to you in a forum post. There are tons of resources around if you want to learn how to implement it yourself, but it isn't trivial...at least if you want it to be fast. Most physics packages can handle ray casting, and there's also some libraries (like this one) that are dedicated to ray tracing.

Share this post


Link to post
Share on other sites
@MJP: Is it possible to detect AI vision by using boundary boxes? I think it's possible and it can be efficient.

Share this post


Link to post
Share on other sites
Calculating if a ray intersects a bounding box is fairly simple and quick.

If you want accurate per polygon testing you can use http://msdn.microsoft.com/en-us/library/windows/desktop/bb172882%28v=vs.85%29.aspx after you've determined that the ray intersects the bounding box of the object.

That should be fast enough for a simple game with a fairly small number of objects to be tested. For more complicated games you really want to use a physics library to do it for you because it will be much quicker.

Share this post


Link to post
Share on other sites
Robust and fast visibility testing is quite hard to implement. It's probably a good idea to not reinvent the wheel and use an existing software package, like Bullet or PhysX. Think twice before using Embree, as it's all triangle soup in there (no notion of transformation hierarchy)

Load your scene into Bullet or PhysX, and trace eye rays to enemies.

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]boundary boxes[/quote][/background]

[/font]

[background=rgb(250, 251, 252)][font="helvetica, arial, verdana, tahoma, sans-serif"][size="2"][color="#282828"]I assume you want support for partial visibility? An easy way to do this is to define an acceptable 'partial visibility' granularity, and trace multiple rays per enemy.[/font][/background]

Share this post


Link to post
Share on other sites
Lets say I have skinned mesh and I want to make a ray coming from the character eyes, when he move his head (the ray position should change as well), is it possible to use D3DXIntersect() to accomplish that? (be aware that SOME boundary boxes could means that the character doesn't see his enemy for example a wall or door. Edited by Medo3337

Share this post


Link to post
Share on other sites
In theory, sure. In practice, you're going to want a much smarter system in place so you don't have to test every single enemy/character against every other-- that's going to scale very, very poorly. I'm not even getting into good stuff like world geometry! Like has been suggested before, go with Bullet, PhysX or Havok. As far as I'm aware most commercial projects do just this with a handful of special cases/optimizations where a generic approach isn't suitable for the problem in question.

BTW, you seem to think that Direct3D is the only tool for the job (?) when it's really just suitable for drawing polygons, etc. to the screen. Just because the feature involves 'visual' stuff doesn't mean you need to use a graphics library! As far as the user is concerned, a handful of rays is more than adequate and more accurate systems may end up doing more harm than good for the final gameplay experience.

Share this post


Link to post
Share on other sites
@InvalidPointer: I am looking to create my own Engine which will include Physics library that I will create myself.

What is the best way with example on checking AI vision (could be a tank, helicopter, human, etc..)?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement