From 5bb14224f764fd205474e8dbfce5ecdc683e7a63 Mon Sep 17 00:00:00 2001 From: Fazana <52551480+FazanaJ@users.noreply.github.com> Date: Wed, 25 Aug 2021 19:01:54 +0100 Subject: [PATCH] Make World scale automatic --- include/config.h | 6 +++--- src/engine/math_util.c | 3 ++- src/game/rendering_graph_node.c | 8 +++++++- src/game/rendering_graph_node.h | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/config.h b/include/config.h index 72bf0caa..3345b5da 100644 --- a/include/config.h +++ b/include/config.h @@ -101,7 +101,7 @@ //Adds multiple languages to the game. Just a placeholder for the most part, because it only works with EU, and must be enabled with EU. #define MULTILANG (0 || VERSION_EU) //Enables Puppy Camera 2, a rewritten camera that can be freely configured and modified. -//#define PUPPYCAM +#define PUPPYCAM // HACKER QOL @@ -116,8 +116,8 @@ // Custom debug mode. Press DPAD left to show the debug UI. Press DPAD right to enter the noclip mode. //#define CUSTOM_DEBUG // Include Puppyprint, a display library for text and large images. Also includes a custom, enhanced performance profiler. -//#define PUPPYPRINT -#define PUPPYPRINT_DEBUG 0 +#define PUPPYPRINT +#define PUPPYPRINT_DEBUG 1 //Visual debug enables some collision visuals. Tapping Right on the dpad will cycle between visual hitboxes, visual surfaces, both, and neither. //If puppyprint is enabled, then this can be cycled only while the screen is active. //#define VISUAL_DEBUG diff --git a/src/engine/math_util.c b/src/engine/math_util.c index a16c29f0..9abebf15 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -8,6 +8,7 @@ #include "trig_tables.inc.c" #include "surface_load.h" #include "game/puppyprint.h" +#include "game/rendering_graph_node.h" #include "config.h" @@ -583,7 +584,7 @@ void mtxf_to_mtx(Mtx *dest, Mat4 src) { for( i = 0; i < 4; i++ ) { for( j = 0; j < 3; j++ ) { - temp[i][j] = src[i][j] / WORLD_SCALE; + temp[i][j] = src[i][j] / gWorldScale; } temp[i][3] = src[i][3]; } diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 591d1272..84fc0a0a 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -46,6 +46,7 @@ s16 gMatStackIndex; Mat4 gMatStack[32]; Mtx *gMatStackFixed[32]; f32 aspect; +f32 gWorldScale = 1.0f; /** * Animation nodes have state in global variables, so this struct captures @@ -259,7 +260,12 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { aspect = 1.33333f; #endif - guPerspective(mtx, &perspNorm, node->fov, aspect, node->near / WORLD_SCALE, node->far / WORLD_SCALE, 1.0f); + if (gCurrLevelNum > 3) + gWorldScale = MAX(((gCamera->pos[0] * gCamera->pos[0]) + (gCamera->pos[1] * gCamera->pos[1]) + (gCamera->pos[2] * gCamera->pos[2]))/67108864, 1.0f); + else + gWorldScale = 1.0f; + + guPerspective(mtx, &perspNorm, node->fov, aspect, node->near / gWorldScale, node->far / gWorldScale, 1.0f); gSPPerspNormalize(gDisplayListHead++, perspNorm); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); diff --git a/src/game/rendering_graph_node.h b/src/game/rendering_graph_node.h index 097c7876..8c37e512 100644 --- a/src/game/rendering_graph_node.h +++ b/src/game/rendering_graph_node.h @@ -12,6 +12,7 @@ extern struct GraphNodeCamera *gCurGraphNodeCamera; extern struct GraphNodeObject *gCurGraphNodeObject; extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject; extern u16 gAreaUpdateCounter; +extern f32 gWorldScale; // after processing an object, the type is reset to this #define ANIM_TYPE_NONE 0