OVR: Normalize planet distance, so they appear infinitely away
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 22 Apr 2018 14:53:35 +0000 (16:53 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Fri, 27 Apr 2018 19:21:16 +0000 (21:21 +0200)
src/mercenary/render.c

index 3582c3a..c35b811 100644 (file)
@@ -2133,7 +2133,7 @@ void render_one_item(render_item_t *render_item, int vr)
                double circle_x[PLANET_VERTICES], circle_y[PLANET_VERTICES], circle_z[PLANET_VERTICES];
                double crescent_x[PLANET_VERTICES], crescent_y[PLANET_VERTICES], crescent_z[PLANET_VERTICES];
                double x[PLANET_VERTICES], y[PLANET_VERTICES], z[PLANET_VERTICES];
-               double size, angle, fabs_angle, crescent;
+               double dist, size, angle, fabs_angle, crescent;
                double _sin, _cos;
                int i;
                int rc;
@@ -2158,6 +2158,9 @@ void render_one_item(render_item_t *render_item, int vr)
                rotate_coordinate(roll, pitch, yaw, &sun_x, &sun_y, &sun_z);
                rotate_coordinate(roll, pitch, yaw, &loc_x, &loc_y, &loc_z);
 
+               /* distance to planet */
+               dist = sqrt(loc_x * loc_x + loc_y * loc_y + loc_z * loc_z);
+
                /* calculate direction of the sun */
                angle_sun_h = atan2(sun_x, sun_z);
                angle_loc_h = atan2(loc_x, loc_z);
@@ -2213,9 +2216,9 @@ void render_one_item(render_item_t *render_item, int vr)
                        }
                }
                for (i = 0; i < PLANET_VERTICES; i++) {
-                       x[i] = loc_x + circle_x[i];
-                       y[i] = loc_y + circle_y[i];
-                       z[i] = loc_z + circle_z[i];
+                       x[i] = (loc_x + circle_x[i]) / dist * 1000000.0;
+                       y[i] = (loc_y + circle_y[i]) / dist * 1000000.0;
+                       z[i] = (loc_z + circle_z[i]) / dist * 1000000.0;
                }
                opengl_render_polygon_and_line(x, y, z, PLANET_VERTICES); /* no culling, its a planet! */
 
@@ -2237,27 +2240,27 @@ void render_one_item(render_item_t *render_item, int vr)
                if (angle > M_PI / 2.0 || (angle < 0.0 && angle > -M_PI / 2.0)) {
                        /* to the right */
                        for (i = 0; i < PLANET_VERTICES / 2 + 1; i++) {
-                               x[i] = loc_x + circle_x[i];
-                               y[i] = loc_y + circle_y[i];
-                               z[i] = loc_z + circle_z[i];
+                               x[i] = (loc_x + circle_x[i]) / dist * 1000000.0;
+                               y[i] = (loc_y + circle_y[i]) / dist * 1000000.0;
+                               z[i] = (loc_z + circle_z[i]) / dist * 1000000.0;
                        }
                        _sin = sin((1.0 - angle / (M_PI / 2)) * (M_PI / 2.0));
                        for (; i < PLANET_VERTICES; i++) {
-                               x[i] = loc_x + crescent_x[i];
-                               y[i] = loc_y + crescent_y[i];
-                               z[i] = loc_z + crescent_z[i];
+                               x[i] = (loc_x + crescent_x[i]) / dist * 1000000.0;
+                               y[i] = (loc_y + crescent_y[i]) / dist * 1000000.0;
+                               z[i] = (loc_z + crescent_z[i]) / dist * 1000000.0;
                        }
                } else {
                        /* to the left */
                        for (i = 0; i < PLANET_VERTICES / 2 + 1; i++) {
-                               x[i] = loc_x + crescent_x[i];
-                               y[i] = loc_y + crescent_y[i];
-                               z[i] = loc_z + crescent_z[i];
+                               x[i] = (loc_x + crescent_x[i]) / dist * 1000000.0;
+                               y[i] = (loc_y + crescent_y[i]) / dist * 1000000.0;
+                               z[i] = (loc_z + crescent_z[i]) / dist * 1000000.0;
                        }
                        for (; i < PLANET_VERTICES; i++) {
-                               x[i] = loc_x + circle_x[i];
-                               y[i] = loc_y + circle_y[i];
-                               z[i] = loc_z + circle_z[i];
+                               x[i] = (loc_x + circle_x[i]) / dist * 1000000.0;
+                               y[i] = (loc_y + circle_y[i]) / dist * 1000000.0;
+                               z[i] = (loc_z + circle_z[i]) / dist * 1000000.0;
                        }
                }
                opengl_render_polygon_and_line(x, y, z, PLANET_VERTICES); /* no culling, its a planet! */