Sign in to follow this  

Line of sight

This topic is 3863 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 have a 3rd person bird's eye view (Think of a RTS). When an enemy unit is hiding behind a wall the player can still see it (because of the birds eye view). Although his character cannot. I want to hide the enemy units mesh whenever the enemy is hidden from the character. My current solution is to raycast to the enemy units node (in the center of the body). But there are times when although the node(center) is not visible the enemy should be able to be seen. (body extremity or weapon is sticking out). How can i test for this? I am using Ogre3d and PhysX.

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
A full solution is not easy.

A fairly quick solution would just be to raycast to multiple points instead of just the center.


How not easy.... lol.....

Hmm im thinking i could cast to the Corners of the AABB but i dont really know how... And if i do this it would be a total of 8 raycasts per character per frame...

How do some of the bigger games deal with line of sight/fog of war?

Share this post


Link to post
Share on other sites
Quote:
Original post by jchmack
How do some of the bigger games deal with line of sight/fog of war?

They probably just cast to the center of the unit ;P

Quote:
Original post by superpig
A fairly quick solution would just be to raycast to multiple points instead of just the center.


I've even see FPS games that do this - one ray to the center, one to the head, one to the center of the feet, and two to the arms...

Quote:
Original post by jchmack
Hmm im thinking i could cast to the Corners of the AABB but i dont really know how... And if i do this it would be a total of 8 raycasts per character per frame...

yeah, that's the easy solution, just find a bounding sphere for each unit (the unit's "radius"), and ray-cast to a few points around on this circle. If the ray-caster is fast, it shouldn't be a problem. Also, you wont need to perform the test for EVERY unit, some of them you can discard before running this algorithm because they will be too far away from your units.

eg.

F = friendly
X = enemy
| = wall

Small unit (Radius = <1 square):
F | X = hidden

Large Unit (Radius = 1.5 squares):
XXX
F | XXX = visible
XXX

For any "large" unit, first cast to the center

F-----| X

Then Radius R units to the left and right of the center
F-----| X X

Then Radius units above and below the center.
/---- X
F-- |
\---- X

Share this post


Link to post
Share on other sites
For the target points in the raycast, you could mark them out as part of your art pipeline. If a model has any target points defined for it, raycast to each of them; if not, use the center of the bounding box.

The full solution basically involves calculating the image of the target unit from the source unit's point of view, clipped by the world geometry. It's very expensive to do it accurately on the CPU; if you had only a few units and some GPU time to spare then I guess you could do an actual render + occlusion query but that too will become expensive after you've got a few units going on.

Share this post


Link to post
Share on other sites
Thanks to both of you (Ratings up). I think im going to take a page out of Hodgman's recommendation and raycast to 2 points on the plane through the enemy and normal to the player. Ill follow this plane and raycast to the positive and negative radius points. This way orientation of the enemy doesn't matter and i can save 2 raycasts. Any other reccomendations are welcome =)

I might also raycast to the top of the player so that they can crouch behind things too.

Thanks again =)

Share this post


Link to post
Share on other sites
A friend told me:
"This is called occlusion test and I think this should be done with the 3D engine not with the physic one. I don't know if you've already tested Warhammer 40000 (the video game) but it has a great occlusion test where all hidden polys are displayed in green and visible ones are normally displayed."

Is this sort of per poly test practical? It seems like i would have to raycast to each poly or if i REALLY wanted to be accurate each vertex. And this would take a lot of raycasts per frame per entity. I have never played warhammer but i believe its an RTS and if they can find a practical use for this(considering the amount of units) im betting there is a cheap(cpu wise) way to do this. Thanks in advance for all help =)

Share this post


Link to post
Share on other sites
Quote:
Original post by jchmack
A friend told me:
"This is called occlusion test and I think this should be done with the 3D engine not with the physic one.
This is what I was alluding to in my last post. Render your geometry during an occlusion query, which counts how many pixels actually get drawn. If it's none, then the geometry is fully occluded; knowing that, you could choose not to draw it next frame, or to not draw all the things inside it.

Quote:
I don't know if you've already tested Warhammer 40000 (the video game) but it has a great occlusion test where all hidden polys are displayed in green and visible ones are normally displayed."

Is this sort of per poly test practical?

They don't do it per-poly. They break the world up into pieces and do it per-piece.

Doing it for per-unit visibility is feasible but would take careful planning - you'd want to minimize the number of pairs of units you'd be testing (e.g. limit it to units within a certain distance of each other), keep the per-unit resolution low (possibly scale it up for units with "better eyesight") and maybe use lower-detail meshes where possible.

It does, of course, require that the graphics card supports occlusion queries.

Share this post


Link to post
Share on other sites

This topic is 3863 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this