From e7629a4809518385bd83e91d3b9bd8454b5aa104 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Fri, 27 Apr 2018 17:35:59 +0200 Subject: [PATCH] Add option to fix the wrong sky rotation when flying over the planet Disabled by default of course!!!! --- src/mercenary/main.c | 12 +++++++++++- src/mercenary/render.c | 34 +++++++++++++++++++++++++--------- src/mercenary/render.h | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/mercenary/main.c b/src/mercenary/main.c index b6aba1f..e1515e6 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -76,6 +76,7 @@ static int config_debug_opengl = 0; /* render improvements */ static int config_improve_extend_roads = 1; /* set to 1 to extend roads */ static int config_improve_smooth_planets = 1; /* set to 1 to rotate planets smoothly */ +static int config_fix_sky_rotation = 0; /* set to 1 to fix sky rotation */ #define CPU_SPEED 7093790.0; @@ -142,6 +143,7 @@ int parse_args(int argc, char *argv[]) while (argc > i) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + /* | | */ print_info("Usage: %s\n", argv[0]); print_info(" -s --render-speed original | fast\n"); print_info(" Set speed of rendering to original Amiga or fast speed.\n"); @@ -161,6 +163,11 @@ int parse_args(int argc, char *argv[]) print_info(" Set field-of-view. Default is %.0f.\n", FOV_NOVAGEN); print_info(" -i --skip-intro\n"); print_info(" Skip intro sequence approaching to Eris space port.\n"); + print_info(" --fix-sky-rotation\n"); + print_info(" Sky rotates in the wrong direction, if flying over surface. This is\n"); + print_info(" fixed by rotating all sky object by 180 degrees. The original (wrong)\n"); + print_info(" rotation is default, because it preserves the game's spirit!\n"); + print_info(" This requires OpenGL rendering\n"); print_info("Debug options:\n"); print_info(" -o --debug-opengl\n"); print_info(" Use split screen to display both Amiga and OpenGL rendering.\n"); @@ -263,6 +270,9 @@ illegal_parameter: if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--skip-intro")) { config_skip_intro = 1; } else + if (!strcmp(argv[i], "--fix-sky-rotation")) { + config_fix_sky_rotation = 1; + } else if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--debug-opengl")) { config_debug_opengl = 1; } else @@ -597,7 +607,7 @@ static void main_loop(void) frame_render = 0; /* start capturing for improved graphics */ if (render_improved) - render_capture_start(config_fov, config_improve_extend_roads, config_improve_smooth_planets, config_debug_transparent); + render_capture_start(config_fov, config_improve_extend_roads, config_improve_smooth_planets, config_fix_sky_rotation, config_debug_transparent); /* execute until the rendered image is ready (wait for VBL) */ cycle_count = 0; diff --git a/src/mercenary/render.c b/src/mercenary/render.c index 4e8b98e..daa07cb 100644 --- a/src/mercenary/render.c +++ b/src/mercenary/render.c @@ -237,6 +237,7 @@ typedef struct interpolation { /* rendering options */ static int extend_roads; /* extend roads in its original width, rather than just using a single point */ +static int fix_sky_rotation; /* sky will rotate correctly by rotating planets/comet by 180 degrees */ static double fov; static double debug_opacity; static double frustum_slope_64, frustum_slope_fov; @@ -288,7 +289,7 @@ static void flush_old_items(void) } /* rendering starts, initialize variables */ -void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int debug) +void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int _fix_sky_rotation, int debug) { #if defined(DEBUG_COLOR) || defined(DEBUG_VERTEX) printf("start rendering a new frame...\n"); @@ -308,6 +309,7 @@ void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, i /* set rendering options */ fov = _fov; extend_roads = _extend_roads; + fix_sky_rotation = _fix_sky_rotation; /* set some transpareny, if debugging is enabled */ debug_opacity = (debug) ? 0.5 : 1.0; @@ -2002,6 +2004,7 @@ void render_one_item(render_item_t *render_item, int vr) double x[MAX_POLYGON], y[MAX_POLYGON], z[MAX_POLYGON]; int i; int rc; + double rotate_sky = 0.0; #ifdef DEBUG_ITEMS printf("RENDER_ITEM_COMET_POLYGON\n"); @@ -2015,9 +2018,12 @@ void render_one_item(render_item_t *render_item, int vr) if (rc < 0) break; /* rotate vertex */ - if (motion_new.planet_rotation) + if (motion_new.planet_rotation) { + if (fix_sky_rotation) + rotate_sky = M_PI; rotate_coordinate(0.0, inclination, azimuth, &x[i], &y[i], &z[i]); - rotate_coordinate(roll, pitch, yaw, &x[i], &y[i], &z[i]); + } + rotate_coordinate(roll, pitch, yaw + rotate_sky, &x[i], &y[i], &z[i]); } /* render */ opengl_render_polygon_and_line(x, y, z, render_item->u.polygon.vertices); /* no culling, because we render only two (out of four) planes! */ @@ -2137,6 +2143,7 @@ void render_one_item(render_item_t *render_item, int vr) double _sin, _cos; int i; int rc; + double rotate_sky = 0.0; #ifdef DEBUG_ITEMS printf("RENDER_ITEM_PLANET\n"); @@ -2152,11 +2159,13 @@ void render_one_item(render_item_t *render_item, int vr) size = render_item->u.planet.size; /* rotate vertex */ if (motion_new.planet_rotation) { + if (fix_sky_rotation) + rotate_sky = M_PI; rotate_coordinate(0.0, inclination, azimuth, &sun_x, &sun_y, &sun_z); rotate_coordinate(0.0, inclination, azimuth, &loc_x, &loc_y, &loc_z); } - rotate_coordinate(roll, pitch, yaw, &sun_x, &sun_y, &sun_z); - rotate_coordinate(roll, pitch, yaw, &loc_x, &loc_y, &loc_z); + rotate_coordinate(roll, pitch, yaw + rotate_sky, &sun_x, &sun_y, &sun_z); + rotate_coordinate(roll, pitch, yaw + rotate_sky, &loc_x, &loc_y, &loc_z); /* distance to planet */ dist = sqrt(loc_x * loc_x + loc_y * loc_y + loc_z * loc_z); @@ -2278,6 +2287,7 @@ void render_one_item(render_item_t *render_item, int vr) double x, y, z; int i; double red, green, blue; + double rotate_sky = 0.0; #ifdef DEBUG_ITEMS printf("RENDER_ITEM_STARS\n"); @@ -2381,9 +2391,12 @@ void render_one_item(render_item_t *render_item, int vr) x = -sin(h) * cos(v1); y = sin(v1); z = cos(h) * cos(v1); - if (motion_new.planet_rotation) + if (motion_new.planet_rotation) { + if (fix_sky_rotation) + rotate_sky = M_PI; rotate_coordinate(0.0, inclination, azimuth, &x, &y, &z); - rotate_coordinate(roll, pitch, yaw, &x, &y, &z); + } + rotate_coordinate(roll, pitch, yaw + rotate_sky, &x, &y, &z); opengl_render_point(1000000.0 * x, 1000000.0 * y, 1000000.0 * z, 0.0); } if (v2 < 0.934 && v2 > -0.934) { @@ -2392,9 +2405,12 @@ void render_one_item(render_item_t *render_item, int vr) x = -sin(h) * cos(v2); y = sin(v2); z = cos(h) * cos(v2); - if (motion_new.planet_rotation) + if (motion_new.planet_rotation) { + if (fix_sky_rotation) + rotate_sky = M_PI; rotate_coordinate(0.0, inclination, azimuth, &x, &y, &z); - rotate_coordinate(roll, pitch, yaw, &x, &y, &z); + } + rotate_coordinate(roll, pitch, yaw + rotate_sky, &x, &y, &z); opengl_render_point(1000000.0 * x, 1000000.0 * y, 1000000.0 * z, 0.0); } } diff --git a/src/mercenary/render.h b/src/mercenary/render.h index d790b63..568a3e3 100644 --- a/src/mercenary/render.h +++ b/src/mercenary/render.h @@ -1,5 +1,5 @@ -void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int debug); +void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int _fix_sky_rotation, int debug); void render_capture_stop(void); void render_capture_event(int event); int render_all_items(double inter, int vr); -- 2.13.6