From 4e46765e6a885584ff035217570554675d2d3bc7 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 15 Apr 2018 09:37:58 +0200 Subject: [PATCH] Rotate planetary view over planet smoothly --- src/mercenary/main.c | 3 ++- src/mercenary/mercenary.h | 2 +- src/mercenary/mercenary2.c | 29 ++++++++++++++++++++++------- src/mercenary/mercenary3.c | 29 ++++++++++++++++++++++------- src/mercenary/render.c | 4 ++-- src/mercenary/render.h | 2 +- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/mercenary/main.c b/src/mercenary/main.c index 62beb7e..edd88cc 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -64,6 +64,7 @@ static int config_debug_transparent = 0; 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 */ #define CPU_SPEED 7093790.0; @@ -367,7 +368,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_debug_transparent); + render_capture_start(config_fov, config_improve_extend_roads, config_improve_smooth_planets, config_debug_transparent); /* execute until the rendered image is ready (wait for VBL) */ cycle_count = 0; diff --git a/src/mercenary/mercenary.h b/src/mercenary/mercenary.h index b65b54e..c8bd3d3 100644 --- a/src/mercenary/mercenary.h +++ b/src/mercenary/mercenary.h @@ -75,7 +75,7 @@ uint32_t mercenary_palette_stars(void); uint32_t mercenary_object_vertex_register(void); void mercenary_get_orientation(double *roll, double *pitch, double *yaw); void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw); -void mercenary_get_orientation_planet(double *inclination, double *azimuth); +void mercenary_get_orientation_planet(double *inclination, double *azimuth, int improved); void mercenary_get_location(int32_t *east, int32_t *height, int32_t *north); void mercenary_get_object_info(int *id, int32_t *east, int32_t *height, int32_t *north); void mercenary_coord_building_interior(int16_t *east, int32_t *height1, int32_t *height2, int32_t *height3, int32_t *height4, int16_t *north); diff --git a/src/mercenary/mercenary2.c b/src/mercenary/mercenary2.c index 657004b..55449d2 100644 --- a/src/mercenary/mercenary2.c +++ b/src/mercenary/mercenary2.c @@ -222,15 +222,30 @@ void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw) *yaw = m68k_read_memory_16(0x007AA2); } -void mercenary_get_orientation_planet(double *inclination, double *azimuth) +void mercenary_get_orientation_planet(double *inclination, double *azimuth, int improved) { - int16_t r; + uint32_t t; + + if (!improved) { + /* get plant's inclination and azimuth */ + t = m68k_read_memory_16(0x42C70) & 0x3ff; + *inclination = (double)t / 0x400 * 2 * M_PI; + t = m68k_read_memory_16(0x42C6c) & 0x3ff; + *azimuth = -(double)t / 0x400 * 2 * M_PI; + } else { + /* inclination depends on north/south position */ + t = m68k_read_memory_32(0x007ABA) >> 2; /* get position */ + t += 0x01000000; + t &= 0x03ffffff; + *inclination = (double)t / 0x04000000 * 2 * M_PI; + /* azimuth depends on east/west position and planet's rotation */ + t = m68k_read_memory_32(0x007AA6); /* get planet index */ + t = m68k_read_memory_32(25322 + t); /* get rotation of planet */ + t += m68k_read_memory_32(0x007AB2) >> 2; /* add position */ + t &= 0x03ffffff; + *azimuth = -(double)t / 0x04000000 * 2 * M_PI; - /* get plant's inclination and rotation */ - r = (int16_t)((m68k_read_memory_16(0x42C70)) & 0x3ff); - *inclination = (double)r / 1024.0 * 2 * M_PI; - r = (int16_t)((m68k_read_memory_16(0x42C6c)) & 0x3ff); - *azimuth = -(double)r / 1024.0 * 2 * M_PI; + } } void mercenary_get_location(int32_t *east, int32_t *height, int32_t *north) diff --git a/src/mercenary/mercenary3.c b/src/mercenary/mercenary3.c index dd4cda0..0a5a76d 100644 --- a/src/mercenary/mercenary3.c +++ b/src/mercenary/mercenary3.c @@ -260,15 +260,30 @@ void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw) *yaw = m68k_read_memory_16(DS_0+0x1E2a); } -void mercenary_get_orientation_planet(double *inclination, double *azimuth) +void mercenary_get_orientation_planet(double *inclination, double *azimuth, int improved) { - int16_t r; + uint32_t t; + + if (!improved) { + /* get plant's inclination and azimuth */ + t = m68k_read_memory_16(0x42C70) & 0x3ff; + *inclination = (double)t / 0x400 * 2 * M_PI; + t = m68k_read_memory_16(0x42C6c) & 0x3ff; + *azimuth = -(double)t / 0x400 * 2 * M_PI; + } else { + /* inclination depends on north/south position */ + t = m68k_read_memory_32(DS_0+0x1E42) >> 2; /* get position */ + t += 0x01000000; + t &= 0x03ffffff; + *inclination = (double)t / 0x04000000 * 2 * M_PI; + /* azimuth depends on east/west position and planet's rotation */ + t = m68k_read_memory_32(DS_0+0x1E2E); /* get planet index */ + t = m68k_read_memory_32(22362 + t); /* get rotation of planet */ + t += m68k_read_memory_32(DS_0+0x1E3A) >> 2; /* add position */ + t &= 0x03ffffff; + *azimuth = -(double)t / 0x04000000 * 2 * M_PI; - /* get plant's inclination and rotation */ - r = (int16_t)((m68k_read_memory_16(0x42C70)) & 0x3ff); - *inclination = (double)r / 1024.0 * 2 * M_PI; - r = (int16_t)((m68k_read_memory_16(0x42C6c)) & 0x3ff); - *azimuth = -(double)r / 1024.0 * 2 * M_PI; + } } void mercenary_get_location(int32_t *east, int32_t *height, int32_t *north) diff --git a/src/mercenary/render.c b/src/mercenary/render.c index 4acbb78..b275e43 100644 --- a/src/mercenary/render.c +++ b/src/mercenary/render.c @@ -287,7 +287,7 @@ static void flush_old_items(void) } /* rendering starts, initialize variables */ -void render_capture_start(double _fov, int _extend_roads, int debug) +void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int debug) { #if defined(DEBUG_COLOR) || defined(DEBUG_VERTEX) printf("start rendering a new frame...\n"); @@ -320,7 +320,7 @@ void render_capture_start(double _fov, int _extend_roads, int debug) mercenary_get_orientation(&motion_new.orientation_roll, &motion_new.orientation_pitch, &motion_new.orientation_yaw); mercenary_get_orientation_raw(&motion_new.orientation_raw_pitch, &motion_new.orientation_raw_yaw); motion_new.planet_rotation = motion_old.planet_rotation; - mercenary_get_orientation_planet(&motion_new.planet_inclination, &motion_new.planet_azimuth); + mercenary_get_orientation_planet(&motion_new.planet_inclination, &motion_new.planet_azimuth, _smooth_planets); render_item_object_info = NULL; render_item_vertices_0 = render_item_vertices_1 = render_item_vertices_2 = NULL; diff --git a/src/mercenary/render.h b/src/mercenary/render.h index ed230c8..d790b63 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 debug); +void render_capture_start(double _fov, int _extend_roads, int _smooth_planets, int debug); void render_capture_stop(void); void render_capture_event(int event); int render_all_items(double inter, int vr); -- 2.13.6