Split off ride_get_rotated_coords()

This commit is contained in:
Michael Steenbeek 2017-10-23 10:52:10 +02:00
parent c77c15e4de
commit 887ec16b53
3 changed files with 34 additions and 40 deletions

View File

@ -3494,27 +3494,7 @@ sint32 ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, u
{ {
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != NULL) if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != NULL)
{ {
LocationXY16 rotatedCoords = {0, 0}; const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z);
switch (get_current_rotation())
{
case 0:
rotatedCoords.x = y - x;
rotatedCoords.y = ((y + x) / 2) - z;
break;
case 1:
rotatedCoords.x = -x - y;
rotatedCoords.y = ((y - x) / 2) - z;
break;
case 2:
rotatedCoords.x = x - y;
rotatedCoords.y = ((-y - x) / 2) - z;
break;
case 3:
rotatedCoords.x = y + x;
rotatedCoords.y = ((x - y) / 2) - z;
break;
}
rct_viewport * viewport = g_music_tracking_viewport; rct_viewport * viewport = g_music_tracking_viewport;
sint16 view_width = viewport->view_width; sint16 view_width = viewport->view_width;
sint16 view_width2 = view_width * 2; sint16 view_width2 = view_width * 2;
@ -8219,3 +8199,30 @@ sint32 ride_get_entry_index(sint32 rideType, sint32 rideSubType)
return subType; return subType;
} }
LocationXY16 ride_get_rotated_coords(sint16 x, sint16 y, sint16 z)
{
LocationXY16 rotatedCoords = { 0, 0 };
switch (get_current_rotation())
{
case 0:
rotatedCoords.x = y - x;
rotatedCoords.y = ((y + x) / 2) - z;
break;
case 1:
rotatedCoords.x = -x - y;
rotatedCoords.y = ((y - x) / 2) - z;
break;
case 2:
rotatedCoords.x = x - y;
rotatedCoords.y = ((-y - x) / 2) - z;
break;
case 3:
rotatedCoords.x = y + x;
rotatedCoords.y = ((x - y) / 2) - z;
break;
}
return rotatedCoords;
}

View File

@ -1212,6 +1212,8 @@ sint32 ride_get_entry_index(sint32 rideType, sint32 rideSubType);
void ride_demolish(sint32 rideIndex, sint32 flags); void ride_demolish(sint32 rideIndex, sint32 flags);
void ride_stop_peeps_queuing(sint32 rideIndex); void ride_stop_peeps_queuing(sint32 rideIndex);
LocationXY16 ride_get_rotated_coords(sint16 x, sint16 y, sint16 z);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -2283,25 +2283,10 @@ static void window_ride_construction_draw_track_piece(
TrackDefinitions[trackType].preview_z_offset; TrackDefinitions[trackType].preview_z_offset;
z -= previewZOffset; z -= previewZOffset;
sint32 start_x = x; const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z);
switch (get_current_rotation()) { x = rotatedCoords.x;
case 0: y = rotatedCoords.y;
x = y - x;
y = (y + start_x) / 2 - z;
break;
case 1:
x = -x - y;
y = (y - start_x) / 2 - z;
break;
case 2:
x -= y;
y = (-y - start_x) / 2 - z;
break;
case 3:
x += y;
y = (-y + start_x) / 2 - z;
break;
}
dpi->x += x - width / 2; dpi->x += x - width / 2;
dpi->y += y - height / 2 - 16; dpi->y += y - height / 2 - 16;
uint32 d = unknown << 16; uint32 d = unknown << 16;