Jump to content

  • Log In with Google      Sign In   
  • Create Account


Character Eyes Vision in DirectX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 10 May 2012 - 11:58 AM

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.

Sponsor:

#2 MJP   Moderators   -  Reputation: 10205

Like
0Likes
Like

Posted 10 May 2012 - 02:33 PM

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.

#3 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 10 May 2012 - 02:54 PM

@MJP: How can I use ray-tracing in DirectX 9 for character vision and how to detect its intersection?

#4 MJP   Moderators   -  Reputation: 10205

Like
0Likes
Like

Posted 11 May 2012 - 11:40 AM

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.

#5 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 11 May 2012 - 02:44 PM

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

#6 Adam_42   Crossbones+   -  Reputation: 2360

Like
0Likes
Like

Posted 11 May 2012 - 05:29 PM

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.

#7 jameszhao00   Members   -  Reputation: 267

Like
0Likes
Like

Posted 11 May 2012 - 08:27 PM

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.

boundary boxes


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.



#8 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 12 May 2012 - 02:27 AM

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, 12 May 2012 - 02:40 AM.


#9 InvalidPointer   Members   -  Reputation: 1364

Like
0Likes
Like

Posted 12 May 2012 - 08:07 AM

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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#10 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 12 May 2012 - 09:51 AM

@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..)?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS