Better skybox position precision
This commit is contained in:
parent
964aba4831
commit
1ddc713f16
1 changed files with 37 additions and 2 deletions
|
@ -10,6 +10,9 @@
|
||||||
#include "segment2.h"
|
#include "segment2.h"
|
||||||
#include "sm64.h"
|
#include "sm64.h"
|
||||||
|
|
||||||
|
#ifndef TARGET_N64
|
||||||
|
#define BETTER_SKYBOX_POSITION_PRECISION
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file skybox.c
|
* @file skybox.c
|
||||||
|
@ -49,10 +52,17 @@ struct Skybox {
|
||||||
u16 yaw;
|
u16 yaw;
|
||||||
/// The camera's pitch, which is bounded by +-16384, which maps to -90 to 90 degrees
|
/// The camera's pitch, which is bounded by +-16384, which maps to -90 to 90 degrees
|
||||||
s16 pitch;
|
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
|
/// The skybox's X position in world space
|
||||||
s32 scaledX;
|
s32 scaledX;
|
||||||
/// The skybox's Y position in world space
|
/// The skybox's Y position in world space
|
||||||
s32 scaledY;
|
s32 scaledY;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// The index of the upper-left tile in the 3x3 grid that gets drawn
|
/// The index of the upper-left tile in the 3x3 grid that gets drawn
|
||||||
s32 upperLeftTile;
|
s32 upperLeftTile;
|
||||||
|
@ -135,17 +145,32 @@ u8 sSkyboxColors[][3] = {
|
||||||
* (how far is the camera rotated from 0, scaled 0 to 1) *
|
* (how far is the camera rotated from 0, scaled 0 to 1) *
|
||||||
* (the screen width)
|
* (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;
|
f32 yaw = sSkyBoxInfo[player].yaw;
|
||||||
|
|
||||||
//! double literals are used instead of floats
|
//! double literals are used instead of floats
|
||||||
f32 yawScaled = SCREEN_WIDTH * 360.0 * yaw / (fov * 65536.0);
|
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
|
// Round the scaled yaw. Since yaw is a u16, it doesn't need to check for < 0
|
||||||
s32 scaledX = yawScaled + 0.5;
|
s32 scaledX = yawScaled + 0.5;
|
||||||
|
|
||||||
if (scaledX > SKYBOX_WIDTH) {
|
if (scaledX > SKYBOX_WIDTH) {
|
||||||
scaledX -= scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH;
|
scaledX -= scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return SKYBOX_WIDTH - scaledX;
|
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
|
* fov may have been used in an earlier version, but the developers changed the function to always use
|
||||||
* 90 degrees.
|
* 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).
|
// 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;
|
f32 pitchInDegrees = (f32) sSkyBoxInfo[player].pitch * 360.0 / 65535.0;
|
||||||
|
|
||||||
// Scale by 360 / fov
|
// Scale by 360 / fov
|
||||||
f32 degreesToScale = 360.0f * pitchInDegrees / 90.0;
|
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);
|
s32 roundedY = round_float(degreesToScale);
|
||||||
|
|
||||||
// Since pitch can be negative, and the tile grid starts 1 octant above the camera's focus, add
|
// Since pitch can be negative, and the tile grid starts 1 octant above the camera's focus, add
|
||||||
// 5 octants to the y position
|
// 5 octants to the y position
|
||||||
s32 scaledY = roundedY + 5 * SKYBOX_TILE_HEIGHT;
|
s32 scaledY = roundedY + 5 * SKYBOX_TILE_HEIGHT;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (scaledY > SKYBOX_HEIGHT) {
|
if (scaledY > SKYBOX_HEIGHT) {
|
||||||
scaledY = SKYBOX_HEIGHT;
|
scaledY = SKYBOX_HEIGHT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue