So, your making a mod, and somewhere down the line you thought it would be cool to have a hexagonal plot area or maybe an octagonal, or even a dodecahedral plot area instead of the standard elliptical.
Whether you wanted it because it made the HUD look more primitive/hardy, or because it was seen in whenever your mod was based on, or "just 'cause," you unfortunately where forced to go with the standard elliptical.
This little project seeks to add the N-gon option to standard radar gauges, allowing the modder to set the number of sides to almost any number they desire as well as rotate it a bit by adding options to a TBL.
The main changes right now are:
Index: radar.cpp
===================================================================
--- radar.cpp (revision 8155)
+++ radar.cpp (working copy)
@@ -378,20 +378,25 @@
new_x_dist = (pos->xyz.x / zdist) * rscale * (Radar_radius[0]/2.0f);
new_y_dist = (pos->xyz.y / zdist) * rscale * (Radar_radius[1]/2.0f);
- // force new_x_dist and new_y_dist to be inside the radar
+ // N-gon tests
+ // Constrain blips to be inside N-gon. Currently, N = 8
float hypotenuse;
- float max_radius;
+ float blip_angle;
+ float line_radial;
+ int N = 8; // N, the number of sides of the N-gon. Full implementation will have this as a private variable assigned during tbl parsing
+ int sector; // The sector (quadrant if N = 4) that the blip is in
hypotenuse = (float) _hypot(new_x_dist, new_y_dist);
- max_radius = i2fl(Radar_radius[0] - 5);
+ blip_angle = atan2_safe(new_x_dist, new_y_dist);
+ sector = (int) ((blip_angle*N)/PI2); // Determine the sector by dividing blip_angle by (PI2 / N)
+ line_radial = (float) ( 1/(sin( blip_angle + (sector*(PI2 / N)) ) ); // Determine the line which the blip will be constrained to
- if (hypotenuse >= max_radius)
+ // If the blip's radial is greater than the sector line, constrain it to the line
+ if(hypotenuse > line_radial)
{
- clipped_x_dist = max_radius * (new_x_dist / hypotenuse);
- clipped_y_dist = max_radius * (new_y_dist / hypotenuse);
- new_x_dist = clipped_x_dist;
- new_y_dist = clipped_y_dist;
+ new_x_dist = line_radial*cos( blip_angle );
+ new_y_dist = line_radial*sin( blip_angle );
}
}
How it works:
It works by using a polar equation for a straight line. As it turns out, the function r = 1/( sin(theta + phi) ) creates a straight line that is tangent to the unit circle, and is perpendicular to a radial with the angle of phi. Try it out on a graphing calculator when you can!
To make the blips fit inside the N-gon, the the blip's radial is constrained to be within the r of the sector the blip is in. (The sectors are basically pie slices)
My current to-do list for this project:
Test initial modifications!

Make the N variable private to the radarstd class
Research and implement TBL parsing
[attachment deleted by a ninja]