Game Development Community

Wing Commander Radar

by Mike Kuklinski · in General Discussion · 03/20/2005 (7:07 pm) · 17 replies

I have been struggling to come up with a correct math solution into rendering a radar such as the one in the Wing Commander games, an image of which is below.

I am hoping someone here has implemented one such as this before and can help me. Please do not link to the radar resources here on GG -- they are 2d and are not similar in any way.

kuattech.com/radar.png

#1
03/20/2005 (8:05 pm)
It's a simple projection. First, compute the position of the object of interest, relative to the orientation and position of the radar. Let's say that Y is up and X is left, giving us, in a right-hand coordinate system, a forward Z. Now, normalize this, as the distance to the target is irrelevant (though you may wish to keep the distance or distance squared for other uses, like point size or something). This gives us the normal vector (X, Y, Z).

Well, if the radius of your rear radar area were exactly double the radius of the area in front of the radar, it would be simple. The position would be the vector (X, Y) * (1 - Z) * R. A negative relative Z means that the target is behind you, while a positive relative Z means it is in front of you. R is the radius of the forward area (the radius of the circle separating "Above/Behind" from "Above").

Of course your radar has a very small area for rear objects and a much larger one for distant objects. To deal with this, your projection method needs works like this:

If the Z > 0, then it is (X, Y) * (1 - Z) * Rf, where Rf is the radius of the forward area (as defined above).
If Z <= 0, then it is (X, Y) * (((Rr - Rf) * (1 - Z)) + Rf), where Rr is the radius of the rear circle.

BTW, as a side note, I always found the radar on WC games to be less useful compared to the radar on X-Wing/Tie Fighter games.
#2
03/20/2005 (8:10 pm)
Here is a small math question (that has been giving me a headache)----after I get the direction vector (targetpos-radarpos), how do I take into account the radarpos' rotation vector?

EDIT: I made a hackjob to determine that --- I used getAnglesFrom, then subtracted the direction angles from the eye angles, then I used getVectorFrom, at which point I also set Y (Which is depth) to mDot(eye,direction).
#3
03/20/2005 (8:55 pm)
Quote:Here is a small math question (that has been giving me a headache)----after I get the direction vector (targetpos-radarpos), how do I take into account the radarpos' rotation vector?

I know far more about math than TGE, but I would imagine/hope that the radar (the ship with the radar, presumably) has some kind of transformation matrix that you can use (the inverse of) to transform the world position of a target into the radar's coordinate system. No need for hacks or angles. At the very least, I would expect a quaternion and a position to be involved, if not a full 4x4 transformation matrix.
#4
03/21/2005 (5:07 am)
I can get the transform -- my math is poor, though... I am wondering how to use it to effect the vector.
#5
03/21/2005 (12:20 pm)
Once again, I don't know how to express it in TGE, but in plain English, you take the inverse of the transformation matrix and transform the position by this.
#6
03/21/2005 (12:59 pm)
Thank you. I misinterpreted what you had said before.
#7
03/21/2005 (5:02 pm)
Ok... I am still somewhat confused.... --- I invert the transformation matrix of the radar ship, but what do you mean "Transform the world position of a target into the radar's coordinate system"? Multiply? I am not clear on what you are saying.
#8
03/22/2005 (6:49 am)
Based on what is written above, it seems like the code would be similar to this:

void MyShip::calcRaderCoords()
{
  MatrixF invTransform(getTransform());
  invTransform.inverse();  // This now can transform world space coords to object space.

  MatrixF objTransform(objectInRadar->getTransform());
  objTransform.mul(invTransform());  // Object transform is now the enemy in object space coords.

Then you can use the projection code Smaug mentions above, but switching the z and y coords to take Torque's coordinate space into consideration.

Hope that helps a little. (Hope I don't lead you down the wrong path.. ;)
#9
03/22/2005 (12:04 pm)
Spoke too soon----the farther the target is from the origin (0,0,0), the more distorted the radar gets... it gets unplayable fast. Any ideas?
#10
03/22/2005 (12:19 pm)
Could you just Limit the radar's range before it reaches the point of distortion and stops tracking targets?
#11
03/22/2005 (12:28 pm)
Thats not the problem.... its not distance from the radar, it's distance from the world origin at (0,0,0). Unless the target is at (0,0,0) all the time, it will become distorted.
#12
03/22/2005 (1:03 pm)
Here is the relevant code -- maybe it will help? As I stated before, the issue is that the radar is accurate while the target is at the WORLD COORDINATE ORIGIN, or (0,0,0). Once it moves away, it begins to become grossly inaccurate.

Wrong Forum
#13
03/22/2005 (1:56 pm)
This is the wrong forum for this discussion to continue.
#14
03/22/2005 (2:14 pm)
Whoops. Sorry. I will move it to a new forum, albeit that the code I posted is proprietary.
#15
03/22/2005 (5:07 pm)
I moved it here
#16
03/22/2005 (5:09 pm)
Er, edit that link... it just points right back here.
#17
03/22/2005 (5:13 pm)
Whoops -- here rather