Skip to main content
GameDev.net gamedev.net
🔒 Locked

Is a point visible?

Started by MrBarby Dec 19, 2004 at 5:41 AM 5 replies 850+ views
Original Post
MrBarby
MrBarby
Basically, what I want to do is see whether or not a point (x,y,z coord) is visible or not, so that when the model is not hidden, I can draw the name of the player above it. Any ideas on how to do this? Thanks, MrBarby
jacksaccountongamedev
jacksaccountongamedev
Try casting a ray from the view origin to the position in question and test for intersections with the game world? This will be rather costly so you may want to look into concepts such as bsps, quad-trees etc (if you haven’t already) to speed things up.

Hope this helps,
Jackson Allan
MrBarby
MrBarby
thanks :)

after looking at some code elsewhere, I can see how to cast a ray and get two vectors, but how would I test for intersections using this?
jacksaccountongamedev
jacksaccountongamedev
This isn’t exactly my thing (I usually program 2d games), but I imagine it is a matter of testing that ray (or line segment I suppose) for intersection with each triangle of every object in your game. There is code for ray/segment with triangle intersection all over the internet.

The brute-force way to do this would be to loop through every single triangle and run the test. However, depending on the complexity of your game, this will kill your framerate like nothing on earth. Thus, as I’ve already mentioned, you’ll probably have to find a way to minimize the number of triangles you process – bsp etc. Also, if you chose to include other objects such as characters and items in your test, you may want to simply run a ray with axis-aligned bound box test because it sounds like you will not need perfect precision.

Once again, I’ll note that this isn’t my area – I’m talking from general knowledge here and I apologize if I’ve said something incorrect.

I’m not exactly sure to what extent this all ties in with DirectX, and how much is actually done for you. Looking through the documentation, I can see functions such as D3DXIntersect (determines if a ray intersects a mesh) and D3DXIntersectTri (determine if a ray intersects a triangle). These may be an ideal solution – I’ve not used them before. Also, take a look at the ‘Pick’ sample that ships with the SDK – it seems very relevant to the topic.

Hope this helps,
Jackson Allan
MrBarby
MrBarby
cheers - this looks perfect!
eFoDay
eFoDay
if you get the cameras frustum planes, you can check if a point is inside

// there is six planes: left, right, top, bottom, near, farfor( int i=0; i<6; i++ ){  if( D3DXVec3Dot(&planes.normal, &D3DXVECTOR3(0, 10, 90)) <= 0 )  {    // the point 0,10,90 is not in the cameras view  }  else  {    // the point 0,10,90 is in the cameras view  }}
kandemor
kandemor
Also you can use Occlusion Queries, or project the point to screen space.

VinCenT

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.