Sign in to follow this  

How do we know if an object is visible or not ?

This topic is 4303 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

Basically, I would like to create a NPC which will have the capacity to know if the user character is or not visible. for instance: if the user is in my direction, but is behind a wall, then he's not visible if the user is in my direction and is not behind a wall, then he's visible, etc I know that the scalar product could help me knowing if a character is in the same direction as another, but it does not tell me if a wall is there as well. cheers...

Share this post


Link to post
Share on other sites
Typically, you will cast one or a few rays between the location of the NPC eyes in the world, and various points of the other character.

This assumes that you actually have collision or visibility geometry for your level, that you can run ray queries on. If not, then you probably need to build them :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by jolyqr
i did not get what you mean...
hplus's post was pretty straightforward. Which part did you need further help with?

Line of sight testing between two objects basically falls into two categories: field of view, and occlusion. The first is easy and (as you stated earlier) can be determined with a few dot products. Occlusion is harder, and how to solve it depends on how your world is represented. For example, Quake-like games have a PVS (potentially visible set) which can be used to roughly determine visibility. In other contexts, you might use raytracing, as suggested by hplus.

Share this post


Link to post
Share on other sites
He means that you have to determine if the NPC can see the character the hard way.

From the NPC you "cast" rays (the geometrical definition of ray is a straight line that extends from a point; your NPC is the point) towards the PC. You examine the path of the rays to see if there is any intermediate objects that block vision. (Again, this is up to you. You could detail the object and its translucency, or decide nothing can be seen through, etc.) If you reach the PC without finding a colliding object then the PC could be considered "visible."

Don't forget to take the NPCs field of view into account; if they're facing away from the PC they can't see them - unless it's an alien with eyes in the back of his head. (Hey, could be a science fiction RPG!)

Wikipedia has a nice article on raycasting - worth the read if you want to follow up on it. GameDev also has a tutorial on it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
For every game engine, it is very important to have a function that does ray tracing, you pass a source coordinate x1,y1,z1 (your NPC position for example) and a target coordinate x2,y2,z2 (your player position for example) then the function will return TRUE if an invisible ray can be "draw" from source to target WITHOUT intersecting any polygon from your world geometry; it will return FLASE otherwise; some more in depth version will also return the coordinate where the ray gets first intersected by the worl geometry. That rutine then is used for visibility testing and collision testing.

For bulding that rutine you need basicaly a function where you pass two coordinates (source and target) and a triangle vertex (p1,p2,p3) and then do a ray to triangle test to kwnow if the triangle is in the path of the imaginary ray.

Testing every triangle in your world geometry with the ray is too much work, so you have to implement a technique that allow to do fewer compares, like using BSP, quadtrees, Octrees, bounding boxes, bounding spheres, etc.

good luck.

tp.

Share this post


Link to post
Share on other sites
my world will be very simple, it is going to contain only geometric components such as cubes and pyramides.

i planned to use simple collision detection using boxes. if i have all understand, i will have to use ray tracing in order to determine if a point is visible or not ?

Share this post


Link to post
Share on other sites
Quote:
Original post by jolyqr
my world will be very simple, it is going to contain only geometric components such as cubes and pyramides.
How many of these objects will there be, on average?

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by jolyqr
my world will be very simple, it is going to contain only geometric components such as cubes and pyramides.
How many of these objects will there be, on average?


six objects, maybe, no more. it's not going to be a huge game. it's more like a demo.

i'm a beginer, so don't hesitate to give me as much details as you can about collision detection and ray tracing...

Share this post


Link to post
Share on other sites
Quote:
Original post by jolyqr
six objects, maybe, no more. it's not going to be a huge game. it's more like a demo.
In that case, don't worry about broad-phase culling, spatial partitioning, or anything like that. Just write functions to test for the intersection of a ray with the object types you're interested in (e.g. boxes and pyramids), and when you need to raytrace, just trace against every object in the scene.

There are different algorithms for raytracing various objects, but speed won't be an issue here, so I'd just find something that works and go with it. Things to google for would be 'raytrace box', 'ray box intersection', 'ray AABB intersection', 'ray OBB intersection', 'ray triangle intersection', and similar phrases.

Share this post


Link to post
Share on other sites
Never dealt with this but here's an idea --

Transform the viewing frustrum to the NPCs eyes - and do some sort of testing with that?

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by jolyqr
six objects, maybe, no more. it's not going to be a huge game. it's more like a demo.
In that case, don't worry about broad-phase culling, spatial partitioning, or anything like that. Just write functions to test for the intersection of a ray with the object types you're interested in (e.g. boxes and pyramids), and when you need to raytrace, just trace against every object in the scene.

There are different algorithms for raytracing various objects, but speed won't be an issue here, so I'd just find something that works and go with it. Things to google for would be 'raytrace box', 'ray box intersection', 'ray AABB intersection', 'ray OBB intersection', 'ray triangle intersection', and similar phrases.


thanks a lot !!

Share this post


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