Sign in to follow this  
mc_abel

Radar tutorial with open gl cplusplus

Recommended Posts

mc_abel    122
Hi there. I'd like to know if anyone know of a good tutorial, book, article, or demo on making a "radar" for a first/3rd person shooter game. I'm using C++ and opengl. Thanks in advance.

Share this post


Link to post
Share on other sites
Lord Darkblade    122
A radar how?

Doing it properly, you would create a pulse heading out of your emitter (possibly phased across the duration of the pulse), and use the return strength (inverse square) to determine the position of an object, noting that the system has problems detecting distance beyond 1 unit if its not a chirped. Most libraries have good books on radar physics since it hasn't changed much since the 1930s, just the implementation technology has.

For a game, you could probably simply this by getting all features within X m (the strength of your radar), and showing the strength of return / mapping it onto a circle (can show walls etc as high returns). Simpler still is just to show a simplified version of your maps solid geometry and any units not obscured by those solid terrain.

Share this post


Link to post
Share on other sites
mc_abel    122
Yeah pretty much is as you say:
+display a circle overlay with a radius of distance equivalent to radar strength

+maybe overlay a simplified map with basic solid structures

+draw dots/small circles with a distance scaled down relative to the player's and enemies distance

+somehow update enemy position on map whenever they move, or player move

>Basically I understand the logic behind it, but since I'm new to openGL it would be nice to have a tutorial or something similar that has been made before to understand how its done. Nevertheless I'll keep experimenting using quadrics to draw the circle, although I'm not sure which class should handle that: either the win main or the Gui class.....

Share this post


Link to post
Share on other sites
Lord Darkblade    122
Not really a graphics programmer, but I would suggest something like:

A circular / square sprite
A simplified map (from your map editor or created), or a 1:n scale of your terrain if you want (starcraft and co used ~ 1pixel / hex, coloured by terrain/faction).

A lot of "radars" in games show the full map around you even if a real radar wouldn't return it, so a simplified map offset so that player coords == offset of map from centre would work. If you really want to do it properly you need to basically do LOS to each wall and determine if you can see it, and if you can see through it (bamboo wall = weak return + see through, steel plate = high return + opaque, but a real radar can confuse a weak bamboo wall return with a steel plate much further out, you don't want to deal with that really).

It should basically be just a case of:

Draw (Radar_Frame)
Offset_minimap()
Draw (minimap)
Draw (players within x yards)

Update the radar like a mini-map since thats basically all it is, and there are several threads/ tutorials here on minimaps.

Share this post


Link to post
Share on other sites
dashurc    236
Well, if you just want the standard circular radar seen in games like Halo, it's really easy. Simply find the distance between you and each enemy. For all enemies within a specific maximum distance, you will get the angle between you and them and from there it's a simple matter of getting the point from the center of the radar to the mapped distance (if the scale from world to radar is for example 1/10th, simply use 1/10th of the distance as the vector's magnitude), and rotate the vector by the angle.

For a minimap, I'd suggest simply having the artists add geometry to the level that doesn't get exported into the loaded level, and use this geometry to create the minimaps. Once you figure out a scale it's pretty trivial to get your position and enemy positions translated onto the minimap.

Here's a link for calculating angle between two vectors:
http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm

For a radar/compass you don't really need to worry about the Y coordinate at all so you can use 2D calculations unless you're doing a funky full 3D radar (maybe useful in a space game or something???).


In terms of how this translates into OpenGL? Well, the only real openGL work is rendering triangles. Once you have all the coordinates for the dots, simply render a couple triangles (or a quad) to represent the dot at that location. Render in orthographic mode of course.

Share this post


Link to post
Share on other sites

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