Rotate planetary view over planet smoothly
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 15 Apr 2018 07:37:58 +0000 (09:37 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 22 Apr 2018 10:02:46 +0000 (12:02 +0200)
src/mercenary/main.c
src/mercenary/mercenary.h
src/mercenary/mercenary2.c
src/mercenary/mercenary3.c
src/mercenary/render.c
src/mercenary/render.h

index 62beb7e..edd88cc 100644 (file)
@@ -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;
index b65b54e..c8bd3d3 100644 (file)
@@ -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);
index 657004b..55449d2 100644 (file)
@@ -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)
index dd4cda0..0a5a76d 100644 (file)
@@ -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)
index 4acbb78..b275e43 100644 (file)
@@ -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;
index ed230c8..d790b63 100644 (file)
@@ -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);