diff --git a/src/game/skybox.c b/src/game/skybox.c index 755fae5..7c8367c 100644 --- a/src/game/skybox.c +++ b/src/game/skybox.c @@ -10,6 +10,9 @@ #include "segment2.h" #include "sm64.h" +#ifndef TARGET_N64 +#define BETTER_SKYBOX_POSITION_PRECISION +#endif /** * @file skybox.c @@ -49,10 +52,17 @@ struct Skybox { u16 yaw; /// The camera's pitch, which is bounded by +-16384, which maps to -90 to 90 degrees s16 pitch; +#ifdef BETTER_SKYBOX_POSITION_PRECISION + /// The skybox's X position in world space + f32 scaledX; + /// The skybox's Y position in world space + f32 scaledY; +#else /// The skybox's X position in world space s32 scaledX; /// The skybox's Y position in world space s32 scaledY; +#endif /// The index of the upper-left tile in the 3x3 grid that gets drawn s32 upperLeftTile; @@ -135,17 +145,32 @@ u8 sSkyboxColors[][3] = { * (how far is the camera rotated from 0, scaled 0 to 1) * * (the screen width) */ -int calculate_skybox_scaled_x(s8 player, f32 fov) { +#ifdef BETTER_SKYBOX_POSITION_PRECISION +f32 +#else +s32 +#endif +calculate_skybox_scaled_x(s8 player, f32 fov) { f32 yaw = sSkyBoxInfo[player].yaw; //! double literals are used instead of floats f32 yawScaled = SCREEN_WIDTH * 360.0 * yaw / (fov * 65536.0); + +#ifdef BETTER_SKYBOX_POSITION_PRECISION + f32 scaledX = yawScaled; + + if (scaledX > SKYBOX_WIDTH) { + scaledX -= (s32) scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH; + } +#else // Round the scaled yaw. Since yaw is a u16, it doesn't need to check for < 0 s32 scaledX = yawScaled + 0.5; if (scaledX > SKYBOX_WIDTH) { scaledX -= scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH; } +#endif + return SKYBOX_WIDTH - scaledX; } @@ -155,17 +180,27 @@ int calculate_skybox_scaled_x(s8 player, f32 fov) { * fov may have been used in an earlier version, but the developers changed the function to always use * 90 degrees. */ -int calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) { +#ifdef BETTER_SKYBOX_POSITION_PRECISION +f32 +#else +s32 +#endif +calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) { // Convert pitch to degrees. Pitch is bounded between -90 (looking down) and 90 (looking up). f32 pitchInDegrees = (f32) sSkyBoxInfo[player].pitch * 360.0 / 65535.0; // Scale by 360 / fov f32 degreesToScale = 360.0f * pitchInDegrees / 90.0; + +#ifdef BETTER_SKYBOX_POSITION_PRECISION + f32 scaledY = degreesToScale + 5 * SKYBOX_TILE_HEIGHT; +#else s32 roundedY = round_float(degreesToScale); // Since pitch can be negative, and the tile grid starts 1 octant above the camera's focus, add // 5 octants to the y position s32 scaledY = roundedY + 5 * SKYBOX_TILE_HEIGHT; +#endif if (scaledY > SKYBOX_HEIGHT) { scaledY = SKYBOX_HEIGHT;