Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

flying starfish

Radar Displays

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

What''s the best way to go abou creating a radar display from a series of object points in my scene? I want to reject everything beyond 5000.0f units or so, and I want to differentiate between objects in front of the player and objects behind them. I''m working in D3D8 - can anyone give me some pointers or ideas? ---- flying starfish

Share this post

Link to post
Share on other sites

For checking if the object is within the radar range use a distance check. For checking if the object is infront or behind use the dot product.

Here is some psuedo code that should help you get started.

rad = the origin of the radar in world space. I.e usually it is the same position as the object being controlled by the player.

In the dotproduct part you may have to swap over the infront or behind results. oh and if it is 0 its on the x axis of the radar.

for each object;
radDistSQ = 5000*5000
dx = (obj.x-rad.x)
dy = (obj.y-rad.y)
dz = (obj.z-rad.z)
dist = dx*dx + dy*dy + dz*dz

if dist > radDistSQ then object is not within radar - move onto next object in loop

// object is within radar is if infront or behind.

radarfrontvector = (0,0,1) - pointing along the z axis (into screen)
objToRadarVector = (dx, dy, dz)

if dotproduct (radarfrontvector, objtoRadarVector ) < 0 then
object is behind player
object is infront of player.

[edited by - noisecrime on June 19, 2003 8:35:12 AM]

Share this post

Link to post
Share on other sites
Project the player''s look-at vector into the horizontal plane. If your ground lies in y=0 for example, then the projected vector is |x, 0, z| where x and z are the x and z coordinates of the look-at vector. Be sure to normalize after the projection.

Next, for each object you want to plot on the radar, calculate the difference vector as such:

diff = object_location - player_location

If the dot product of diff with itself (dist_squared) is greater than (5000 * 5000) then the object is more than 5000 units away and you can reject it. Otherwise, project the diff vector into the horizontal plane as before, normalize the diff vector, and take the dot product of diff with the projected look-at vector. The angle theta between the player''s view direction and the object is given by the acos function: theta = acos(dotproduct(projected_diff, projected_lookat))

Now comes the fun part. cos(theta) = dotproduct(projected_diff, projected_lookat) which we already calculated, so we don''t need to find it again. sin(theta) can be figured easily given the theta we just calculated. Choose some scale factor S that will correspond to the "scale" of your radar, such as 100 world units per pixel. We have dist_squared from earlier, so we take the square root to obtain dist. Then the screen coordinates of the radar blip are given by x,y:

x = cos(theta) * dist * S + center_of_radar_x
y = sin(theta) * dist * S + center_of_radar_y

This will make "up" always be the direction the player is facing on the radar. You can easily tweak that if you want by rotating the above x,y coordinates about the center of the radar. You can also obtain a very interesting effect by not taking the square root of dist, so that radar blips farther away seem to move faster than ones close by.

Hope that helps some.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!