 # Radar for 3D Space Games

I found creating a radar for a 6DOF game quite difficult and there were few resources that I could find online that gave me an idea of what to do, so I’m posting this here in hopes that someone will find this useful.

``````

float sensitivity = 100; // the higher the sensitivity, the smoother the rotations are of the dots being drawn on the radar
int xl = (mode.getWidth() / 2) - 200; // arbitrary circle drawing positions, you can put these where you'd like
int yl = (mode.getHeight() / 2) + 120; // ^

v.drawCircle(xl, yl, radius, 0xffffff); // draw circle at xl, yl with given radius and a white color

// the following three lines of code should be modified to create no garbage, but this is up to you.
float[] ps = new float[] { player.pos_x, player.pos_y, player.pos_z }; // put player position (x,y,z) into float array
fPlane plt = new fPlane(ps, player.tangent.toArray()); // new plane, 'ps' is the point on the plane, tangent is  normal.
fPlane plb = new fPlane(ps, player.binormal.toArray()); // new plane, 'ps' is the point on the plane, binormal is normal.
// tangent vector is the 'forward' vector of the player, and the binormal is the 'left/right' vector of the player
for (int i = 0; i < targets.size(); i++) {
Entity e = targets.get(i);
dotRadius = (int) e.radius / 8; // optional, but this line creates dots on the radar that are scaled so that they reflect the radius of the enemies
float d1 = plb.pointPlaneDistance(e.pos_x, e.pos_y, e.pos_z); // find distance from entity's position to the binormal plane.
}
}
float d2 = plt.pointPlaneDistance(e.pos_x, e.pos_y, e.pos_z); // find distance from entity's position to the tangent plane.
}
}
double xc = d1 / sensitivity;
double yc = -d2 / sensitivity; // negate the y coordinate because of window graphics
double mag = Math.sqrt(xc * xc + yc * yc);
// Scale vector to meet the radius if the magnitude of the vector is larger than the radius