From 1633abc11abca4624d9043b2912ffade1ef7418f Mon Sep 17 00:00:00 2001 From: Unnunu Date: Fri, 30 May 2025 16:50:19 +0300 Subject: [PATCH] decompile and document math_util.c (#595) --- README.md | 4 +- include/structs.h | 6 +- include/types.h | 4 +- src/audio_spatial.c | 4 +- src/audio_vehicle.c | 4 +- src/audiomgr.c | 2 +- src/camera.c | 171 +++--- src/camera.h | 30 +- src/fade_transition.c | 40 +- src/fade_transition.h | 16 +- src/font.c | 22 +- src/font.h | 4 +- src/game_ui.c | 37 +- src/game_ui.h | 6 +- src/hasm/math_util.c | 848 +++++++++++++++------------ src/hasm/math_util.s | 96 +-- src/hasm/obj_shade_fast.s | 6 +- src/lights.c | 18 +- src/lights.h | 4 +- src/math_util.h | 46 +- src/menu.c | 41 +- src/menu.h | 10 +- src/object_functions.c | 82 ++- src/objects.c | 117 ++-- src/objects.h | 8 +- src/particles.c | 115 ++-- src/particles.h | 2 +- src/printf.c | 6 +- src/racer.c | 134 ++--- src/rcp_dkr.c | 28 +- src/rcp_dkr.h | 9 +- src/screen_asset.c | 2 +- src/textures_sprites.c | 60 +- src/thread3_main.c | 26 +- src/tracks.c | 26 +- src/tracks.h | 4 +- src/vehicle_smokey.c | 2 +- src/vehicle_tricky.c | 4 +- src/waves.c | 14 +- src/weather.c | 77 ++- src/weather.h | 4 +- ver/symbols/symbol_addrs.jpn.v79.txt | 54 +- ver/symbols/symbol_addrs.pal.v77.txt | 54 +- ver/symbols/symbol_addrs.pal.v80.txt | 54 +- ver/symbols/symbol_addrs.us.v77.txt | 54 +- ver/symbols/symbol_addrs.us.v80.txt | 54 +- 46 files changed, 1253 insertions(+), 1156 deletions(-) diff --git a/README.md b/README.md index 3c029904..590eb5a2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This repo contains a work-in-progress decompilation of Diddy Kong Racing for the All versions are supported, and the US 1.0 version (SHA1 = 0cb115d8716dbbc2922fda38e533b9fe63bb9670) of the game is the default if not specified. -As of May 28, 2025, this is our current score: +As of May 30, 2025, this is our current score:     Decomp progress: 88.84% @@ -117,7 +117,7 @@ s32 is_drumstick_unlocked(void) { ``` -As of May 28, 2025, this is our current score: +As of May 30, 2025, this is our current score: ``` =================================================================== ADVENTURE ONE (ASM -> C Decompilation) diff --git a/include/structs.h b/include/structs.h index c4b2b413..15f1a60f 100644 --- a/include/structs.h +++ b/include/structs.h @@ -589,7 +589,7 @@ typedef struct TexCoords { #define BACKFACE_CULL 0x00 #define BACKFACE_DRAW 0x40 -#define DKR_TRIANGLE(flags, ind0, ind1, ind2) ((flags << 24) | (ind0 << 16) | (ind1 << 8) | (ind2 << 0)) +#define DKR_TRIANGLE(flags, ind0, ind1, ind2) (((flags) << 24) | ((ind0) << 16) | ((ind1) << 8) | ((ind2) << 0)) /* Size: 0x10 bytes */ typedef struct Triangle { @@ -916,8 +916,8 @@ typedef struct ShadeProperties { typedef f32 FakeHalfMatrix[2][4]; typedef struct Object_5C { union { - /* 0x0000 */ Matrix matrices[4]; - /* 0x0000 */ FakeHalfMatrix _matrices[8]; // This is a hack. The Matrix[4] is the real one. + /* 0x0000 */ MtxF matrices[4]; + /* 0x0000 */ FakeHalfMatrix _matrices[8]; // This is a hack. The MtxF[4] is the real one. }; /* 0x0100 */ void *unk100; /* 0x0104 */ u8 unk104; diff --git a/include/types.h b/include/types.h index 7c37fd8c..548862f5 100644 --- a/include/types.h +++ b/include/types.h @@ -3,8 +3,8 @@ #include -typedef float Matrix[4][4]; -typedef s32 MatrixS[4][4]; +typedef float MtxF[4][4]; +typedef s32 MtxS[4][4]; typedef s16 VertexList; typedef u8 TriangleList; typedef u32 uintptr_t; diff --git a/src/audio_spatial.c b/src/audio_spatial.c index 1c46b696..8b2739c8 100644 --- a/src/audio_spatial.c +++ b/src/audio_spatial.c @@ -919,8 +919,8 @@ void audspat_debug_render_line(Gfx **dList, Vertex **verts, Triangle **tris, f32 temp_verts = *verts; temp_tris = *tris; material_set_no_tex_offset(&temp_dlist, NULL, RENDER_NONE); - gSPVertexDKR(temp_dlist++, OS_PHYSICAL_TO_K0(temp_verts), 4, 0); - gSPPolygon(temp_dlist++, OS_PHYSICAL_TO_K0(temp_tris), 2, 0); + gSPVertexDKR(temp_dlist++, OS_K0_TO_PHYSICAL(temp_verts), 4, 0); + gSPPolygon(temp_dlist++, OS_K0_TO_PHYSICAL(temp_tris), 2, 0); temp_verts[0].x = x1; temp_verts[0].y = (y1 + 5); temp_verts[0].z = z1; diff --git a/src/audio_vehicle.c b/src/audio_vehicle.c index 2f5b14a7..b9e80b78 100644 --- a/src/audio_vehicle.c +++ b/src/audio_vehicle.c @@ -284,8 +284,8 @@ void racer_sound_car(Object *obj, u32 buttonsPressed, u32 buttonsHeld, s32 ticks // Add engine jitter effect for player cars to simulate engine vibration // Max pitch variation ±0.02, volume variation ±5 if (gSoundRacerObj->playerIndex != PLAYER_COMPUTER) { - if (get_random_number_from_range(0, 10) < 7) { - gRacerSound->engineJitter += get_random_number_from_range(0, 10) - 5; + if (rand_range(0, 10) < 7) { + gRacerSound->engineJitter += rand_range(0, 10) - 5; if (gRacerSound->engineJitter > 5) { gRacerSound->engineJitter = 5; } else if (gRacerSound->engineJitter < -5) { diff --git a/src/audiomgr.c b/src/audiomgr.c index eb5b0c18..8983901a 100644 --- a/src/audiomgr.c +++ b/src/audiomgr.c @@ -292,7 +292,7 @@ static u32 __amHandleFrameMsg(AudioInfo *info, AudioInfo *lastInfo) { #ifdef ANTI_TAMPER // Antipiracy measure if (gAntiPiracyAudioFreq) { - osAiSetFrequency(get_random_number_from_range(0, 10000) + OUTPUT_RATE); + osAiSetFrequency(rand_range(0, 10000) + OUTPUT_RATE); } #endif } diff --git a/src/camera.c b/src/camera.c index 2c966adf..77bf7343 100644 --- a/src/camera.c +++ b/src/camera.c @@ -66,7 +66,7 @@ ObjectTransform D_800DD2A0 = { { { { 0, 0, 0 } } }, { 0 }, 1.0f, 0.0f, 0.0f, 0.0f, }; -Matrix gOrthoMatrixF = { +MtxF gOrthoMatrixF = { { 1.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f }, @@ -98,17 +98,17 @@ f32 gModelMatrixViewX[6]; f32 gModelMatrixViewY[6]; f32 gModelMatrixViewZ[5]; u16 perspNorm; -Matrix *gModelMatrixF[6]; -MatrixS *gModelMatrixS[6]; +MtxF *gModelMatrixF[6]; +Mtx *gModelMatrix[6]; f32 D_80120DA0[5 * 16]; -Matrix gPerspectiveMatrixF; -Matrix gViewMatrixF; -Matrix gCameraMatrixF; -Matrix gProjectionMatrixF; -MatrixS gProjectionMatrixS; -UNUSED MatrixS gUnusedProjectionMatrixS; // Copied to the same way as gProjectionMatrixS, but not actually used. -Matrix gCurrentModelMatrixF; -Matrix gCurrentModelMatrixS; +MtxF gPerspectiveMatrixF; +MtxF gViewMatrixF; +MtxF gCameraMatrixF; +MtxF gProjectionMatrixF; +Mtx gProjectionMatrix; +UNUSED Mtx gUnusedProjectionMatrix; // Copied to the same way as gProjectionMatrix, but not actually used. +MtxF gCurrentModelMatrixF; +MtxF gCurrentModelMatrixS; /******************************/ @@ -122,7 +122,7 @@ void cam_init(void) { u32 stat; // clang-format off - for (i = 0; i < 5; i++) { gModelMatrixF[i] = (Matrix*)&D_80120DA0[i << 4]; } + for (i = 0; i < 5; i++) { gModelMatrixF[i] = (MtxF*)&D_80120DA0[i << 4]; } // clang-format on for (j = 0; j < 8; j++) { @@ -149,7 +149,7 @@ void cam_init(void) { guPerspectiveF(gPerspectiveMatrixF, &perspNorm, CAMERA_DEFAULT_FOV, CAMERA_ASPECT, CAMERA_NEAR, CAMERA_FAR, CAMERA_SCALE); - f32_matrix_to_s16_matrix(&gPerspectiveMatrixF, &gProjectionMatrixS); + mtxf_to_mtx(&gPerspectiveMatrixF, &gProjectionMatrix); gCurCamFOV = CAMERA_DEFAULT_FOV; } @@ -195,7 +195,7 @@ void cam_set_fov(f32 camFieldOfView) { gCurCamFOV = camFieldOfView; guPerspectiveF(gPerspectiveMatrixF, &perspNorm, camFieldOfView, CAMERA_ASPECT, CAMERA_NEAR, CAMERA_FAR, CAMERA_SCALE); - f32_matrix_to_s16_matrix(&gPerspectiveMatrixF, &gProjectionMatrixS); + mtxf_to_mtx(&gPerspectiveMatrixF, &gProjectionMatrix); } } @@ -205,13 +205,13 @@ void cam_set_fov(f32 camFieldOfView) { UNUSED void cam_reset_fov(void) { guPerspectiveF(gPerspectiveMatrixF, &perspNorm, CAMERA_DEFAULT_FOV, CAMERA_ASPECT, CAMERA_NEAR, CAMERA_FAR, CAMERA_SCALE); - f32_matrix_to_s16_matrix(&gPerspectiveMatrixF, &gProjectionMatrixS); + mtxf_to_mtx(&gPerspectiveMatrixF, &gProjectionMatrix); } /** * Return the current fixed point model matrix. */ -UNUSED Matrix *matrix_get_model_s16(void) { +UNUSED MtxF *matrix_get_model_s16(void) { return &gCurrentModelMatrixS; } @@ -234,7 +234,7 @@ s32 get_current_viewport(void) { /** * Initialises the camera object for the tracks menu. */ -void camera_init_tracks_menu(Gfx **dList, MatrixS **mtxS) { +void camera_init_tracks_menu(Gfx **dList, Mtx **mtxS) { Camera *cam; s16 angleY; s16 angleX; @@ -606,7 +606,7 @@ UNUSED void copy_framebuffer_size_to_coords(s32 *x1, s32 *y1, s32 *x2, s32 *y2) *y2 = GET_VIDEO_HEIGHT(widthAndHeight); } -void viewport_main(Gfx **dlist, MatrixS **mats) { +void viewport_main(Gfx **dlist, Mtx **mats) { u32 y; u32 x; u32 tempX; @@ -860,7 +860,7 @@ void viewport_scissor(Gfx **dList) { } // Official Name: camGetPlayerProjMtx / camSetProjMtx - ?? -void func_80067D3C(Gfx **dList, UNUSED MatrixS **mats) { +void func_80067D3C(Gfx **dList, UNUSED Mtx **mats) { s32 temp; gSPPerspNormalize((*dList)++, perspNorm); @@ -882,8 +882,8 @@ void func_80067D3C(Gfx **dList, UNUSED MatrixS **mats) { } gCameraTransform.z_position = -gCameras[gActiveCameraID].trans.z_position; - object_inverse_transform_to_matrix(gCameraMatrixF, &gCameraTransform); - f32_matrix_mult(&gCameraMatrixF, &gPerspectiveMatrixF, &gViewMatrixF); + mtxf_from_inverse_transform(&gCameraMatrixF, &gCameraTransform); + mtxf_mul(&gCameraMatrixF, &gPerspectiveMatrixF, &gViewMatrixF); gCameraTransform.rotation.y_rotation = -0x8000 - gCameras[gActiveCameraID].trans.rotation.y_rotation; gCameraTransform.rotation.x_rotation = @@ -897,8 +897,8 @@ void func_80067D3C(Gfx **dList, UNUSED MatrixS **mats) { } gCameraTransform.z_position = gCameras[gActiveCameraID].trans.z_position; - object_transform_to_matrix(gProjectionMatrixF, &gCameraTransform); - f32_matrix_to_s16_matrix(&gProjectionMatrixF, &gUnusedProjectionMatrixS); + mtxf_from_transform(&gProjectionMatrixF, &gCameraTransform); + mtxf_to_mtx(&gProjectionMatrixF, &gUnusedProjectionMatrix); gActiveCameraID = temp; } @@ -917,7 +917,7 @@ void set_ortho_matrix_height(f32 value) { * Used for drawing triangles on screen as HUD. * Official Name: camStandardOrtho */ -void set_ortho_matrix_view(Gfx **dList, MatrixS **mtx) { +void set_ortho_matrix_view(Gfx **dList, Mtx **mtx) { u32 widthAndHeight; s32 width, height; s32 i, j; @@ -925,8 +925,8 @@ void set_ortho_matrix_view(Gfx **dList, MatrixS **mtx) { widthAndHeight = fb_size(); height = GET_VIDEO_HEIGHT(widthAndHeight); width = GET_VIDEO_WIDTH(widthAndHeight); - f32_matrix_to_s16_matrix(&gOrthoMatrixF, *mtx); - gModelMatrixS[0] = *mtx; + mtxf_to_mtx(&gOrthoMatrixF, *mtx); + gModelMatrix[0] = *mtx; gViewportStack[gActiveCameraID + 5].vp.vscale[0] = width * 2; gViewportStack[gActiveCameraID + 5].vp.vscale[1] = width * 2; gViewportStack[gActiveCameraID + 5].vp.vtrans[0] = width * 2; @@ -947,12 +947,12 @@ void set_ortho_matrix_view(Gfx **dList, MatrixS **mtx) { } // Official Name: camStandardPersp? -void func_8006807C(Gfx **dList, MatrixS **mtx) { - object_inverse_transform_to_matrix(gCurrentModelMatrixF, &D_800DD288); - f32_matrix_mult(&gCurrentModelMatrixF, &gPerspectiveMatrixF, &gViewMatrixF); - object_inverse_transform_to_matrix((float(*)[4]) gModelMatrixF[0], &D_800DD2A0); - f32_matrix_mult(gModelMatrixF[0], &gViewMatrixF, &gCurrentModelMatrixF); - f32_matrix_to_s16_matrix(&gCurrentModelMatrixF, *mtx); +void func_8006807C(Gfx **dList, Mtx **mtx) { + mtxf_from_inverse_transform(&gCurrentModelMatrixF, &D_800DD288); + mtxf_mul(&gCurrentModelMatrixF, &gPerspectiveMatrixF, &gViewMatrixF); + mtxf_from_inverse_transform(gModelMatrixF[0], &D_800DD2A0); + mtxf_mul(gModelMatrixF[0], &gViewMatrixF, &gCurrentModelMatrixF); + mtxf_to_mtx(&gCurrentModelMatrixF, *mtx); gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_0); gModelMatrixStackPos = 0; gMatrixType = G_MTX_DKR_INDEX_0; @@ -1011,11 +1011,11 @@ UNUSED const char D_800E6F44[] = "cameraPushSprMtx: model stack overflow!!\n"; * Used when the next thing rendered relies on there not being any matrix offset. * Official Name: camOffsetZero? */ -void matrix_world_origin(Gfx **dList, MatrixS **mtx) { - f32_matrix_from_position(gModelMatrixF[gModelMatrixStackPos], 0.0f, 0.0f, 0.0f); - f32_matrix_mult(gModelMatrixF[gModelMatrixStackPos], &gViewMatrixF, &gCurrentModelMatrixF); - f32_matrix_to_s16_matrix(&gCurrentModelMatrixF, *mtx); - gModelMatrixS[gModelMatrixStackPos] = *mtx; +void matrix_world_origin(Gfx **dList, Mtx **mtx) { + mtxf_from_translation(gModelMatrixF[gModelMatrixStackPos], 0.0f, 0.0f, 0.0f); + mtxf_mul(gModelMatrixF[gModelMatrixStackPos], &gViewMatrixF, &gCurrentModelMatrixF); + mtxf_to_mtx(&gCurrentModelMatrixF, *mtx); + gModelMatrix[gModelMatrixStackPos] = *mtx; gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), gMatrixType); } @@ -1030,7 +1030,7 @@ void sprite_anim_off(s32 setting) { /** * Calculates angle from object to camera, then renders the sprite as a billboard, facing the camera. */ -s32 render_sprite_billboard(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, Sprite *arg4, s32 flags) { +s32 render_sprite_billboard(Gfx **dList, Mtx **mtx, Vertex **vertexList, Object *obj, Sprite *arg4, s32 flags) { f32 diffX; f32 diffY; Vertex *v; @@ -1089,13 +1089,12 @@ s32 render_sprite_billboard(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Obj gCameraTransform.x_position = obj->segment.trans.x_position; gCameraTransform.y_position = obj->segment.trans.y_position; gCameraTransform.z_position = obj->segment.trans.z_position; - object_transform_to_matrix(gCurrentModelMatrixF, &gCameraTransform); + mtxf_from_transform(&gCurrentModelMatrixF, &gCameraTransform); gModelMatrixStackPos++; - f32_matrix_mult(&gCurrentModelMatrixF, gModelMatrixF[gModelMatrixStackPos - 1], - gModelMatrixF[gModelMatrixStackPos]); - f32_matrix_mult(gModelMatrixF[gModelMatrixStackPos], &gViewMatrixF, &gCurrentModelMatrixF); - f32_matrix_to_s16_matrix(&gCurrentModelMatrixF, *mtx); - gModelMatrixS[gModelMatrixStackPos] = *mtx; + mtxf_mul(&gCurrentModelMatrixF, gModelMatrixF[gModelMatrixStackPos - 1], gModelMatrixF[gModelMatrixStackPos]); + mtxf_mul(gModelMatrixF[gModelMatrixStackPos], &gViewMatrixF, &gCurrentModelMatrixF); + mtxf_to_mtx(&gCurrentModelMatrixF, *mtx); + gModelMatrix[gModelMatrixStackPos] = *mtx; gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_2); gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(&gVehiclePartVertex), 1, 0); } else { @@ -1117,10 +1116,9 @@ s32 render_sprite_billboard(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Obj } textureFrame = obj->segment.animFrame; gModelMatrixStackPos++; - f32_matrix_from_rotation_and_scale((f32(*)[4]) gModelMatrixF[gModelMatrixStackPos], angleDiff, - obj->segment.trans.scale, gVideoAspectRatio); - f32_matrix_to_s16_matrix(gModelMatrixF[gModelMatrixStackPos], *mtx); - gModelMatrixS[gModelMatrixStackPos] = *mtx; + mtxf_billboard(gModelMatrixF[gModelMatrixStackPos], angleDiff, obj->segment.trans.scale, gVideoAspectRatio); + mtxf_to_mtx(gModelMatrixF[gModelMatrixStackPos], *mtx); + gModelMatrix[gModelMatrixStackPos] = *mtx; gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_2); gDkrEnableBillboard((*dList)++); } @@ -1152,14 +1150,14 @@ s32 render_sprite_billboard(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Obj * Sets transform and scale matrices to set position and size, loads the texture, sets the rendermodes, then draws the * result onscreen. */ -void render_ortho_triangle_image(Gfx **dList, MatrixS **mtx, Vertex **vtx, ObjectSegment *segment, Sprite *sprite, +void render_ortho_triangle_image(Gfx **dList, Mtx **mtx, Vertex **vtx, ObjectSegment *segment, Sprite *sprite, s32 flags) { UNUSED s32 pad; f32 scale; s32 index; Vertex *temp_v1; - Matrix aspectMtxF; - Matrix scaleMtxF; + MtxF aspectMtxF; + MtxF scaleMtxF; if (sprite != NULL) { temp_v1 = *vtx; @@ -1183,17 +1181,17 @@ void render_ortho_triangle_image(Gfx **dList, MatrixS **mtx, Vertex **vtx, Objec gCameraTransform.z_position = 0.0f; if (gAdjustViewportHeight) { scale = segment->trans.scale; - f32_matrix_from_scale(scaleMtxF, scale, scale, 1.0f); - f32_matrix_from_rotation_and_scale(aspectMtxF, 0, 1.0f, gVideoAspectRatio); - f32_matrix_mult(&aspectMtxF, &scaleMtxF, &gCurrentModelMatrixF); + mtxf_from_scale(&scaleMtxF, scale, scale, 1.0f); + mtxf_billboard(&aspectMtxF, 0, 1.0f, gVideoAspectRatio); + mtxf_mul(&aspectMtxF, &scaleMtxF, &gCurrentModelMatrixF); } else { scale = segment->trans.scale; - f32_matrix_from_scale(gCurrentModelMatrixF, scale, scale, 1.0f); + mtxf_from_scale(&gCurrentModelMatrixF, scale, scale, 1.0f); } - object_inverse_transform_to_matrix(aspectMtxF, &gCameraTransform); - f32_matrix_mult(&gCurrentModelMatrixF, &aspectMtxF, gModelMatrixF[gModelMatrixStackPos]); - f32_matrix_to_s16_matrix(gModelMatrixF[gModelMatrixStackPos], *mtx); - gModelMatrixS[gModelMatrixStackPos] = *mtx; + mtxf_from_inverse_transform(&aspectMtxF, &gCameraTransform); + mtxf_mul(&gCurrentModelMatrixF, &aspectMtxF, gModelMatrixF[gModelMatrixStackPos]); + mtxf_to_mtx(gModelMatrixF[gModelMatrixStackPos], *mtx); + gModelMatrix[gModelMatrixStackPos] = *mtx; gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_2); gDkrEnableBillboard((*dList)++); if (gSpriteAnimOff == FALSE) { @@ -1218,7 +1216,7 @@ void render_ortho_triangle_image(Gfx **dList, MatrixS **mtx, Vertex **vtx, Objec * Generate a matrix with rotation, scaling and shearing and run it. * Used for wavy type effects like the shield. */ -void apply_object_shear_matrix(Gfx **dList, MatrixS **mtx, Object *arg2, Object *arg3, f32 shear) { +void apply_object_shear_matrix(Gfx **dList, Mtx **mtx, Object *arg2, Object *arg3, f32 shear) { UNUSED s32 pad; f32 cossf_x_arg2; f32 cossf_y_arg2; @@ -1237,7 +1235,7 @@ void apply_object_shear_matrix(Gfx **dList, MatrixS **mtx, Object *arg2, Object f32 arg3_xPos; f32 arg3_yPos; f32 arg3_zPos; - Matrix matrix_mult; + MtxF matrix_mult; cossf_x_arg2 = coss_f(arg2->segment.trans.rotation.x_rotation); sinsf_x_arg2 = sins_f(arg2->segment.trans.rotation.x_rotation); @@ -1313,41 +1311,40 @@ void apply_object_shear_matrix(Gfx **dList, MatrixS **mtx, Object *arg2, Object (arg2_zPos * (cossf_x_arg3 * cossf_y_arg3)) + arg3_zPos; matrix_mult[3][3] = 1.0f; - f32_matrix_mult(&matrix_mult, &gViewMatrixF, &gCurrentModelMatrixS); - f32_matrix_to_s16_matrix(&gCurrentModelMatrixS, *mtx); + mtxf_mul(&matrix_mult, &gViewMatrixF, &gCurrentModelMatrixS); + mtxf_to_mtx(&gCurrentModelMatrixS, *mtx); gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_1); } /** * Official Name: camPushModelMtx */ -s32 cam_push_model_mtx(Gfx **dList, MatrixS **mtx, ObjectTransform *trans, f32 scaleY, f32 offsetY) { +s32 cam_push_model_mtx(Gfx **dList, Mtx **mtx, ObjectTransform *trans, f32 scaleY, f32 offsetY) { f32 tempX; f32 tempY; f32 tempZ; s32 index; f32 scaleFactor; - object_transform_to_matrix(gCurrentModelMatrixF, trans); + mtxf_from_transform(&gCurrentModelMatrixF, trans); if (offsetY != 0.0f) { - f32_matrix_translate_y_axis(&gCurrentModelMatrixF, offsetY); + mtxf_translate_y(&gCurrentModelMatrixF, offsetY); } if (scaleY != 1.0f) { - f32_matrix_scale_y_axis(&gCurrentModelMatrixF, scaleY); + mtxf_scale_y(&gCurrentModelMatrixF, scaleY); } - f32_matrix_mult(&gCurrentModelMatrixF, gModelMatrixF[gModelMatrixStackPos], - gModelMatrixF[gModelMatrixStackPos + 1]); - f32_matrix_mult(gModelMatrixF[gModelMatrixStackPos + 1], &gViewMatrixF, &gCurrentModelMatrixS); - f32_matrix_to_s16_matrix(&gCurrentModelMatrixS, *mtx); + mtxf_mul(&gCurrentModelMatrixF, gModelMatrixF[gModelMatrixStackPos], gModelMatrixF[gModelMatrixStackPos + 1]); + mtxf_mul(gModelMatrixF[gModelMatrixStackPos + 1], &gViewMatrixF, &gCurrentModelMatrixS); + mtxf_to_mtx(&gCurrentModelMatrixS, *mtx); gModelMatrixStackPos++; - gModelMatrixS[0, gModelMatrixStackPos] = *mtx; // Should be [gModelMatrixStackPos] - if (gModelMatrixStackPos >= ARRAY_COUNT(gModelMatrixS)) { + gModelMatrix[0, gModelMatrixStackPos] = *mtx; // Should be [gModelMatrixStackPos] + if (gModelMatrixStackPos >= ARRAY_COUNT(gModelMatrix)) { stubbed_printf("cameraPushModelMtx: model stack overflow!!\n"); } if (1) {} if (1) {}; // Fakematch gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_1); - guMtxXFMF(*gModelMatrixF[gModelMatrixStackPos], 0.0f, 0.0f, 0.0f, &tempX, &tempY, &tempZ); + mtxf_transform_point(gModelMatrixF[gModelMatrixStackPos], 0.0f, 0.0f, 0.0f, &tempX, &tempY, &tempZ); index = gActiveCameraID; if (gCutsceneCameraActive) { index += 4; @@ -1362,8 +1359,8 @@ s32 cam_push_model_mtx(Gfx **dList, MatrixS **mtx, ObjectTransform *trans, f32 s gCameraTransform.y_position = 0.0f; gCameraTransform.z_position = 0.0f; gCameraTransform.scale = 1.0f; - object_inverse_transform_to_matrix(gCurrentModelMatrixF, &gCameraTransform); - guMtxXFMF(gCurrentModelMatrixF, tempX, tempY, tempZ, &tempX, &tempY, &tempZ); + mtxf_from_inverse_transform(&gCurrentModelMatrixF, &gCameraTransform); + mtxf_transform_point(&gCurrentModelMatrixF, tempX, tempY, tempZ, &tempX, &tempY, &tempZ); scaleFactor = 1.0f / trans->scale; tempX *= scaleFactor; tempY *= scaleFactor; @@ -1381,7 +1378,7 @@ s32 cam_push_model_mtx(Gfx **dList, MatrixS **mtx, ObjectTransform *trans, f32 s /** * Calculate the rotation matrix for an actors head, then run it. */ -void apply_head_turning_matrix(Gfx **dList, MatrixS **mtx, Object_68 *objGfx, s16 headAngle) { +void apply_head_turning_matrix(Gfx **dList, Mtx **mtx, Object_68 *objGfx, s16 headAngle) { f32 coss_headAngle; f32 sins_headAngle; f32 offsetX; @@ -1389,8 +1386,8 @@ void apply_head_turning_matrix(Gfx **dList, MatrixS **mtx, Object_68 *objGfx, s1 f32 offsetZ; f32 coss_unk1C; f32 sins_unk1C; - Matrix rotationMtxF; - Matrix headMtxF; + MtxF rotationMtxF; + MtxF headMtxF; offsetX = (f32) objGfx->offsetX; offsetY = (f32) objGfx->offsetY; @@ -1417,8 +1414,8 @@ void apply_head_turning_matrix(Gfx **dList, MatrixS **mtx, Object_68 *objGfx, s1 (-offsetZ * (sins_headAngle * sins_unk1C)) + offsetY; headMtxF[3][2] = (-offsetX * -sins_headAngle) + (-offsetZ * coss_headAngle) + offsetZ; headMtxF[3][3] = 1.0f; - f32_matrix_mult(&headMtxF, &gCurrentModelMatrixS, &rotationMtxF); - f32_matrix_to_s16_matrix(&rotationMtxF, *mtx); + mtxf_mul(&headMtxF, &gCurrentModelMatrixS, &rotationMtxF); + mtxf_to_mtx(&rotationMtxF, *mtx); gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL((*mtx)++), G_MTX_DKR_INDEX_2); gSPSelectMatrixDKR((*dList)++, G_MTX_DKR_INDEX_1); } @@ -1451,7 +1448,7 @@ void apply_matrix_from_stack(Gfx **dList) { } // Fakematch if (gModelMatrixStackPos > 0) { - gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL(gModelMatrixS[gModelMatrixStackPos]), G_MTX_DKR_INDEX_1); + gSPMatrixDKR((*dList)++, OS_K0_TO_PHYSICAL(gModelMatrix[gModelMatrixStackPos]), G_MTX_DKR_INDEX_1); } else { gSPSelectMatrixDKR((*dList)++, G_MTX_DKR_INDEX_0); } @@ -1524,21 +1521,21 @@ Camera *get_cutscene_camera_segment(void) { /** * Return the current floating point projection matrix. */ -Matrix *get_projection_matrix_f32(void) { +MtxF *get_projection_matrix_f32(void) { return &gProjectionMatrixF; } /** * Return the current fixed point projection matrix. */ -MatrixS *get_projection_matrix_s16(void) { - return &gProjectionMatrixS; +Mtx *get_projection_matrix_s16(void) { + return &gProjectionMatrix; } /** * Return the current camera matrix. */ -Matrix *get_camera_matrix(void) { +MtxF *get_camera_matrix(void) { return &gCameraMatrixF; } @@ -1548,7 +1545,7 @@ Matrix *get_camera_matrix(void) { f32 get_distance_to_camera(f32 x, f32 y, f32 z) { f32 ox, oy, oz; - guMtxXFMF(gCameraMatrixF, x, y, z, &ox, &oy, &oz); + mtxf_transform_point(&gCameraMatrixF, x, y, z, &ox, &oy, &oz); return oz; } diff --git a/src/camera.h b/src/camera.h index c790a0fa..793998e0 100644 --- a/src/camera.h +++ b/src/camera.h @@ -99,10 +99,10 @@ void func_800660C0(void); void func_800660D0(void); UNUSED f32 cam_get_fov(void); void cam_set_fov(f32 camFieldOfView); -Matrix *matrix_get_model_s16(void); +MtxF *matrix_get_model_s16(void); s32 cam_get_viewport_layout(void); s32 get_current_viewport(void); -void camera_init_tracks_menu(Gfx **dList, MatrixS **mtxS); +void camera_init_tracks_menu(Gfx **dList, Mtx **mtxS); f32 get_distance_to_active_camera(f32 xPos, f32 yPos, f32 zPos); void camera_reset(s32 xPos, s32 yPos, s32 zPos, s32 angleZ, s32 angleX, s32 angleY); void write_to_object_render_stack(s32 stackPos, f32 xPos, f32 yPos, f32 zPos, s16 arg4, s16 arg5, s16 arg6); @@ -119,31 +119,31 @@ s32 copy_viewport_background_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1, void copy_viewport_frame_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1, s32 *x2, s32 *y2); void copy_framebuffer_size_to_coords(s32 *x1, s32 *y1, s32 *x2, s32 *y2); void set_ortho_matrix_height(f32 value); -void set_ortho_matrix_view(Gfx **dList, MatrixS **mtx); -void func_8006807C(Gfx **dList, MatrixS **mtx); +void set_ortho_matrix_view(Gfx **dList, Mtx **mtx); +void func_8006807C(Gfx **dList, Mtx **mtx); void viewport_rsp_set(Gfx **dList, s32 halfWidth, s32 halfHeight, s32 centerX, s32 centerY); void viewport_reset(Gfx **dList); -void matrix_world_origin(Gfx **dList, MatrixS **mtx); +void matrix_world_origin(Gfx **dList, Mtx **mtx); void sprite_anim_off(s32 setting); Camera *cam_get_active_camera_no_cutscenes(void); Camera *cam_get_active_camera(void); Camera *get_cutscene_camera_segment(void); -Matrix *get_projection_matrix_f32(void); -MatrixS *get_projection_matrix_s16(void); -Matrix *get_camera_matrix(void); +MtxF *get_projection_matrix_f32(void); +Mtx *get_projection_matrix_s16(void); +MtxF *get_camera_matrix(void); f32 get_distance_to_camera(f32 x, f32 y, f32 z); void set_camera_shake_by_distance(f32 x, f32 y, f32 z, f32 dist, f32 magnitude); void set_camera_shake(f32 magnitude); -void func_80067D3C(Gfx **dList, MatrixS **mats); -void render_ortho_triangle_image(Gfx **dList, MatrixS **mtx, Vertex **vtx, ObjectSegment *segment, Sprite *sprite, s32 flags); -s32 render_sprite_billboard(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, Sprite *arg4, s32 flags); -s32 cam_push_model_mtx(Gfx **dList, MatrixS **mtx, ObjectTransform *trans, f32 scaleY, f32 offsetY); +void func_80067D3C(Gfx **dList, Mtx **mats); +void render_ortho_triangle_image(Gfx **dList, Mtx **mtx, Vertex **vtx, ObjectSegment *segment, Sprite *sprite, s32 flags); +s32 render_sprite_billboard(Gfx **dList, Mtx **mtx, Vertex **vertexList, Object *obj, Sprite *arg4, s32 flags); +s32 cam_push_model_mtx(Gfx **dList, Mtx **mtx, ObjectTransform *trans, f32 scaleY, f32 offsetY); void viewport_scissor(Gfx **dList); void apply_matrix_from_stack(Gfx **dList); void copy_viewports_to_stack(void); -void apply_head_turning_matrix(Gfx **dList, MatrixS **mtx, Object_68 *objGfx, s16 headAngle); -void apply_object_shear_matrix(Gfx **dList, MatrixS **mtx, Object *arg2, Object *arg3, f32 shear); +void apply_head_turning_matrix(Gfx **dList, Mtx **mtx, Object_68 *objGfx, s16 headAngle); +void apply_object_shear_matrix(Gfx **dList, Mtx **mtx, Object *arg2, Object *arg3, f32 shear); void cam_init(void); -void viewport_main(Gfx **dlist, MatrixS **mats); +void viewport_main(Gfx **dlist, Mtx **mats); #endif diff --git a/src/fade_transition.c b/src/fade_transition.c index ae3f2d5f..f2d3ec9e 100644 --- a/src/fade_transition.c +++ b/src/fade_transition.c @@ -322,7 +322,7 @@ s32 transition_update(s32 updateRate) { * The rendering portion of transitions. * First establishes an orthogonal matrix, then renders a transition effect onscreen. */ -void transition_render(Gfx **dList, MatrixS **mtx, Vertex **vtx) { +void transition_render(Gfx **dList, Mtx **mtx, Vertex **vtx) { if (sTransitionStatus != TRANSITION_NONE) { if (osTvType == OS_TV_TYPE_PAL) { set_ortho_matrix_height(1.4f); @@ -436,7 +436,7 @@ void transition_update_fullscreen(s32 updateRate) { /** * Draws a simple fillrect covering the whole screen that fades in or out. */ -void transition_render_fullscreen(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_fullscreen(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { s32 screenSize = fb_size(); gSPDisplayList((*dList)++, dTransitionFadeSettings); gDPSetPrimColor((*dList)++, 0, 0, gCurFadeRed, gCurFadeGreen, gCurFadeBlue, gCurFadeAlpha); @@ -564,11 +564,11 @@ void transition_update_shape(s32 updateRate) { /** * Renders a transition effect on screen that will close in from both sides horizonally. */ -void transition_render_barndoor_hor(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_barndoor_hor(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { rendermode_reset(dList); gSPDisplayList((*dList)++, dTransitionShapeSettings); - gSPVertexDKR((*dList)++, OS_PHYSICAL_TO_K0(sTransitionVtx[sTransitionTaskNum]), 12, 0); - gSPPolygon((*dList)++, OS_PHYSICAL_TO_K0(sTransitionTris[sTransitionTaskNum]), 8, TRIN_DISABLE_TEXTURE); + gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(sTransitionVtx[sTransitionTaskNum]), 12, 0); + gSPPolygon((*dList)++, OS_K0_TO_PHYSICAL(sTransitionTris[sTransitionTaskNum]), 8, TRIN_DISABLE_TEXTURE); rendermode_reset(dList); } @@ -576,11 +576,11 @@ void transition_render_barndoor_hor(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Ve * Renders a transition effect on screen that will close in from both sides vertically. * Codewise, exactly the same as above, but uses a different vertex layout to make the difference. */ -void transition_render_barndoor_vert(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_barndoor_vert(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { rendermode_reset(dList); gSPDisplayList((*dList)++, dTransitionShapeSettings); - gSPVertexDKR((*dList)++, OS_PHYSICAL_TO_K0(sTransitionVtx[sTransitionTaskNum]), 12, 0); - gSPPolygon((*dList)++, OS_PHYSICAL_TO_K0(sTransitionTris[sTransitionTaskNum]), 8, TRIN_DISABLE_TEXTURE); + gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(sTransitionVtx[sTransitionTaskNum]), 12, 0); + gSPPolygon((*dList)++, OS_K0_TO_PHYSICAL(sTransitionTris[sTransitionTaskNum]), 8, TRIN_DISABLE_TEXTURE); rendermode_reset(dList); } @@ -744,7 +744,7 @@ void transition_update_circle(s32 updateRate) { /** * Render a circle shape transition onscreen using previously allocated geometry. */ -void transition_render_circle(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_circle(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { Vertex *vertsToRender; Triangle *trisToRender; Gfx *gfx; @@ -758,8 +758,8 @@ void transition_render_circle(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex * gSPDisplayList(gfx++, dTransitionShapeSettings); for (i = 0; i < 4; i++) { - gSPVertexDKR(gfx++, OS_PHYSICAL_TO_K0(vertsToRender), NUM_OF_VERTS, 0); - gSPPolygon(gfx++, OS_PHYSICAL_TO_K0(trisToRender), NUM_OF_TRIS, TRIN_DISABLE_TEXTURE); + gSPVertexDKR(gfx++, OS_K0_TO_PHYSICAL(vertsToRender), NUM_OF_VERTS, 0); + gSPPolygon(gfx++, OS_K0_TO_PHYSICAL(trisToRender), NUM_OF_TRIS, TRIN_DISABLE_TEXTURE); vertsToRender += NUM_OF_VERTS; trisToRender += NUM_OF_TRIS; } @@ -771,7 +771,7 @@ void transition_render_circle(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex * /** * Render the wavy transition onscreen using the vertex data allocated earlier. */ -void transition_render_waves(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_waves(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { Gfx *gfx; s32 i; Vertex *v; @@ -791,13 +791,13 @@ void transition_render_waves(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex ** */ for (i = 0; i < 6; i++) { if (i == 1 || i == 4) { // Is middle third? - gSPVertexDKR(gfx++, OS_PHYSICAL_TO_K0(v), 14, 0); - gSPPolygon(gfx++, OS_PHYSICAL_TO_K0(t), 12, TRIN_DISABLE_TEXTURE); + gSPVertexDKR(gfx++, OS_K0_TO_PHYSICAL(v), 14, 0); + gSPPolygon(gfx++, OS_K0_TO_PHYSICAL(t), 12, TRIN_DISABLE_TEXTURE); v += 14; t += 12; } else { - gSPVertexDKR(gfx++, OS_PHYSICAL_TO_K0(v), 16, 0); - gSPPolygon(gfx++, OS_PHYSICAL_TO_K0(t), 14, TRIN_DISABLE_TEXTURE); + gSPVertexDKR(gfx++, OS_K0_TO_PHYSICAL(v), 16, 0); + gSPPolygon(gfx++, OS_K0_TO_PHYSICAL(t), 14, TRIN_DISABLE_TEXTURE); v += 16; t += 14; } @@ -809,11 +809,11 @@ void transition_render_waves(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex ** /** * Renders a transition effect on screen that will close in from the opposite corners of the screen. */ -void transition_render_barndoor_diag(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_barndoor_diag(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { rendermode_reset(dList); gSPDisplayList((*dList)++, dTransitionShapeSettings); - gSPVertexDKR((*dList)++, OS_PHYSICAL_TO_K0(sTransitionVtx[sTransitionTaskNum]), 10, 0); - gSPPolygon((*dList)++, OS_PHYSICAL_TO_K0(sTransitionTris[sTransitionTaskNum]), 6, TRIN_DISABLE_TEXTURE); + gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(sTransitionVtx[sTransitionTaskNum]), 10, 0); + gSPPolygon((*dList)++, OS_K0_TO_PHYSICAL(sTransitionTris[sTransitionTaskNum]), 6, TRIN_DISABLE_TEXTURE); rendermode_reset(dList); } @@ -867,7 +867,7 @@ void transition_update_blank(s32 updateRate) { /** * Fill the whole screen with a solid colour. */ -void transition_render_blank(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { +void transition_render_blank(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx) { s32 screenSize = fb_size(); gSPDisplayList((*dList)++, dTransitionFadeSettings); gDPSetPrimColor((*dList)++, 0, 0, (gLastFadeRed >> 16), (gLastFadeGreen >> 16), (gLastFadeBlue >> 16), 255); diff --git a/src/fade_transition.h b/src/fade_transition.h index 5e13883a..87501416 100644 --- a/src/fade_transition.h +++ b/src/fade_transition.h @@ -54,23 +54,23 @@ void disable_new_screen_transitions(void); u32 check_fadeout_transition(void); void transition_end(void); s32 transition_update(s32 updateRate); -void transition_render(Gfx **dList, MatrixS **mtx, Vertex **vtx); -void transition_render_fullscreen(Gfx **dList, MatrixS **mtx, Vertex **vtx); -void transition_render_barndoor_hor(Gfx **dList, MatrixS **mtx, Vertex **vtx); -void transition_render_barndoor_vert(Gfx **dList, MatrixS **mtx, Vertex **vtx); -void transition_render_barndoor_diag(Gfx **dList, MatrixS **mtx, Vertex **vtx); -void transition_render_blank(Gfx **dList, MatrixS **mtx, Vertex **vtx); +void transition_render(Gfx **dList, Mtx **mtx, Vertex **vtx); +void transition_render_fullscreen(Gfx **dList, Mtx **mtx, Vertex **vtx); +void transition_render_barndoor_hor(Gfx **dList, Mtx **mtx, Vertex **vtx); +void transition_render_barndoor_vert(Gfx **dList, Mtx **mtx, Vertex **vtx); +void transition_render_barndoor_diag(Gfx **dList, Mtx **mtx, Vertex **vtx); +void transition_render_blank(Gfx **dList, Mtx **mtx, Vertex **vtx); void transition_fullscreen_start(FadeTransition *transition); void transition_init_blank(FadeTransition *transition); void transition_update_fullscreen(s32 updateRate); void transition_update_blank(s32 updateRate); s32 transition_begin(FadeTransition *transition); -void transition_render_circle(Gfx **dList, MatrixS **mtx, Vertex **vtx); +void transition_render_circle(Gfx **dList, Mtx **mtx, Vertex **vtx); void transition_update_shape(s32 updateRate); void transition_init_shape(FadeTransition *transition, s32 numVerts, s32 numTris, s16 *coords, u8 *nextPos, u8 *targetPos, u8 *nextAlpha, u8 *targetAlpha, u8 *vertIndices); void transition_update_circle(s32 updateRate); -void transition_render_waves(Gfx **dList, UNUSED MatrixS **mtx, UNUSED Vertex **vtx); +void transition_render_waves(Gfx **dList, UNUSED Mtx **mtx, UNUSED Vertex **vtx); void transition_init_circle(FadeTransition *transition); #endif diff --git a/src/font.c b/src/font.c index 1dc9d8b4..5e996df9 100644 --- a/src/font.c +++ b/src/font.c @@ -466,7 +466,7 @@ void render_text_string(Gfx **dList, DialogueBoxBackground *box, char *text, Ali if (lastTextureIndex != textureIndex) { lastTextureIndex = textureIndex; texture = fontData->texturePointers[textureIndex]; - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(texture->cmd), texture->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(texture->cmd), texture->numberOfCommands); } textureWidth = fontData->letter[curChar].width; textureHeight = fontData->letter[curChar].height; @@ -1120,7 +1120,7 @@ void clear_dialogue_box_open_flag(s32 dialogueBoxID) { * when the player exits out of one. * Official Name: fontWindowsDraw */ -void render_dialogue_boxes(Gfx **dList, MatrixS **mat, Vertex **verts) { +void render_dialogue_boxes(Gfx **dList, Mtx **mat, Vertex **verts) { s32 i; if (sDialogueBoxIsOpen) { @@ -1210,7 +1210,7 @@ void render_fill_rectangle(Gfx **dList, s32 ulx, s32 uly, s32 lrx, s32 lry) { * Render the selected dialogue box. Background first, then text. * Official Name: fontWindowDraw */ -void render_dialogue_box(Gfx **dList, MatrixS **mat, Vertex **verts, s32 dialogueBoxID) { +void render_dialogue_box(Gfx **dList, Mtx **mat, Vertex **verts, s32 dialogueBoxID) { DialogueBoxBackground *dialogueBox; DialogueBox *dialogueTextBox; s32 i; @@ -1501,7 +1501,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { } if (asset->unk4 != NULL) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt @@ -1510,7 +1510,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD, // shifts G_TX_NOLOD); // shiftt - gDPLoadMultiBlock_4bS(dList++, OS_PHYSICAL_TO_K0(asset->unk4), 0x100, 1, G_IM_FMT_I, width, height, + gDPLoadMultiBlock_4bS(dList++, OS_K0_TO_PHYSICAL(asset->unk4), 0x100, 1, G_IM_FMT_I, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt @@ -1524,7 +1524,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { } else { switch (asset->unk8) { case 0: // RGBA32 - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms @@ -1535,7 +1535,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD); // shiftt break; case 1: // RGBA16 - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms @@ -1546,7 +1546,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD); // shiftt break; case 5: // IA8 - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt @@ -1556,7 +1556,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD); // shiftt break; case 6: // IA4 - gDPLoadTextureBlock_4bS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_IA, width, height, + gDPLoadTextureBlock_4bS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_IA, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt @@ -1566,7 +1566,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD); // shiftt break; case 3: // I4 - gDPLoadTextureBlock_4bS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_I, width, height, + gDPLoadTextureBlock_4bS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_I, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt @@ -1576,7 +1576,7 @@ void fontCreateDisplayList(Gfx *dList, Asset46 *asset, s32 width, s32 height) { G_TX_NOLOD); // shiftt break; case 2: // I8 - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(asset->unk0), G_IM_FMT_I, G_IM_SIZ_8b, width, height, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(asset->unk0), G_IM_FMT_I, G_IM_SIZ_8b, width, height, 0, // palette G_TX_NOMIRROR | G_TX_WRAP, // cms G_TX_NOMIRROR | G_TX_WRAP, // cmt diff --git a/src/font.h b/src/font.h index 25faa594..1697f66a 100644 --- a/src/font.h +++ b/src/font.h @@ -175,9 +175,9 @@ void dialogue_clear(s32 dialogueBoxID); void open_dialogue_box(s32 dialogueBoxID); void dialogue_close(s32 dialogueBoxID); void clear_dialogue_box_open_flag(s32 dialogueBoxID); -void render_dialogue_boxes(Gfx **dList, MatrixS **mat, Vertex **verts); +void render_dialogue_boxes(Gfx **dList, Mtx **mat, Vertex **verts); void render_fill_rectangle(Gfx **dList, s32 ulx, s32 uly, s32 lrx, s32 lry); -void render_dialogue_box(Gfx **dList, MatrixS **mat, Vertex **verts, s32 dialogueBoxID); +void render_dialogue_box(Gfx **dList, Mtx **mat, Vertex **verts, s32 dialogueBoxID); void parse_string_with_number(char *input, char *output, s32 number); void s32_to_string(char **outString, s32 number); void load_font(s32 fontID); diff --git a/src/game_ui.c b/src/game_ui.c index b415416e..4c13623a 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -255,7 +255,7 @@ s16 *gAssetHudElementIds; HudElements *gAssetHudElements; s32 gAssetHudElementIdsCount; Gfx *gHudDL; -MatrixS *gHudMtx; +Mtx *gHudMtx; Vertex *gHudVtx; s32 gHudCurrentViewport; s32 gHUDNumPlayers; @@ -426,7 +426,7 @@ void hud_init_element(void) { gHudPALScale = FALSE; gAdventurePlayerFinish = FALSE; D_80126D4C = -100; - D_80126D50 = get_random_number_from_range(120, 360); + D_80126D50 = rand_range(120, 360); D_8012718A = func_8000E158(); gStopwatchErrorX = 55; gStopwatchErrorY = 179; @@ -672,7 +672,7 @@ u8 race_starting(void) { * Root function for the HUD updating and rendering for individual players. * The player can toggle specific overrides and settings for displays based on their current game modes. */ -void hud_render_player(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s32 updateRate) { +void hud_render_player(Gfx **dList, Mtx **mtx, Vertex **vertexList, Object *obj, s32 updateRate) { s32 countdown; Object_Racer *racer; @@ -1612,9 +1612,9 @@ void hud_main_time_trial(s32 arg0, Object *playerRacerObj, s32 updateRate) { if ((D_80126D4C == 0) && (!curRacer->raceFinished)) { D_80126D4C = -100; if (gHUDVoiceSoundMask == 0) { - soundID = get_random_number_from_range(0, D_80126D64 + 2) + SOUND_VOICE_TT_OH_NO; + soundID = rand_range(0, D_80126D64 + 2) + SOUND_VOICE_TT_OH_NO; while (soundID == gHudTTSoundID) { - soundID = get_random_number_from_range(0, D_80126D64 + 2) + SOUND_VOICE_TT_OH_NO; + soundID = rand_range(0, D_80126D64 + 2) + SOUND_VOICE_TT_OH_NO; } gHudTTSoundID = soundID; sound_play(soundID, &gHUDVoiceSoundMask); @@ -1649,13 +1649,13 @@ void hud_main_time_trial(s32 arg0, Object *playerRacerObj, s32 updateRate) { posZ = ttSWBodyObject->segment.trans.z_position - playerRacerObj->segment.trans.z_position; if ((sqrtf((posX * posX) + (posY * posY) + (posZ * posZ)) < 600.0f) && (gHUDVoiceSoundMask == 0) && (D_80126D50 == 0)) { - soundID = SOUND_VOICE_TT_GO_FOR_IT + get_random_number_from_range(0, 2); + soundID = SOUND_VOICE_TT_GO_FOR_IT + rand_range(0, 2); while (soundID == gHudTTSoundID) { - soundID = SOUND_VOICE_TT_GO_FOR_IT + get_random_number_from_range(0, 2); + soundID = SOUND_VOICE_TT_GO_FOR_IT + rand_range(0, 2); } gHudTTSoundID = soundID; sound_play(soundID, &gHUDVoiceSoundMask); - D_80126D50 = get_random_number_from_range(120, 1200); + D_80126D50 = rand_range(120, 1200); } D_80126D50 -= updateRate; if (D_80126D50 < 0) { @@ -1915,16 +1915,15 @@ void hud_race_start(s32 countdown, s32 updateRate) { Object_Racer *racer; s32 numRacerObjects; racerGroup = get_racer_objects(&numRacerObjects); - randomRacer = racerGroup[get_random_number_from_range(1, numRacerObjects) - 1]; + randomRacer = racerGroup[rand_range(1, numRacerObjects) - 1]; racer = &randomRacer->unk64->racer; if (racer->vehicleID == VEHICLE_CAR) { - if (get_random_number_from_range(0, 100) >= 96) { - frequency = 1.25 - ((get_random_number_from_range(0, 7) * 0.5) / 7.0); + if (rand_range(0, 100) >= 96) { + frequency = 1.25 - ((rand_range(0, 7) * 0.5) / 7.0); audspat_play_sound_direct( 76, randomRacer->segment.trans.x_position, randomRacer->segment.trans.y_position, randomRacer->segment.trans.z_position, AUDIO_POINT_FLAG_ONE_TIME_TRIGGER, - ((get_random_number_from_range(0, 7) * 63) / 7) + 24, frequency * 100.0f, - &gRaceStartSoundMask); + ((rand_range(0, 7) * 63) / 7) + 24, frequency * 100.0f, &gRaceStartSoundMask); } } } @@ -2457,10 +2456,10 @@ void hud_wrong_way(Object_Racer *obj, s32 updateRate) { !is_game_paused()) { if ((gWrongWayNagPrefix || gWrongWayNagTimer == 0) && gHUDVoiceSoundMask == NULL) { // 20% chance that T.T decides not to precede his nagging with "No no no!" - if (gWrongWayNagPrefix || get_random_number_from_range(1, 10) >= 8) { + if (gWrongWayNagPrefix || rand_range(1, 10) >= 8) { gWrongWayNagPrefix = FALSE; sound_play(SOUND_VOICE_TT_WRONG_WAY, &gHUDVoiceSoundMask); - gWrongWayNagTimer = get_random_number_from_range(1, 480) + 120; + gWrongWayNagTimer = rand_range(1, 480) + 120; } else { gWrongWayNagPrefix = TRUE; sound_play(SOUND_VOICE_TT_NONONO, &gHUDVoiceSoundMask); @@ -3316,7 +3315,7 @@ s8 hud_setting(void) { * Renders HUD elements concerning all players. * This includes the minimap and score counters for challenge modes. */ -void hud_render_general(Gfx **dList, MatrixS **mtx, Vertex **vtx, s32 updateRate) { +void hud_render_general(Gfx **dList, Mtx **mtx, Vertex **vtx, s32 updateRate) { Object_Racer *curRacerObj; LevelModel *lvlMdl; Sprite *minimap; @@ -3811,7 +3810,7 @@ void minimap_marker_pos(f32 x, f32 z, f32 angleSin, f32 angleCos, f32 modelAspec * Since hud elements can be all sorts of things, the function checks what asset type it is, before * deciding to draw a texture rectangle, ortho tris, or a 3D model entirely. */ -void hud_element_render(Gfx **dList, MatrixS **mtx, Vertex **vtxList, HudElement *hud) { +void hud_element_render(Gfx **dList, Mtx **mtx, Vertex **vtxList, HudElement *hud) { TextureHeader **textureHeader3; TextureHeader *textureHeader2; TextureHeader *textureHeader; @@ -4029,11 +4028,11 @@ void hud_draw_model(ObjectModel *objModel) { texPtr = objModel->textures[texIndex].texture; } material_set_no_tex_offset(&gHudDL, texPtr, flags & ~RENDER_Z_COMPARE); - gSPVertexDKR(gHudDL++, OS_PHYSICAL_TO_K0(verts), numVerts, 0); + gSPVertexDKR(gHudDL++, OS_K0_TO_PHYSICAL(verts), numVerts, 0); if (texPtr == NULL) { textureEnabled = TRIN_DISABLE_TEXTURE; } - gSPPolygon(gHudDL++, OS_PHYSICAL_TO_K0(tris), numTris, textureEnabled); + gSPPolygon(gHudDL++, OS_K0_TO_PHYSICAL(tris), numTris, textureEnabled); numBatches = objModel->numberOfBatches; } } diff --git a/src/game_ui.h b/src/game_ui.h index 1a3c5a4b..bf11bf52 100644 --- a/src/game_ui.h +++ b/src/game_ui.h @@ -420,14 +420,14 @@ void hud_race_time(Object_Racer *racer, s32 updateRate); void hud_wrong_way(Object_Racer *obj, s32 updateRate); void hud_course_arrows(Object_Racer *racer, s32 updateRate); void hud_main_hub(Object *obj, s32 updateRate); -void hud_render_player(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s32 updateRate); +void hud_render_player(Gfx **dList, Mtx **mtx, Vertex **vertexList, Object *obj, s32 updateRate); void hud_weapon(Object *obj, s32 updateRate); void hud_race_start(s32 countdown, s32 updateRate); void hud_bananas(Object_Racer *racer, s32 updateRate); void hud_race_finish_1player(Object_Racer *racer, s32 updateRate); void hud_speedometre(Object *obj, s32 updateRate); void hud_lap_count(Object_Racer *racer, s32 updateRate); -void hud_render_general(Gfx **dList, MatrixS **mtx, Vertex **vtx, s32 updateRate); +void hud_render_general(Gfx **dList, Mtx **mtx, Vertex **vtx, s32 updateRate); void hud_init(s32 viewportCount); void hud_main_battle(s32 countdown, Object *obj, s32 updateRate); void hud_lives_render(Object_Racer *racer, s32 updateRate); @@ -446,7 +446,7 @@ void hud_treasure(Object_Racer *racer); void minimap_marker_pos(f32 x, f32 z, f32 angleSin, f32 angleCos, f32 modelAspectRatio); void hud_timer_render(s32 x, s32 y, s32 minutes, s32 seconds, s32 hundredths, s32 smallFont); void hud_draw_model(ObjectModel *objModel); -void hud_element_render(Gfx **dList, MatrixS **mtx, Vertex **vtxList, HudElement *hud); +void hud_element_render(Gfx **dList, Mtx **mtx, Vertex **vtxList, HudElement *hud); void hud_main_time_trial(s32, Object*, s32); void hud_race_finish_multiplayer(Object_Racer *racer, s32 updateRate); void func_800A1E48(Object*, s32 updateRate); diff --git a/src/hasm/math_util.c b/src/hasm/math_util.c index 3cb32daf..9c63e3f0 100644 --- a/src/hasm/math_util.c +++ b/src/hasm/math_util.c @@ -72,101 +72,131 @@ s8 get_gIntDisFlag(void) { GLOBAL_ASM("asm/math_util/get_gIntDisFlag.s") #endif -#ifdef NON_EQUIVALENT // Untested -UNUSED void s32_matrix_to_s16_matrix(s32 **input, s16 **output) { - s32 i; +/** + * Converts a Mtx (fixed-point matrix with split integer and fractional parts) + * into a 4×4 matrix of 32-bit signed integers, where each element is in 16.16 fixed-point format. + */ +#ifdef NON_MATCHING +UNUSED void mtx_to_mtxs(Mtx *m, MtxS *mi) { + s32 i, j; + s32 ei, ef; + s32 *ai, *af; + + ai = &m->m[0][0]; + af = &m->m[2][0]; + for (i = 0; i < 4; i++) { - output[i][2] = input[i][0]; - output[i][3] = input[i + 4][0]; - output[i][6] = input[i][1]; - output[i][7] = input[i + 4][1]; - output[i][0] = input[i][0] >> 16; - output[i][1] = input[i + 4][0] >> 16; - output[i][4] = input[i][1] >> 16; - output[i][5] = input[i + 4][1] >> 16; + for (j = 0; j < 4; j += 2) { + ei = *ai++; + ef = *af++; + (*mi)[i][j] = (ei & 0xFFFF0000) | ((ef >> 16) & 0xFFFF); + (*mi)[i][j + 1] = ((ei & 0xFFFF) << 16) | (ef & 0xFFFF); + } } } #else -GLOBAL_ASM("asm/math_util/s32_matrix_to_s16_matrix.s") +GLOBAL_ASM("asm/math_util/mtx_to_mtxs.s") #endif +/** + * Converts a 4×4 matrix of 32-bit floating-point values into a 4×4 matrix + * of 32-bit signed fixed-point values in 16.16 format. + */ #ifdef NON_MATCHING -void f32_matrix_to_s32_matrix(Matrix *input, MatrixS *output) { - s32 i; +void mtxf_to_mtxs(MtxF *mf, MtxS *mi) { + s32 i, j; + for (i = 0; i < 4; i++) { - (*output)[i][0] = (s32) ((*input)[i][0] * 65536.0f); - (*output)[i][1] = (s32) ((*input)[i][1] * 65536.0f); - (*output)[i][2] = (s32) ((*input)[i][2] * 65536.0f); - (*output)[i][3] = (s32) ((*input)[i][3] * 65536.0f); + for (j = 0; j < 4; j++) { + (*mi)[i][j] = FTOFIX32((*mf)[i][j]); + } } } #else -GLOBAL_ASM("asm/math_util/f32_matrix_to_s32_matrix.s") +GLOBAL_ASM("asm/math_util/mtxf_to_mtxs.s") #endif #ifdef NON_MATCHING +/** + * Transforms a 3D vector using a 4×4 transformation matrix. + */ /* Official name: mathMtxXFMF */ -void guMtxXFMF(Matrix mf, float x, float y, float z, float *ox, float *oy, float *oz) { - *ox = mf[0][0] * x + mf[1][0] * y + mf[2][0] * z + mf[3][0]; - *oy = mf[0][1] * x + mf[1][1] * y + mf[2][1] * z + mf[3][1]; - *oz = mf[0][2] * x + mf[1][2] * y + mf[2][2] * z + mf[3][2]; +void mtxf_transform_point(MtxF *mf, float x, float y, float z, float *ox, float *oy, float *oz) { + *ox = (*mf)[0][0] * x + (*mf)[1][0] * y + (*mf)[2][0] * z + (*mf)[3][0]; + *oy = (*mf)[0][1] * x + (*mf)[1][1] * y + (*mf)[2][1] * z + (*mf)[3][1]; + *oz = (*mf)[0][2] * x + (*mf)[1][2] * y + (*mf)[2][2] * z + (*mf)[3][2]; } #else -GLOBAL_ASM("asm/math_util/guMtxXFMF.s") +GLOBAL_ASM("asm/math_util/mtxf_transform_point.s") #endif #ifdef NON_MATCHING +/** + * Transforms a direction vector in 3D space using the rotation part of a 4×4 matrix. + * This function multiplies the input vector by the upper-left 3×3 portion of the matrix mf, + * ignoring the translation component. It is used for transforming directions, such as normals, + * rather than points. + */ /* Official name: mathMtxFastXFMF */ -void f32_matrix_dot(Matrix *mat1, Matrix *mat2, Matrix *output) { - f32 temp_f4; - f32 temp_f6; - f32 temp_f8; - - temp_f4 = (*mat2)[0][0]; - temp_f6 = (*mat2)[0][1]; - temp_f8 = (*mat2)[0][2]; - (*output)[0][0] = (temp_f4 * (*mat1)[0][0]) + (temp_f6 * (*mat1)[1][0]) + (temp_f8 * (*mat1)[2][0]); - (*output)[0][1] = (temp_f4 * (*mat1)[0][1]) + (temp_f6 * (*mat1)[1][1]) + (temp_f8 * (*mat1)[2][1]); - (*output)[0][2] = (temp_f4 * (*mat1)[0][2]) + (temp_f6 * (*mat1)[1][2]) + (temp_f8 * (*mat1)[2][2]); +void mtxf_transform_dir(MtxF *mf, Vec3f *in, Vec3f *out) { + out->f[0] = (in->f[0] * mf[0][0]) + (in->f[1] * mf[1][0]) + (in->f[2] * mf[2][0]); + out->f[1] = (in->f[0] * mf[0][1]) + (in->f[1] * mf[1][1]) + (in->f[2] * mf[2][1]); + out->f[2] = (in->f[0] * mf[0][2]) + (in->f[1] * mf[1][2]) + (in->f[2] * mf[2][2]); } #else -GLOBAL_ASM("asm/math_util/f32_matrix_dot.s") +GLOBAL_ASM("asm/math_util/mtxf_transform_dir.s") #endif #ifdef NON_MATCHING +/** + * Multiplies two 4×4 matrices. + */ /* Official name: mathMtxCatF */ -void f32_matrix_mult(Matrix *mat1, Matrix *mat2, Matrix *output) { - s32 i; - f32 x; - f32 y; - f32 z; - f32 w; +void mtxf_mul(MtxF *mat1, MtxF *mat2, MtxF *output) { + s32 i, j, k; + for (i = 0; i < 4; i++) { - x = (*mat1)[i][0]; - y = (*mat1)[i][1]; - z = (*mat1)[i][2]; - w = (*mat1)[i][3]; - (*output)[i][0] = - (f32) ((y * (*mat2)[1][0]) + (z * (*mat2)[2][0]) + ((x * (*mat2)[0][0]) + (w * (*mat2)[3][0]))); - (*output)[i][1] = - (f32) ((y * (*mat2)[1][1]) + (z * (*mat2)[2][1]) + ((x * (*mat2)[0][1]) + (w * (*mat2)[3][1]))); - (*output)[i][2] = - (f32) ((y * (*mat2)[1][2]) + (z * (*mat2)[2][2]) + ((x * (*mat2)[0][2]) + (w * (*mat2)[3][2]))); - (*output)[i][3] = - (f32) ((y * (*mat2)[1][3]) + (z * (*mat2)[2][3]) + ((x * (*mat2)[0][3]) + (w * (*mat2)[3][3]))); + for (j = 0; j < 4; j++) { + /* + (*output)[i][j] = 0.0f; + for (k = 0; k < 4; k++) { + (*output)[i][j] += (*mat1)[i][k] * (*mat2)[k][j]; + } + */ + // Reordered addition to preserve exact bitwise result + (*output)[i][j] = ((*mat1)[i][1] * (*mat2)[1][j] + (*mat1)[i][2] * (*mat2)[2][j]) + + ((*mat1)[i][0] * (*mat2)[0][j] + (*mat1)[i][3] * (*mat2)[3][j]); + } } } #else -GLOBAL_ASM("asm/math_util/f32_matrix_mult.s") +GLOBAL_ASM("asm/math_util/mtxf_mul.s") #endif #ifdef NON_MATCHING +/** + * Converts a floating-point 4×4 matrix to a Mtx fixed-point matrix. + */ /* Official name: mathMtxF2L */ -void f32_matrix_to_s16_matrix(Matrix *input, MatrixS *output) { - guMtxF2L((float(*)[4]) input, (Mtx *) output); +void mtxf_to_mtx(MtxF *mf, Mtx *m) { + s32 i, j; + s32 e1, e2; + s32 *ai, *af; + + ai = &m->m[0][0]; + af = &m->m[2][0]; + + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j += 2) { + e1 = FTOFIX32((*mf)[i][j]); + e2 = FTOFIX32((*mf)[i][j + 1]); + *ai++ = (e1 & 0xFFFF0000) | ((e2 >> 16) & 0xFFFF); + *af++ = ((e1 << 16) & 0xFFFF0000) | (e2 & 0xFFFF); + } +} } #else -GLOBAL_ASM("asm/math_util/f32_matrix_to_s16_matrix.s") +GLOBAL_ASM("asm/math_util/mtxf_to_mtx.s") #endif /* Official Name: mathSeed */ @@ -176,8 +206,7 @@ void set_rng_seed(s32 num) { #ifdef NON_MATCHING void save_rng_seed(void) { - s32 num = gCurrentRNGSeed; - gPrevRNGSeed = num; + gPrevRNGSeed = gCurrentRNGSeed; } #else GLOBAL_ASM("asm/math_util/save_rng_seed.s") @@ -185,8 +214,7 @@ GLOBAL_ASM("asm/math_util/save_rng_seed.s") #ifdef NON_MATCHING void load_rng_seed(void) { - s32 num = gPrevRNGSeed; - gCurrentRNGSeed = num; + gCurrentRNGSeed = gPrevRNGSeed; } #else GLOBAL_ASM("asm/math_util/load_rng_seed.s") @@ -197,69 +225,101 @@ s32 get_rng_seed(void) { } #ifdef NON_MATCHING +/** + * Generates a random integer within the inclusive range [min, max]. + */ /* Official Name: mathRnd */ -s32 get_random_number_from_range(s32 min, s32 max) { - s32 newSeed; - u64 curSeed; +s32 rand_range(s32 min, s32 max) { + s64 temp = gCurrentRNGSeed; - curSeed = (((u64) ((s64) gCurrentRNGSeed << 0x3F) >> 0x1F) | ((u64) ((s64) gCurrentRNGSeed << 0x1F) >> 0x20)) ^ - ((u64) ((s64) gCurrentRNGSeed << 0x2C) >> 0x20); - newSeed = ((curSeed >> 0x14) & 0xFFF) ^ curSeed; - gCurrentRNGSeed = newSeed; - return ((u32) (newSeed - min) % (u32) ((max - min) + 1)) + min; + temp = (temp << 32) | (temp >> 1); + temp = temp ^ ((gCurrentRNGSeed & 0xFFFFF) << 12); + gCurrentRNGSeed = temp ^ ((temp >> 20) & 0xFFF); + + return (u32) (gCurrentRNGSeed - min) % (max - min + 1) + min; } #else GLOBAL_ASM("asm/math_util/rng.s") #endif -#ifdef NON_EQUIVALENT +#ifdef NON_MATCHING +/** + * Reflects a vector across a given normal, such that the sum of the input and output vectors + * lies in the direction of the normal (i.e. symmetric reflection). + * + * The normal vector must be normalized and represented in 3.13 fixed-point format (signed 16-bit, + * with 13 fractional bits). + * + */ /* Official name: fastShortReflection */ -// name and code are incorrect -void s16_matrix_rotate(Vec3s *arg0, Vec3s *arg1) { - // TODO -} -#else -GLOBAL_ASM("asm/math_util/s16_matrix_rotate.s") -#endif +void vec3s_reflect(Vec3s *vec, Vec3s *n) { + s32 proj_x2 = (vec->x * n->x + vec->y * n->y + vec->z * n->z) >> 12; -#ifdef NON_EQUIVALENT // Untested -UNUSED void s16_matrix_to_s32_matrix(s16 **arg0, s32 **arg1) { - s32 i, j; - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - arg1[i][j] = (arg0[i][j] << 16) | arg0[i + 4][j]; - } - } + vec[1].x = ((proj_x2 * n->x) >> 13) - vec->x; + vec[1].y = ((proj_x2 * n->y) >> 13) - vec->y; + vec[1].z = ((proj_x2 * n->z) >> 13) - vec->x; //!@bug: should be vec->z } #else -GLOBAL_ASM("asm/math_util/s16_matrix_to_s32_matrix.s") -#endif - -#ifdef NON_EQUIVALENT // Untested -UNUSED void s16_vec3_mult_by_s32_matrix_full(s32 **input, s16 *output) { - output[0] = ((output[0] * input[0][0]) + (output[1] * input[1][0]) + (output[2] * input[2][0]) + input[3][0]) >> 16; - output[1] = ((output[0] * input[0][1]) + (output[1] * input[1][1]) + (output[2] * input[2][1]) + input[3][1]) >> 16; - output[2] = ((output[0] * input[0][2]) + (output[1] * input[1][2]) + (output[2] * input[2][2]) + input[3][2]) >> 16; -} -#else -GLOBAL_ASM("asm/math_util/s16_vec3_mult_by_s32_matrix_full.s") +GLOBAL_ASM("asm/math_util/vec3s_reflect.s") #endif #ifdef NON_MATCHING -void s16_vec3_mult_by_s32_matrix(MatrixS input, Vec3s *output) { - s32 x; - s32 y; - s32 z; +/** + * Converts an Mtx matrix (used by the RSP) into a 4x4 fixed-point matrix, + * where each element is in 16.16 fixed-point format. + */ +UNUSED void mtx_to_mtxs_2(Mtx *m, MtxS *mi) { + s16 *ai; + u16 *af; + s32 *ptr; + s32 i; - x = output->x; - y = output->y; - z = output->z; - output->x = ((x * input[0][0]) + (y * input[1][0]) + (z * input[2][0])) >> 16; - output->y = ((x * input[0][1]) + (y * input[1][1]) + (z * input[2][1])) >> 16; - output->z = ((x * input[0][2]) + (y * input[1][2]) + (z * input[2][2])) >> 16; + ai = (s16 *) &m->m[0][0]; + af = (u16 *) &m->m[2][0]; + ptr = (s32 *) &mi[0][0]; + + for (i = 0; i < 16; i++) { + *ptr++ = (*ai++ << 16) | (*af++); + } } #else -GLOBAL_ASM("asm/math_util/s16_vec3_mult_by_s32_matrix.s") +GLOBAL_ASM("asm/math_util/mtx_to_mtxs_2.s") +#endif + +#ifdef NON_MATCHING +/** + * Transforms a 3D short vector using a 4×4 fixed-point (16.16) matrix. + * The result is written back into the input vector. + */ +UNUSED void mtxs_transform_point(MtxS *mi, Vec3s *vec) { + s16 x = vec->x; + s16 y = vec->y; + s16 z = vec->z; + + vec->x = ((*mi)[0][0] * x + (*mi)[1][0] * y + (*mi)[2][0] * z + (*mi)[3][0]) >> 16; + vec->y = ((*mi)[0][1] * x + (*mi)[1][1] * y + (*mi)[2][1] * z + (*mi)[3][1]) >> 16; + vec->z = ((*mi)[0][2] * x + (*mi)[1][2] * y + (*mi)[2][2] * z + (*mi)[3][2]) >> 16; +} +#else +GLOBAL_ASM("asm/math_util/mtxs_transform_point.s") +#endif + +#ifdef NON_MATCHING +/** + * Transforms a direction vector in 3D space using a 4×4 fixed-point (16.16) matrix. + * The result is written back into the input vector. + */ +void mtxs_transform_dir(MtxS *mi, Vec3s *vec) { + s16 x = vec->x; + s16 y = vec->y; + s16 z = vec->z; + + vec->x = ((*mi)[0][0] * x + (*mi)[1][0] * y + (*mi)[2][0] * z) >> 16; + vec->y = ((*mi)[0][1] * x + (*mi)[1][1] * y + (*mi)[2][1] * z) >> 16; + vec->z = ((*mi)[0][2] * x + (*mi)[1][2] * y + (*mi)[2][2] * z) >> 16; +} +#else +GLOBAL_ASM("asm/math_util/mtxs_transform_dir.s") #endif #ifdef NON_MATCHING @@ -272,7 +332,7 @@ GLOBAL_ASM("asm/math_util/s16_vec3_mult_by_s32_matrix.s") * 4. Rotation around Y axis (yaw) * 5. Translation */ -void object_transform_to_matrix(Matrix mtx, ObjectTransform *trans) { +void mtxf_from_transform(MtxF *mtx, ObjectTransform *trans) { f32 yRotSine; f32 yRotCosine; f32 xRotSine; @@ -289,50 +349,60 @@ void object_transform_to_matrix(Matrix mtx, ObjectTransform *trans) { zRotCosine = coss_s16(trans->rotation.z_rotation) * (1.0f / 0x10000); scale = trans->scale; - mtx[0][0] = (xRotSine * yRotSine * zRotSine + zRotCosine * yRotCosine) * scale; - mtx[0][1] = (zRotSine * xRotCosine) * scale; - mtx[0][2] = (xRotSine * yRotCosine * zRotSine - zRotCosine * yRotSine) * scale; - mtx[0][3] = 0; - mtx[1][0] = (xRotSine * yRotSine * zRotCosine - zRotSine * yRotCosine) * scale; - mtx[1][1] = (zRotCosine * xRotCosine) * scale; - mtx[1][2] = (xRotSine * yRotCosine * zRotCosine + zRotSine * yRotSine) * scale; - mtx[1][3] = 0; - mtx[2][0] = (xRotCosine * yRotSine) * scale; - mtx[2][1] = -(xRotSine * scale); - mtx[2][2] = (xRotCosine * yRotCosine) * scale; - mtx[2][3] = 0; - mtx[3][0] = trans->x_position; - mtx[3][1] = trans->y_position; - mtx[3][2] = trans->z_position; - mtx[3][3] = 1.0f; + (*mtx)[0][0] = (xRotSine * yRotSine * zRotSine + zRotCosine * yRotCosine) * scale; + (*mtx)[0][1] = (zRotSine * xRotCosine) * scale; + (*mtx)[0][2] = (xRotSine * yRotCosine * zRotSine - zRotCosine * yRotSine) * scale; + (*mtx)[0][3] = 0; + (*mtx)[1][0] = (xRotSine * yRotSine * zRotCosine - zRotSine * yRotCosine) * scale; + (*mtx)[1][1] = (zRotCosine * xRotCosine) * scale; + (*mtx)[1][2] = (xRotSine * yRotCosine * zRotCosine + zRotSine * yRotSine) * scale; + (*mtx)[1][3] = 0; + (*mtx)[2][0] = (xRotCosine * yRotSine) * scale; + (*mtx)[2][1] = -(xRotSine * scale); + (*mtx)[2][2] = (xRotCosine * yRotCosine) * scale; + (*mtx)[2][3] = 0; + (*mtx)[3][0] = trans->x_position; + (*mtx)[3][1] = trans->y_position; + (*mtx)[3][2] = trans->z_position; + (*mtx)[3][3] = 1.0f; } #else -GLOBAL_ASM("asm/math_util/object_transform_to_matrix.s") +GLOBAL_ASM("asm/math_util/mtxf_from_transform.s") #endif #ifdef NON_MATCHING +/** + * Scales the Y axis of the given 4×4 transformation matrix by the specified factor. + * If this is a model matrix, the operation is equivalent to stretching or squashing + * the model along its local Y axis. + / /* Official name: mathSquashY */ -void f32_matrix_scale_y_axis(Matrix *input, f32 scale) { - input[0][1][0] *= scale; - input[0][1][1] *= scale; - input[0][1][2] *= scale; +void mtxf_scale_y(MtxF *input, f32 scale) { + (*input)[1][0] *= scale; + (*input)[1][1] *= scale; + (*input)[1][2] *= scale; } #else -GLOBAL_ASM("asm/math_util/f32_matrix_scale_y_axis.s") +GLOBAL_ASM("asm/math_util/mtxf_scale_y.s") #endif #ifdef NON_MATCHING +/** + * Modifies the matrix by translating its position along the local Y axis. + * If this is a model matrix, the operation is equivalent to moving the model + * along its local Y axis in model space. + */ /* Official name: mathTransY */ -void f32_matrix_translate_y_axis(Matrix *input, f32 offset) { - input[0][3][0] += input[0][1][0] * offset; - input[0][3][1] += input[0][1][1] * offset; - input[0][3][2] += input[0][1][2] * offset; +void mtxf_translate_y(MtxF *input, f32 offset) { + (*input)[3][0] += (*input)[1][0] * offset; + (*input)[3][1] += (*input)[1][1] * offset; + (*input)[3][2] += (*input)[1][2] * offset; } #else -GLOBAL_ASM("asm/math_util/f32_matrix_translate_y_axis.s") +GLOBAL_ASM("asm/math_util/mtxf_translate_y.s") #endif -#ifdef NON_EQUIVALENT +#ifdef NON_MATCHING /** * Writes an inverse transformation matrix to `mtx` based on a pre-inverted `ObjectTransform`. * This is used to convert world-space coordinates to local object-space coordinates. @@ -348,7 +418,7 @@ GLOBAL_ASM("asm/math_util/f32_matrix_translate_y_axis.s") * 4. Rotate Z (negative roll) */ /* Official Name: mathRpyXyzMtx */ -void object_inverse_transform_to_matrix(Matrix mtx, ObjectTransform *trans) { +void mtxf_from_inverse_transform(MtxF *mtx, ObjectTransform *trans) { f32 yRotSine; f32 yRotCosine; f32 xRotSine; @@ -363,270 +433,303 @@ void object_inverse_transform_to_matrix(Matrix mtx, ObjectTransform *trans) { zRotCosine = coss_s16(trans->rotation.z_rotation) * (1.0f / 0x10000); zRotSine = sins_s16(trans->rotation.z_rotation) * (1.0f / 0x10000); - mtx[0][0] = yRotCosine * zRotCosine - xRotSine * zRotSine * yRotSine; - mtx[0][1] = xRotSine * zRotCosine * yRotSine + yRotCosine * zRotSine; - mtx[0][2] = -(yRotSine * xRotCosine); - mtx[0][3] = 0; - mtx[1][0] = -(xRotCosine * zRotSine); - mtx[1][1] = xRotCosine * zRotCosine; - mtx[1][2] = xRotSine; - mtx[1][3] = 0; - mtx[2][0] = xRotSine * zRotSine * yRotCosine + yRotSine * zRotCosine; - mtx[2][1] = yRotSine * zRotSine - xRotSine * zRotCosine * yRotCosine; - mtx[2][2] = yRotCosine * xRotCosine; - mtx[2][3] = 0; - mtx[3][0] = (mtx[0][0] * trans->x_position) + (mtx[1][0] * trans->y_position) + (mtx[2][0] * trans->z_position); - mtx[3][1] = (mtx[0][1] * trans->x_position) + (mtx[1][1] * trans->y_position) + (mtx[2][1] * trans->z_position); - mtx[3][2] = (mtx[0][2] * trans->x_position) + (mtx[1][2] * trans->y_position) + (mtx[2][2] * trans->z_position); - mtx[3][3] = 1.0f; + (*mtx)[0][0] = yRotCosine * zRotCosine - xRotSine * zRotSine * yRotSine; + (*mtx)[0][1] = xRotSine * zRotCosine * yRotSine + yRotCosine * zRotSine; + (*mtx)[0][2] = -(yRotSine * xRotCosine); + (*mtx)[0][3] = 0; + (*mtx)[1][0] = -(xRotCosine * zRotSine); + (*mtx)[1][1] = xRotCosine * zRotCosine; + (*mtx)[1][2] = xRotSine; + (*mtx)[1][3] = 0; + (*mtx)[2][0] = xRotSine * zRotSine * yRotCosine + yRotSine * zRotCosine; + (*mtx)[2][1] = yRotSine * zRotSine - xRotSine * zRotCosine * yRotCosine; + (*mtx)[2][2] = yRotCosine * xRotCosine; + (*mtx)[2][3] = 0; + (*mtx)[3][0] = + ((*mtx)[0][0] * trans->x_position) + ((*mtx)[1][0] * trans->y_position) + ((*mtx)[2][0] * trans->z_position); + (*mtx)[3][1] = + ((*mtx)[0][1] * trans->x_position) + ((*mtx)[1][1] * trans->y_position) + ((*mtx)[2][1] * trans->z_position); + (*mtx)[3][2] = + ((*mtx)[0][2] * trans->x_position) + ((*mtx)[1][2] * trans->y_position) + ((*mtx)[2][2] * trans->z_position); + (*mtx)[3][3] = 1.0f; } #else -GLOBAL_ASM("asm/math_util/object_inverse_transform_to_matrix.s") +GLOBAL_ASM("asm/math_util/mtxf_from_inverse_transform.s") #endif GLOBAL_ASM("asm/math_util/func_80070058.s") #ifdef NON_MATCHING -void f32_matrix_from_rotation_and_scale(Matrix mtx, s32 angle, f32 scale, f32 scaleY) { +/** + * Builds a billboard matrix for a sprite that always faces the camera. + * + * The resulting 4×4 matrix applies a rotation around the Z axis (in the XY plane), + * followed by non-uniform scaling (uniform in X/Z and scaled by scaleY in Y). + * + * This is commonly used to render flat sprites that rotate to face the camera + * while preserving their upright orientation. + */ +void mtxf_billboard(MtxF *mtx, s32 angle, f32 scale, f32 scaleY) { f32 cosine, sine; sine = sins_s16(angle) * (1.0f / 0x10000); cosine = coss_s16(angle) * (1.0f / 0x10000); - mtx[0][0] = cosine * scale; - mtx[0][1] = sine * scale; - mtx[0][2] = 0; - mtx[0][3] = 0; - mtx[1][0] = -sine * scale; - mtx[1][1] = (cosine * scale) * scaleY; - mtx[1][2] = 0; - mtx[1][3] = 0; - mtx[2][0] = 0; - mtx[2][1] = 0; - mtx[2][2] = scale; - mtx[2][3] = 0; - mtx[3][0] = 0; - mtx[3][1] = 0; - mtx[3][2] = 0; - mtx[3][3] = 1.0f; + (*mtx)[0][0] = cosine * scale; + (*mtx)[0][1] = sine * scale; + (*mtx)[0][2] = 0; + (*mtx)[0][3] = 0; + (*mtx)[1][0] = -sine * scale; + (*mtx)[1][1] = (cosine * scale) * scaleY; + (*mtx)[1][2] = 0; + (*mtx)[1][3] = 0; + (*mtx)[2][0] = 0; + (*mtx)[2][1] = 0; + (*mtx)[2][2] = scale; + (*mtx)[2][3] = 0; + (*mtx)[3][0] = 0; + (*mtx)[3][1] = 0; + (*mtx)[3][2] = 0; + (*mtx)[3][3] = 1.0f; } #else -GLOBAL_ASM("asm/math_util/f32_matrix_from_rotation_and_scale.s") -#endif - -#ifdef NON_EQUIVALENT -void s16_vec3_apply_object_rotation(ObjectTransform *trans, s16 *vec3Arg) { - s32 yRotSine; - s32 yRotCosine; - s32 xRotSine; - s32 xRotCosine; - s32 zRotSine; - s32 zRotCosine; - s32 temp_t3; - s32 temp_t4; - s32 temp_t5; - - yRotCosine = coss_s16(trans->rotation.y_rotation); - yRotSine = sins_s16(trans->rotation.y_rotation); - xRotCosine = coss_s16(trans->rotation.x_rotation); - xRotSine = sins_s16(trans->rotation.x_rotation); - zRotCosine = coss_s16(trans->rotation.z_rotation); - zRotSine = sins_s16(trans->rotation.z_rotation); - - temp_t3 = ((vec3Arg[0] * yRotSine) - (vec3Arg[1] * yRotCosine)) >> 16; - temp_t4 = ((vec3Arg[1] * yRotSine) + (vec3Arg[0] * yRotCosine)) >> 16; - - temp_t4 = ((temp_t4 * xRotSine) - (vec3Arg[2] * xRotCosine)) >> 16; - temp_t5 = ((vec3Arg[2] * xRotSine) + (temp_t4 * xRotCosine)) >> 16; - - vec3Arg[1] = temp_t4; - - temp_t3 = ((temp_t3 * zRotSine) + (temp_t5 * zRotCosine)) >> 16; - temp_t5 = ((temp_t5 * zRotSine) - (temp_t3 * zRotCosine)) >> 16; - - vec3Arg[0] = temp_t3; - vec3Arg[2] = temp_t5; -} -#else -GLOBAL_ASM("asm/math_util/s16_vec3_apply_object_rotation.s") -#endif - -#ifdef NON_EQUIVALENT -/* Official Name: mathOneFloatRPY */ -void f32_vec3_apply_object_rotation(ObjectTransform *trans, f32 *vec3_f32) { - f32 yRotSine; - f32 yRotCosine; - f32 xRotSine; - f32 xRotCosine; - f32 zRotSine; - f32 zRotCosine; - f32 x, y, z; - f32 temp; - - zRotSine = sinf(trans->rotation.z_rotation); - zRotCosine = cosf(trans->rotation.z_rotation); - xRotSine = sinf(trans->rotation.x_rotation); - xRotCosine = cosf(trans->rotation.x_rotation); - yRotSine = sinf(trans->rotation.y_rotation); - yRotCosine = cosf(trans->rotation.y_rotation); - - x = vec3_f32[0]; - y = vec3_f32[1]; - z = vec3_f32[2]; - - x = (vec3_f32[0] * zRotCosine) - (vec3_f32[1] * zRotSine); - y = (vec3_f32[1] * zRotCosine) + (vec3_f32[0] * zRotSine); - - temp = y; - y = (temp * xRotCosine) - (vec3_f32[2] * xRotSine); - z = (vec3_f32[2] * xRotCosine) + (temp * xRotSine); - - temp = x; - x = (temp * yRotCosine) + (z * yRotSine); - z = (z * yRotCosine) - (temp * yRotSine); - - vec3_f32[0] = x; - vec3_f32[1] = y; - vec3_f32[2] = z; -} -#else -GLOBAL_ASM("asm/math_util/f32_vec3_apply_object_rotation.s") -#endif - -#ifdef NON_EQUIVALENT -/* Official Name: mathOneFloatYPR */ -void f32_vec3_apply_object_rotation2(Vec3s *trans, f32 *arg1) { - f32 yRotSine; - f32 yRotCosine; - f32 xRotSine; - f32 xRotCosine; - f32 zRotSine; - f32 zRotCosine; - f32 temp_f4; - f32 temp_f6; - f32 temp_f8; - - xRotSine = sinf(trans->rotation.x_rotation); - xRotCosine = cosf(trans->rotation.x_rotation); - yRotSine = sinf(trans->rotation.y_rotation); - yRotCosine = cosf(trans->rotation.y_rotation); - zRotCosine = cosf(trans->rotation.z_rotation); - zRotSine = sinf(trans->rotation.z_rotation); - - temp_f4 = (arg1[0] * xRotSine) + (arg1[2] * xRotCosine); - temp_f8 = (arg1[2] * xRotSine) - (arg1[0] * xRotCosine); - - temp_f6 = (arg1[1] * yRotSine) - (temp_f8 * yRotCosine); - temp_f8 = (temp_f8 * yRotSine) + (arg1[1] * yRotCosine); - - arg1[2] = temp_f8; - - temp_f4 = (temp_f4 * zRotSine) - (temp_f6 * zRotCosine); - temp_f6 = (temp_f6 * zRotSine) + (temp_f4 * zRotCosine); - - arg1[0] = temp_f4; - arg1[1] = temp_f6; -} -#else -GLOBAL_ASM("asm/math_util/f32_vec3_apply_object_rotation2.s") -#endif - -#ifdef NON_EQUIVALENT -/* Official Name: mathOneFloatPY */ -void f32_vec3_apply_object_rotation3(Vec3s *trans, f32 *vec3_f32) { - f32 xRotSine; - f32 xRotCosine; - f32 yRotSine; - f32 yRotCosine; - f32 x, y, z; - - xRotSine = sinf(trans->x_rotation); - xRotCosine = cosf(trans->x_rotation); - yRotSine = sinf(trans->y_rotation); - yRotCosine = cosf(trans->y_rotation); - - z = vec3_f32[2]; - y = -(z * xRotSine); - z = z * xRotCosine; - x = (z * yRotSine); - z = z * yRotCosine; - - vec3_f32[0] = x; - vec3_f32[1] = y; - vec3_f32[2] = z; -} -#else -GLOBAL_ASM("asm/math_util/f32_vec3_apply_object_rotation3.s") +GLOBAL_ASM("asm/math_util/mtxf_billboard.s") #endif #ifdef NON_MATCHING +/** + * Rotates the given vector in place. + * Note: The rotation angles are specified in reverse order, but the applied rotation is standard + * — roll first, then pitch, then yaw. + */ +void vec3s_rotate_rpy(RPYAngles *rotation, Vec3s *vec) { + s32 x1, y1, z1; + s32 x2, y2, z2; + s32 sine, cosine; + + x1 = vec->x; + y1 = vec->y; + z1 = vec->z; + + sine = sins_s16(rotation->z_rotation); + cosine = coss_s16(rotation->z_rotation); + x2 = (x1 * cosine - y1 * sine) >> 16; + y2 = (y1 * cosine + x1 * sine) >> 16; + z2 = z1; + + sine = sins_s16(rotation->x_rotation); + cosine = coss_s16(rotation->x_rotation); + x1 = x2; + y1 = (y2 * cosine - z2 * sine) >> 16; + z1 = (z2 * cosine + y2 * sine) >> 16; + + sine = sins_s16(rotation->y_rotation); + cosine = coss_s16(rotation->y_rotation); + x2 = (x1 * cosine + z1 * sine) >> 16; + y2 = y1; + z2 = (z1 * cosine - x1 * sine) >> 16; + + vec->x = x2; + vec->y = y2; + vec->z = z2; +} +#else +GLOBAL_ASM("asm/math_util/vec3s_rotate_rpy.s") +#endif + +#ifdef NON_MATCHING +/** + * Rotates the given vector according to the specified rotation angles. + * The result is written back into the same vector. + */ +/* Official Name: mathOneFloatRPY */ +void vec3f_rotate(Vec3s *rotation, Vec3f *vec) { + f32 sine; + f32 cosine; + f32 x1, y1, z1; + f32 x2, y2, z2; + + x1 = vec->x; + y1 = vec->y; + z1 = vec->z; + + sine = sins_f(rotation->z_rotation); + cosine = coss_f(rotation->z_rotation); + x2 = x1 * cosine - y1 * sine; + y2 = y1 * cosine + x1 * sine; + z2 = z1; + + sine = sins_f(rotation->x_rotation); + cosine = coss_f(rotation->x_rotation); + x1 = x2; + y1 = y2 * cosine - z2 * sine; + z1 = z2 * cosine + y2 * sine; + + sine = sins_f(rotation->y_rotation); + cosine = coss_f(rotation->y_rotation); + x2 = x1 * cosine + z1 * sine; + y2 = y1; + z2 = z1 * cosine - x1 * sine; + + vec->x = x2; + vec->y = y2; + vec->z = z2; +} +#else +GLOBAL_ASM("asm/math_util/vec3f_rotate.s") +#endif + +#ifdef NON_MATCHING +/** + * Applies the inverse of the object rotation using the specified angles. + * Unlike the standard roll-pitch-yaw (Z-X-Y) order, this applies the angles in yaw-pitch-roll (Y-X-Z) order. + * To fully reverse the effect of vec3f_rotate, the input angles must also be negated. + * The result is written back into the same vector. + */ +/* Official Name: mathOneFloatYPR */ +void vec3f_rotate_ypr(Vec3s *rotation, Vec3f *vec) { + f32 sine; + f32 cosine; + f32 x1, y1, z1; + f32 x2, y2, z2; + + x1 = vec->x; + y1 = vec->y; + z1 = vec->z; + + sine = sins_f(rotation->y_rotation); + cosine = coss_f(rotation->y_rotation); + x2 = x1 * cosine + z1 * sine; + y2 = y1; + z2 = z1 * cosine - x1 * sine; + + sine = sins_f(rotation->x_rotation); + cosine = coss_f(rotation->x_rotation); + x1 = x2; + y1 = y2 * cosine - z2 * sine; + z1 = z2 * cosine + y2 * sine; + + sine = sins_f(rotation->z_rotation); + cosine = coss_f(rotation->z_rotation); + x2 = x1 * cosine - y1 * sine; + y2 = y1 * cosine + x1 * sine; + z2 = z1; + + vec->x = x2; + vec->y = y2; + vec->z = z2; +} +#else +GLOBAL_ASM("asm/math_util/vec3f_rotate_ypr.s") +#endif + +#ifdef NON_MATCHING +/** + * Rotates a forward-facing vector by the given pitch and yaw angles. + * Only the Z component of the input vector is considered; X and Y components are ignored. + * The roll angle is also ignored, as it has no effect on directional vectors. + * This is typically used to compute a direction vector from pitch and yaw angles. + * The result is written back into the same vector. + */ +/* Official Name: mathOneFloatPY */ +void vec3f_rotate_py(Vec3s *rotation, Vec3f *vec) { + f32 sinX; + f32 cosX; + f32 sinY; + f32 cosY; + f32 z; + + sinX = sins_f(rotation->x_rotation); + cosX = coss_f(rotation->x_rotation); + sinY = sins_f(rotation->y_rotation); + cosY = coss_f(rotation->y_rotation); + + z = vec->z; + + vec->x = z * cosX * sinY; + vec->y = -z * sinX; + vec->z = z * cosX * cosY; +} +#else +GLOBAL_ASM("asm/math_util/vec3f_rotate_py.s") +#endif + +#ifdef NON_MATCHING +/** + * Determines whether a point lies inside a triangle, projected onto the XZ plane. + * Points lying exactly on the triangle's edges are not considered inside. + */ /* Official Name: mathXZInTri */ -s32 point_triangle_2d_xz_intersection(s32 x, s32 z, s16 *vec3A, s16 *vec3B, s16 *vec3C) { - s32 result; - s32 aX; - s32 aZ; - s32 bX; - s32 bZ; - s32 cX; - s32 cZ; +s32 tri2d_xz_contains_point(s32 x, s32 z, Vec3s *pointA, Vec3s *pointB, Vec3s *pointC) { + s32 aX, aZ, bX, bZ, cX, cZ; s32 var_a1; s32 var_a2; s32 var_a3; - aX = vec3A[0]; - aZ = vec3A[2]; - bX = vec3B[0]; - bZ = vec3B[2]; - cX = vec3C[0]; - cZ = vec3C[2]; - result = FALSE; - var_a1 = 1; - var_a2 = 1; - var_a3 = 1; - if ((((x - aX) * (bZ - aZ)) - ((bX - aX) * (z - aZ))) < 0) { - var_a3 ^= 1; - } - if ((((x - bX) * (cZ - bZ)) - ((cX - bX) * (z - bZ))) < 0) { - var_a2 ^= 1; - } - if (var_a3 == var_a2) { - if ((((x - cX) * (aZ - cZ)) - ((aX - cX) * (z - cZ))) < 0) { - var_a1 ^= 1; - } - if (var_a1 == var_a2) { - result = TRUE; - } - } - return result; + aX = pointA->x; + aZ = pointA->z; + bX = pointB->x; + bZ = pointB->z; + cX = pointC->x; + cZ = pointC->z; + + var_a3 = (x - aX) * (bZ - aZ) - (bX - aX) * (z - aZ) >= 0; + var_a2 = (x - bX) * (cZ - bZ) - (cX - bX) * (z - bZ) >= 0; + var_a1 = (x - cX) * (aZ - cZ) - (aX - cX) * (z - cZ) >= 0; + return var_a3 == var_a2 && var_a2 == var_a1; } #else -GLOBAL_ASM("asm/math_util/point_triangle_2d_xz_intersection.s") +GLOBAL_ASM("asm/math_util/tri2d_xz_contains_point.s") #endif -#ifdef NON_EQUIVALENT +#ifdef NON_MATCHING +/** + * Creates a translation matrix that moves points by the specified (x, y, z) offset. + */ /* Official Name: mathTranslateMtx */ -void f32_matrix_from_position(Matrix *mtx, f32 x, f32 y, f32 z) { - s32 j; - s32 i; +void mtxf_from_translation(MtxF *mtx, f32 x, f32 y, f32 z) { + s32 i, j; + // Clear matrix for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { - *mtx[i][j] = 0; + (*mtx)[i][j] = 0; } } - *mtx[0][0] = 1.0f; - *mtx[1][1] = 1.0f; - *mtx[2][2] = 1.0f; - *mtx[3][3] = 1.0f; - *mtx[3][0] = x; - *mtx[3][1] = y; - *mtx[3][2] = z; + (*mtx)[0][0] = 1.0f; + (*mtx)[1][1] = 1.0f; + (*mtx)[2][2] = 1.0f; + (*mtx)[3][3] = 1.0f; + (*mtx)[3][0] = x; + (*mtx)[3][1] = y; + (*mtx)[3][2] = z; } #else -GLOBAL_ASM("asm/math_util/f32_matrix_from_position.s") +GLOBAL_ASM("asm/math_util/mtxf_from_translation.s") #endif +#ifdef NON_MATCHING +/** + * Creates a scaling matrix with the specified scale factors along the X, Y, and Z axes. + */ /* Official Name: mathScaleMtx */ -GLOBAL_ASM("asm/math_util/f32_matrix_from_scale.s") +void mtxf_from_scale(MtxF *mtx, f32 scaleX, f32 scaleY, f32 scaleZ) { + s32 i, j; + + // Clear matrix + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + (*mtx)[i][j] = 0; + } + } + + (*mtx)[0][0] = scaleX; + (*mtx)[1][1] = scaleY; + (*mtx)[2][2] = scaleZ; + (*mtx)[3][3] = 1.0f; +} +#else +GLOBAL_ASM("asm/math_util/mtxf_from_scale.s") +#endif #ifdef NON_MATCHING // Blatantly stolen from SM64 :) @@ -690,12 +793,17 @@ u16 arctan2_f(f32 y, f32 x) { GLOBAL_ASM("asm/math_util/arctan2_f.s") #endif -#ifdef NON_EQUIVALENT // Untested -UNUSED s32 s32_matrix_cell_sqrt(s32 arg0) { - return (s32) (sqrtf((f32) arg0 / 65536.0f) * 65536.0f); +#ifdef NON_EQUIVALENT +/** + * Computes the square root of a 16.16 fixed-point number and returns the result in the same format. + * Due to differences in rounding, the result from this C implementation may differ by 1 from the + * result produced by the assembly code. + */ +UNUSED s32 fix32_sqrt(s32 x) { + return FTOFIX32(sqrtf(FIX32TOF(x))); } #else -GLOBAL_ASM("asm/math_util/s32_matrix_cell_sqrt.s") +GLOBAL_ASM("asm/math_util/fix32_sqrt.s") #endif #ifdef NON_EQUIVALENT // Untested diff --git a/src/hasm/math_util.s b/src/hasm/math_util.s index 406526a3..4ba65515 100644 --- a/src/hasm/math_util.s +++ b/src/hasm/math_util.s @@ -72,7 +72,7 @@ leaf get_gIntDisFlag /* 70178 8006F578 9042D430 */ lbu $v0, %lo(gIntDisFlag)($v0) .end get_gIntDisFlag -leaf s32_matrix_to_s16_matrix +leaf mtx_to_mtxs /* 7017C 8006F57C 34080004 */ ori $t0, $zero, 0x4 /* 70180 8006F580 3C0FFFFF */ lui $t7, (0xFFFF0000 >> 16) .L8006F584: @@ -99,9 +99,9 @@ leaf s32_matrix_to_s16_matrix /* 701D4 8006F5D4 00000000 */ nop /* 701D8 8006F5D8 03E00008 */ jr $ra /* 701DC 8006F5DC 00000000 */ nop -.end s32_matrix_to_s16_matrix +.end mtx_to_mtxs -leaf f32_matrix_to_s32_matrix +leaf mtxf_to_mtxs /* 701E0 8006F5E0 3C014780 */ lui $at, (0x47800000 >> 16) /* 701E4 8006F5E4 44816000 */ mtc1 $at, $f12 /* 701E8 8006F5E8 34080004 */ ori $t0, $zero, 0x4 @@ -130,10 +130,10 @@ leaf f32_matrix_to_s32_matrix /* 70240 8006F640 00000000 */ nop /* 70244 8006F644 03E00008 */ jr $ra /* 70248 8006F648 00000000 */ nop -.end f32_matrix_to_s32_matrix +.end mtxf_to_mtxs /* Official Name: mathMtxXFMF */ -leaf guMtxXFMF +leaf mtxf_transform_point /* 7024C 8006F64C 44856000 */ mtc1 $a1, $f12 /* 70250 8006F650 C4840000 */ lwc1 $f4, 0x0($a0) /* 70254 8006F654 44867000 */ mtc1 $a2, $f14 @@ -174,10 +174,10 @@ leaf guMtxXFMF /* 702E0 8006F6E0 460A4100 */ add.s $f4, $f8, $f10 /* 702E4 8006F6E4 03E00008 */ jr $ra /* 702E8 8006F6E8 E7040000 */ swc1 $f4, 0x0($t8) -.end guMtxXFMF +.end mtxf_transform_point /* Official Name: mathMtxFastXFMF */ -leaf f32_matrix_dot +leaf mtxf_transform_dir /* 702EC 8006F6EC C4A40000 */ lwc1 $f4, 0x0($a1) /* 702F0 8006F6F0 C48A0000 */ lwc1 $f10, 0x0($a0) /* 702F4 8006F6F4 C4A60004 */ lwc1 $f6, 0x4($a1) @@ -209,10 +209,10 @@ leaf f32_matrix_dot /* 7035C 8006F75C 460E6380 */ add.s $f14, $f12, $f14 /* 70360 8006F760 03E00008 */ jr $ra /* 70364 8006F764 E4CE0008 */ swc1 $f14, 0x8($a2) -.end f32_matrix_dot +.end mtxf_transform_dir /* Official Name: mathMtxCatF */ -leaf f32_matrix_mult +leaf mtxf_mul /* 70368 8006F768 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 7036C 8006F76C F7A20000 */ sdc1 $f2, 0x0($sp) /* 70370 8006F770 34080004 */ ori $t0, $zero, 0x4 @@ -280,10 +280,10 @@ leaf f32_matrix_mult /* 70464 8006F864 D7A20000 */ ldc1 $f2, 0x0($sp) /* 70468 8006F868 03E00008 */ jr $ra /* 7046C 8006F86C 27BD0008 */ addiu $sp, $sp, 0x8 -.end f32_matrix_mult +.end mtxf_mul /* Official Name: mathMtxF2L */ -leaf f32_matrix_to_s16_matrix +leaf mtxf_to_mtx /* 70470 8006F870 3C014780 */ lui $at, (0x47800000 >> 16) /* 70474 8006F874 44816000 */ mtc1 $at, $f12 /* 70478 8006F878 34080004 */ ori $t0, $zero, 0x4 @@ -324,7 +324,7 @@ leaf f32_matrix_to_s16_matrix /* 70500 8006F900 00000000 */ nop /* 70504 8006F904 03E00008 */ jr $ra /* 70508 8006F908 00000000 */ nop -.end f32_matrix_to_s16_matrix +.end mtxf_to_mtx /* Official Name: mathSeed */ leaf set_rng_seed @@ -356,7 +356,7 @@ leaf get_rng_seed .end get_rng_seed /* Official Name: mathRnd */ -leaf get_random_number_from_range +leaf rand_range /* 7054C 8006F94C 3C08800E */ lui $t0, %hi(gCurrentRNGSeed) /* 70550 8006F950 8D08D434 */ lw $t0, %lo(gCurrentRNGSeed)($t0) /* 70554 8006F954 3C01800E */ lui $at, %hi(gCurrentRNGSeed) @@ -385,10 +385,10 @@ leaf get_random_number_from_range .L8006F9B0: /* 705B0 8006F9B0 03E00008 */ jr $ra /* 705B4 8006F9B4 00000000 */ nop -.end get_random_number_from_range +.end rand_range /* Official Name: fastShortReflection */ -leaf s16_matrix_rotate +leaf vec3s_reflect /* 705B8 8006F9B8 84880000 */ lh $t0, 0x0($a0) /* 705BC 8006F9BC 84AB0000 */ lh $t3, 0x0($a1) /* 705C0 8006F9C0 84890002 */ lh $t1, 0x2($a0) @@ -423,9 +423,9 @@ leaf s16_matrix_rotate /* 70634 8006FA34 01A86822 */ sub $t5, $t5, $t0 /* handwritten instruction */ /* 70638 8006FA38 03E00008 */ jr $ra /* 7063C 8006FA3C A48D000A */ sh $t5, 0xA($a0) -.end s16_matrix_rotate +.end vec3s_reflect -leaf s16_matrix_to_s32_matrix +leaf mtx_to_mtxs_2 /* 70640 8006FA40 340A0010 */ ori $t2, $zero, 0x10 /* 70644 8006FA44 016B5826 */ xor $t3, $t3, $t3 .L8006FA48: @@ -441,9 +441,9 @@ leaf s16_matrix_to_s32_matrix /* 7066C 8006FA6C 00000000 */ nop /* 70670 8006FA70 03E00008 */ jr $ra /* 70674 8006FA74 00000000 */ nop -.end s16_matrix_to_s32_matrix +.end mtx_to_mtxs_2 -leaf s16_vec3_mult_by_s32_matrix_full +leaf mtxs_transform_point /* 70678 8006FA78 84A80000 */ lh $t0, 0x0($a1) /* 7067C 8006FA7C 8C8B0000 */ lw $t3, 0x0($a0) /* 70680 8006FA80 84A90002 */ lh $t1, 0x2($a1) @@ -502,9 +502,9 @@ leaf s16_vec3_mult_by_s32_matrix_full /* 70754 8006FB54 000C6403 */ sra $t4, $t4, 16 /* 70758 8006FB58 03E00008 */ jr $ra /* 7075C 8006FB5C A4AC0004 */ sh $t4, 0x4($a1) -.end s16_vec3_mult_by_s32_matrix_full +.end mtxs_transform_point -leaf s16_vec3_mult_by_s32_matrix +leaf mtxs_transform_dir /* 70760 8006FB60 8C8B0000 */ lw $t3, 0x0($a0) /* 70764 8006FB64 84A80000 */ lh $t0, 0x0($a1) /* 70768 8006FB68 84A90002 */ lh $t1, 0x2($a1) @@ -557,9 +557,9 @@ leaf s16_vec3_mult_by_s32_matrix /* 70824 8006FC24 000C6403 */ sra $t4, $t4, 16 /* 70828 8006FC28 03E00008 */ jr $ra /* 7082C 8006FC2C A4AC0004 */ sh $t4, 0x4($a1) -.end s16_vec3_mult_by_s32_matrix +.end mtxs_transform_dir -leaf object_transform_to_matrix +leaf mtxf_from_transform /* 70830 8006FC30 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70834 8006FC34 3C013780 */ lui $at, (0x37800000 >> 16) /* 70838 8006FC38 FFBF0000 */ sd $ra, 0x0($sp) @@ -677,10 +677,10 @@ leaf object_transform_to_matrix /* 709F8 8006FDF8 27BD0008 */ addiu $sp, $sp, 0x8 /* 709FC 8006FDFC 03E00008 */ jr $ra /* 70A00 8006FE00 00000000 */ nop -.end object_transform_to_matrix +.end mtxf_from_transform /* Official Name: mathSquashY */ -leaf f32_matrix_scale_y_axis +leaf mtxf_scale_y /* 70A04 8006FE04 44859000 */ mtc1 $a1, $f18 /* 70A08 8006FE08 C4900010 */ lwc1 $f16, 0x10($a0) /* 70A0C 8006FE0C 46128402 */ mul.s $f16, $f16, $f18 @@ -692,10 +692,10 @@ leaf f32_matrix_scale_y_axis /* 70A24 8006FE24 46128402 */ mul.s $f16, $f16, $f18 /* 70A28 8006FE28 03E00008 */ jr $ra /* 70A2C 8006FE2C E4900018 */ swc1 $f16, 0x18($a0) -.end f32_matrix_scale_y_axis +.end mtxf_scale_y /* Official Name: mathTransY */ -leaf f32_matrix_translate_y_axis +leaf mtxf_translate_y /* 70A30 8006FE30 44858000 */ mtc1 $a1, $f16 /* 70A34 8006FE34 C4800010 */ lwc1 $f0, 0x10($a0) /* 70A38 8006FE38 C4840014 */ lwc1 $f4, 0x14($a0) @@ -713,10 +713,10 @@ leaf f32_matrix_translate_y_axis /* 70A68 8006FE68 E4840034 */ swc1 $f4, 0x34($a0) /* 70A6C 8006FE6C 03E00008 */ jr $ra /* 70A70 8006FE70 E4880038 */ swc1 $f8, 0x38($a0) -.end f32_matrix_translate_y_axis +.end mtxf_translate_y /* Official Name: mathRpyXyzMtx */ -leaf object_inverse_transform_to_matrix +leaf mtxf_from_inverse_transform /* 70A74 8006FE74 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70A78 8006FE78 3C013780 */ lui $at, (0x37800000 >> 16) /* 70A7C 8006FE7C FFBF0000 */ sd $ra, 0x0($sp) @@ -838,7 +838,7 @@ leaf object_inverse_transform_to_matrix /* 70C4C 8007004C 27BD0008 */ addiu $sp, $sp, 0x8 /* 70C50 80070050 03E00008 */ jr $ra /* 70C54 80070054 00000000 */ nop -.end object_inverse_transform_to_matrix +.end mtxf_from_inverse_transform leaf func_80070058 /* 70C58 80070058 27BDFFF8 */ addiu $sp, $sp, -0x8 @@ -897,7 +897,7 @@ leaf func_80070058 /* 70D2C 8007012C 00000000 */ nop .end func_80070058 -leaf f32_matrix_from_rotation_and_scale +leaf mtxf_billboard /* 70D30 80070130 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70D34 80070134 00E0C825 */ or $t9, $a3, $zero /* 70D38 80070138 3C013780 */ lui $at, (0x37800000 >> 16) @@ -943,9 +943,9 @@ leaf f32_matrix_from_rotation_and_scale /* 70DD8 800701D8 27BD0008 */ addiu $sp, $sp, 0x8 /* 70DDC 800701DC 03E00008 */ jr $ra /* 70DE0 800701E0 00000000 */ nop -.end f32_matrix_from_rotation_and_scale +.end mtxf_billboard -leaf s16_vec3_apply_object_rotation +leaf vec3s_rotate_rpy /* 70DE4 800701E4 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70DE8 800701E8 FFBF0000 */ sd $ra, 0x0($sp) /* 70DEC 800701EC 00803025 */ or $a2, $a0, $zero @@ -1025,10 +1025,10 @@ leaf s16_vec3_apply_object_rotation /* 70F14 80070314 27BD0008 */ addiu $sp, $sp, 0x8 /* 70F18 80070318 03E00008 */ jr $ra /* 70F1C 8007031C 00000000 */ nop -.end s16_vec3_apply_object_rotation +.end vec3s_rotate_rpy /* Official Name: mathOneFloatRPY */ -leaf f32_vec3_apply_object_rotation +leaf vec3f_rotate /* 70F20 80070320 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70F24 80070324 FFBF0000 */ sd $ra, 0x0($sp) /* 70F28 80070328 00803025 */ or $a2, $a0, $zero @@ -1075,10 +1075,10 @@ leaf f32_vec3_apply_object_rotation /* 70FCC 800703CC 27BD0008 */ addiu $sp, $sp, 0x8 /* 70FD0 800703D0 03E00008 */ jr $ra /* 70FD4 800703D4 00000000 */ nop -.end f32_vec3_apply_object_rotation +.end vec3f_rotate /* Official Name: mathOneFloatYPR */ -leaf f32_vec3_apply_object_rotation2 +leaf vec3f_rotate_ypr /* 70FD8 800703D8 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 70FDC 800703DC FFBF0000 */ sd $ra, 0x0($sp) /* 70FE0 800703E0 00803025 */ or $a2, $a0, $zero @@ -1125,10 +1125,10 @@ leaf f32_vec3_apply_object_rotation2 /* 71084 80070484 27BD0008 */ addiu $sp, $sp, 0x8 /* 71088 80070488 03E00008 */ jr $ra /* 7108C 8007048C 00000000 */ nop -.end f32_vec3_apply_object_rotation2 +.end vec3f_rotate_ypr /* Official Name: mathOneFloatPY */ -leaf f32_vec3_apply_object_rotation3 +leaf vec3f_rotate_py /* 71090 80070490 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 71094 80070494 FFBF0000 */ sd $ra, 0x0($sp) /* 71098 80070498 00803025 */ or $a2, $a0, $zero @@ -1153,10 +1153,10 @@ leaf f32_vec3_apply_object_rotation3 /* 710E4 800704E4 27BD0008 */ addiu $sp, $sp, 0x8 /* 710E8 800704E8 03E00008 */ jr $ra /* 710EC 800704EC 00000000 */ nop -.end f32_vec3_apply_object_rotation3 +.end vec3f_rotate_py /* Official Name: mathXZInTri */ -leaf point_triangle_2d_xz_intersection +leaf tri2d_xz_contains_point /* 710F0 800704F0 8FAE0010 */ lw $t6, 0x10($sp) /* 710F4 800704F4 84C80000 */ lh $t0, 0x0($a2) /* 710F8 800704F8 84C90004 */ lh $t1, 0x4($a2) @@ -1227,10 +1227,10 @@ leaf point_triangle_2d_xz_intersection .L800705F0: /* 711F0 800705F0 03E00008 */ jr $ra /* 711F4 800705F4 00000000 */ nop -.end point_triangle_2d_xz_intersection +.end tri2d_xz_contains_point /* Official Name: mathTranslateMtx */ -leaf f32_matrix_from_position +leaf mtxf_from_translation /* 711F8 800705F8 00804025 */ or $t0, $a0, $zero /* 711FC 800705FC 25090040 */ addiu $t1, $t0, 0x40 .L80070600: @@ -1248,10 +1248,10 @@ leaf f32_matrix_from_position /* 7122C 8007062C AC860034 */ sw $a2, 0x34($a0) /* 71230 80070630 03E00008 */ jr $ra /* 71234 80070634 AC870038 */ sw $a3, 0x38($a0) -.end f32_matrix_from_position +.end mtxf_from_translation /* Official Name: mathScaleMtx */ -leaf f32_matrix_from_scale +leaf mtxf_from_scale /* 71238 80070638 00804025 */ or $t0, $a0, $zero /* 7123C 8007063C 25090040 */ addiu $t1, $t0, 0x40 .L80070640: @@ -1266,7 +1266,7 @@ leaf f32_matrix_from_scale /* 71260 80070660 AC860014 */ sw $a2, 0x14($a0) /* 71264 80070664 03E00008 */ jr $ra /* 71268 80070668 AC870028 */ sw $a3, 0x28($a0) -.end f32_matrix_from_scale +.end mtxf_from_scale leaf atan2s /* 7126C 8007066C 00854025 */ or $t0, $a0, $a1 @@ -1352,7 +1352,7 @@ leaf arctan2_f /* 7137C 8007077C 00000000 */ nop .end arctan2_f -leaf s32_matrix_cell_sqrt +leaf fix32_sqrt /* 71380 80070780 44840000 */ mtc1 $a0, $f0 /* 71384 80070784 3C014780 */ lui $at, (0x47800000 >> 16) /* 71388 80070788 44811000 */ mtc1 $at, $f2 @@ -1364,7 +1364,7 @@ leaf s32_matrix_cell_sqrt /* 713A0 800707A0 44020000 */ mfc1 $v0, $f0 /* 713A4 800707A4 03E00008 */ jr $ra /* 713A8 800707A8 00000000 */ nop -.end s32_matrix_cell_sqrt +.end fix32_sqrt leaf bad_int_sqrt /* 713AC 800707AC 44840000 */ mtc1 $a0, $f0 diff --git a/src/hasm/obj_shade_fast.s b/src/hasm/obj_shade_fast.s index 418939e7..7c4cda2c 100644 --- a/src/hasm/obj_shade_fast.s +++ b/src/hasm/obj_shade_fast.s @@ -138,7 +138,7 @@ leaf calc_dynamic_lighting_for_object_2 /* 253BC 800247BC 00000000 */ nop /* 253C0 800247C0 27A50010 */ addiu $a1, $sp, 0x10 /* 253C4 800247C4 00402025 */ or $a0, $v0, $zero -/* 253C8 800247C8 0C01BDBB */ jal f32_matrix_dot +/* 253C8 800247C8 0C01BDBB */ jal mtxf_transform_dir /* 253CC 800247CC 00A03025 */ or $a2, $a1, $zero .L800247D0: /* 253D0 800247D0 86080000 */ lh $t0, 0x0($s0) @@ -158,11 +158,11 @@ leaf calc_dynamic_lighting_for_object_2 /* 25408 80024808 A70A0004 */ sh $t2, 0x4($t8) /* 2540C 8002480C AF030010 */ sw $v1, 0x10($t8) /* 25410 80024810 AF030014 */ sw $v1, 0x14($t8) -/* 25414 80024814 0C01BF9D */ jal object_inverse_transform_to_matrix +/* 25414 80024814 0C01BF9D */ jal mtxf_from_inverse_transform /* 25418 80024818 03002825 */ or $a1, $t8, $zero /* 2541C 8002481C 27A50010 */ addiu $a1, $sp, 0x10 /* 25420 80024820 27A40034 */ addiu $a0, $sp, 0x34 -/* 25424 80024824 0C01BDBB */ jal f32_matrix_dot +/* 25424 80024824 0C01BDBB */ jal mtxf_transform_dir /* 25428 80024828 00A03025 */ or $a2, $a1, $zero /* 2542C 8002482C 8E190054 */ lw $t9, 0x54($s0) /* 25430 80024830 44933000 */ mtc1 $s3, $f6 diff --git a/src/lights.c b/src/lights.c index f74b869a..f0959a34 100644 --- a/src/lights.c +++ b/src/lights.c @@ -273,7 +273,7 @@ void func_80032424(ObjectLight *light, s32 updateRate) { light->pos.x = light->homeX; light->pos.y = light->homeY; light->pos.z = light->homeZ; - f32_vec3_apply_object_rotation(&light->owner->segment.trans, (f32 *) &light->pos); + vec3f_rotate(&light->owner->segment.trans.rotation, &light->pos); light->pos.x += light->owner->segment.trans.x_position; light->pos.y += light->owner->segment.trans.y_position; light->pos.z += light->owner->segment.trans.z_position; @@ -385,17 +385,17 @@ void func_80032424(ObjectLight *light, s32 updateRate) { light->unk5A = light->pos.z + light->radius; } if (light->unk1 == 2) { - light->unk84 = -1.0f; + light->unk7C.z = -1.0f; rotation.y_rotation = light->unk70; rotation.x_rotation = light->unk72; rotation.z_rotation = 0; - f32_vec3_apply_object_rotation3(&rotation, &light->unk7C); + vec3f_rotate_py(&rotation, &light->unk7C); if (light->owner != NULL) { - f32_vec3_apply_object_rotation(&light->owner->segment.trans, &light->unk7C); + vec3f_rotate(&light->owner->segment.trans.rotation, &light->unk7C); } - light->unk7C = -light->unk7C; - light->unk80 = -light->unk80; - light->unk84 = -light->unk84; + light->unk7C.x = -light->unk7C.x; + light->unk7C.y = -light->unk7C.y; + light->unk7C.z = -light->unk7C.z; } light->unk5 = 0; } @@ -662,8 +662,8 @@ f32 light_direction_calc(ObjectLight *light) { distance = gLightDistance; if (distance > 0.0f) { mag = 1.0f / sqrtf(distance); - distance = (gLightDiffX * mag * light->unk7C) + (gLightDiffY * mag * light->unk80) + - (gLightDiffZ * mag * light->unk84); + distance = (gLightDiffX * mag * light->unk7C.x) + (gLightDiffY * mag * light->unk7C.y) + + (gLightDiffZ * mag * light->unk7C.z); if (distance < 0.0f) { distance = 0.0f; } diff --git a/src/lights.h b/src/lights.h index b1c69b2e..54460b6b 100644 --- a/src/lights.h +++ b/src/lights.h @@ -78,9 +78,7 @@ typedef struct ObjectLight { s16 unk76; u16 unk78; u16 unk7A; - f32 unk7C; // Think this might be scale. - f32 unk80; // Ditto. - f32 unk84; // The evolved form of ditto. + Vec3f unk7C; // Think this might be scale. } ObjectLight; /* Size: 0x14 bytes */ diff --git a/src/math_util.h b/src/math_util.h index eacf196e..5abe606b 100644 --- a/src/math_util.h +++ b/src/math_util.h @@ -5,6 +5,12 @@ #include "structs.h" #include "memory.h" +typedef struct RPYAngles { + s16 z_rotation; + s16 x_rotation; + s16 y_rotation; +} RPYAngles; + /** * Keeps the value within the range. */ @@ -36,26 +42,26 @@ void set_rng_seed(s32 num); void save_rng_seed(void); void load_rng_seed(void); s32 get_rng_seed(void); -s32 get_random_number_from_range(s32, s32); -void f32_matrix_to_s32_matrix(Matrix *input, MatrixS *output); -void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz); -void f32_matrix_dot(Matrix *mat1, Matrix *mat2, Matrix *output); -void f32_matrix_mult(Matrix *mat1, Matrix *mat2, Matrix *output); -void f32_matrix_to_s16_matrix(Matrix *input, MatrixS *output); -void s16_matrix_rotate(Vec3s *arg0, Vec3s *arg1); -void s16_vec3_mult_by_s32_matrix(MatrixS input, Vec3s *output); -void object_transform_to_matrix(Matrix mtx, ObjectTransform *trans); -void f32_matrix_scale_y_axis(Matrix *input, f32 scale); -void f32_matrix_translate_y_axis(Matrix *input, f32 offset); -void object_inverse_transform_to_matrix(Matrix mtx, ObjectTransform *trans); -void f32_matrix_from_rotation_and_scale(Matrix mtx, s32 angle, f32 scale, f32 scaleY); -void s16_vec3_apply_object_rotation(ObjectTransform *trans, s16 *vec3Arg); -void f32_vec3_apply_object_rotation(ObjectTransform *trans, f32 *vec3_f32); -void f32_vec3_apply_object_rotation2(Vec3s *trans, f32 *arg1); -void f32_vec3_apply_object_rotation3(Vec3s *trans, f32 *vec3_f32); -s32 point_triangle_2d_xz_intersection(s32 x, s32 z, s16 *vec3A, s16 *vec3B, s16 *vec3C); -void f32_matrix_from_position(Matrix *mtx, f32 x, f32 y, f32 z); -void f32_matrix_from_scale(Matrix, f32, f32, f32); +s32 rand_range(s32, s32); +void mtxf_to_mtxs(MtxF *mf, MtxS *mi); +void mtxf_transform_point(MtxF *mf, float x, float y, float z, float *ox, float *oy, float *oz); +void mtxf_transform_dir(MtxF *mf, Vec3f *in, Vec3f *out); +void mtxf_mul(MtxF *mat1, MtxF *mat2, MtxF *output); +void mtxf_to_mtx(MtxF *input, Mtx *output); +void vec3s_reflect(Vec3s *vec, Vec3s *n); +void mtxs_transform_dir(MtxS *input, Vec3s *output); +void mtxf_from_transform(MtxF *mtx, ObjectTransform *trans); +void mtxf_scale_y(MtxF *input, f32 scale); +void mtxf_translate_y(MtxF *input, f32 offset); +void mtxf_from_inverse_transform(MtxF *mtx, ObjectTransform *trans); +void mtxf_billboard(MtxF *mtx, s32 angle, f32 scale, f32 scaleY); +void vec3s_rotate_rpy(RPYAngles *rotation, Vec3s *vec3Arg); +void vec3f_rotate(Vec3s *rotation, Vec3f *vec); +void vec3f_rotate_ypr(Vec3s *rotation, Vec3f *vec); +void vec3f_rotate_py(Vec3s *rotation, Vec3f *vec); +s32 tri2d_xz_contains_point(s32 x, s32 z, Vec3s *vec3A, Vec3s *vec3B, Vec3s *vec3C); +void mtxf_from_translation(MtxF *mtx, f32 x, f32 y, f32 z); +void mtxf_from_scale(MtxF *mtx, f32 scaleX, f32 scaleY, f32 scaleZ); s32 atan2s(s32 xDelta, s32 zDelta); f32 area_triangle_2d(f32 x0, f32 z0, f32 x1, f32 z1, f32 x2, f32 z2); void dmacopy_doubleword(void *src, void *dst, s32 end); diff --git a/src/menu.c b/src/menu.c index fa51a023..ec45ec3b 100644 --- a/src/menu.c +++ b/src/menu.c @@ -50,7 +50,7 @@ s32 gNumberOfCheats; s32 gNameEntryStickX; Gfx *sMenuCurrDisplayList; s16 gCheatInputCurrentRow; -MatrixS *sMenuCurrHudMat; +Mtx *sMenuCurrHudMat; s16 gCheatInputCurrentColumn; Vertex *sMenuCurrHudVerts; s16 gCheatInputStringLength; @@ -271,13 +271,13 @@ s32 gAdventureSaveGhost; // For some reason these BSS vars swapped places in different versions Gfx *sMenuCurrDisplayList; s32 gPreviousMenuID; -MatrixS *sMenuCurrHudMat; +Mtx *sMenuCurrHudMat; char **gTTSaveGhostPakErrorText; #else s32 gPreviousMenuID; Gfx *sMenuCurrDisplayList; char **gTTSaveGhostPakErrorText; -MatrixS *sMenuCurrHudMat; +Mtx *sMenuCurrHudMat; #endif Vertex *sMenuCurrHudVerts; Triangle *sMenuCurrHudTris; @@ -2287,15 +2287,15 @@ void func_80080580(Gfx **dList, s32 startX, s32 startY, s32 width, s32 height, s gSPDisplayList((*dList)++, &dMenuHudSettings); if (tex != NULL) { gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(&dMenuHudDrawModes[1]), 2); - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(tex->cmd), tex->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(tex->cmd), tex->numberOfCommands); i = TRUE; // texEnabled } else { gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(&dMenuHudDrawModes[0]), 2); i = FALSE; // texEnabled } gDPPipeSync((*dList)++); - gSPVertexDKR((*dList)++, OS_PHYSICAL_TO_K0(gMenuGeometry[gWoodPanelCount].vertices[gMenuTrisFlip]), 20, 0); - gSPPolygon((*dList)++, OS_PHYSICAL_TO_K0(gMenuGeometry[gWoodPanelCount].triangles[gMenuTrisFlip]), 10, i); + gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(gMenuGeometry[gWoodPanelCount].vertices[gMenuTrisFlip]), 20, 0); + gSPPolygon((*dList)++, OS_K0_TO_PHYSICAL(gMenuGeometry[gWoodPanelCount].triangles[gMenuTrisFlip]), 10, i); rendermode_reset(dList); } else { gMenuGeometry[gWoodPanelCount].unk18[gMenuTrisFlip] = 0; @@ -2578,8 +2578,7 @@ void menu_init(u32 menuId) { /** * Runs every frame. Calls the loop function of the current menu id */ -s32 menu_loop(Gfx **currDisplayList, MatrixS **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, - s32 updateRate) { +s32 menu_loop(Gfx **currDisplayList, Mtx **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate) { s32 ret; sMenuCurrDisplayList = *currDisplayList; @@ -7059,7 +7058,7 @@ void charselect_assign_ai(s32 charSlot) { for (i = charSlot; i < 8; i++) { do { - gCharacterIdSlots[i] = (*gCurrCharacterSelectData)[get_random_number_from_range(0, numCharacters)].voiceID; + gCharacterIdSlots[i] = (*gCurrCharacterSelectData)[rand_range(0, numCharacters)].voiceID; for (j = 0, foundIt = FALSE; j < i; j++) { if (gCharacterIdSlots[j] == gCharacterIdSlots[i]) { foundIt = TRUE; @@ -8569,7 +8568,7 @@ void menu_track_select_unload(void) { #endif } -s32 func_8008F618(Gfx **dList, MatrixS **mtx) { +s32 func_8008F618(Gfx **dList, Mtx **mtx) { s32 sp7C; s32 yPos; s32 texU; @@ -8664,8 +8663,8 @@ s32 func_8008F618(Gfx **dList, MatrixS **mtx) { } material_set(dList, bgTexture, flags, 0); - gSPVertexDKR((*dList)++, OS_PHYSICAL_TO_K0(tempVertices), 4, 0); - gSPPolygon((*dList)++, OS_PHYSICAL_TO_K0(tempTriangles), 2, hasTexture); + gSPVertexDKR((*dList)++, OS_K0_TO_PHYSICAL(tempVertices), 4, 0); + gSPPolygon((*dList)++, OS_K0_TO_PHYSICAL(tempTriangles), 2, hasTexture); prevIndex = gTrackSelectBgData[index]; if (curIndex != prevIndex) { yPos -= (gTrackSelectViewportY >> 3); @@ -9624,7 +9623,7 @@ void func_80092188(s32 updateRate) { if (gTrackTTSoundMask != NULL) { sndp_stop(gTrackTTSoundMask); } - if (get_random_number_from_range(0, 255) >= 128) { + if (rand_range(0, 255) >= 128) { sound_play(SOUND_VOICE_TT_INTRO, &D_80126848); } else { sound_play(SOUND_VOICE_TT_GO_FOR_IT, &D_80126848); @@ -10809,7 +10808,7 @@ void postrace_message(SIDeviceStatus status) { * Handle the shrunken viewport when the race ends. * This includes the options and results of the race, depending on mode. */ -s32 menu_postrace(Gfx **dList, MatrixS **matrices, Vertex **vertices, s32 updateRate) { +s32 menu_postrace(Gfx **dList, Mtx **matrices, Vertex **vertices, s32 updateRate) { s32 sp54; s32 sp50; s32 sp4C; @@ -12987,7 +12986,7 @@ void menu_credits_init(void) { gCreditsArray[84] = gCreditsLastMessageArray[0]; // "THE END?" } - cheat = gCheatsInCreditsArray[get_random_number_from_range(0, NUMBER_CHEATS_IN_CREDITS - 1)]; + cheat = gCheatsInCreditsArray[rand_range(0, NUMBER_CHEATS_IN_CREDITS - 1)]; cheatIndex = -1; while (cheat != 0) { cheat >>= 1; @@ -13801,9 +13800,9 @@ void menu_image_load(s32 imageID) { gMenuImages[imageID].trans.z_position = sMenuImageProperties[imageID].trans.z_position; gMenuImages[imageID].trans.scale = sMenuImageProperties[imageID].trans.scale; gMenuImages[imageID].spriteOffset = sMenuImageProperties[imageID].spriteOffset; - gMenuImages[imageID].unk1A = get_random_number_from_range(0, 0xFFFF); - gMenuImages[imageID].unk1B = get_random_number_from_range(0, 0xFFFF); - gMenuImages[imageID].unk1C = get_random_number_from_range(0, 0xFFFF); + gMenuImages[imageID].unk1A = rand_range(0, 0xFFFF); + gMenuImages[imageID].unk1B = rand_range(0, 0xFFFF); + gMenuImages[imageID].unk1C = rand_range(0, 0xFFFF); gMenuImages[imageID].unk1D = sMenuImageProperties[imageID].unk1D; } @@ -13916,8 +13915,8 @@ void render_track_selection_viewport_border(ObjectModel *objMdl) { } material_set(&sMenuCurrDisplayList, tex, flags, texOffset); - gSPVertexDKR(sMenuCurrDisplayList++, OS_PHYSICAL_TO_K0(verts), numVerts, 0); - gSPPolygon(sMenuCurrDisplayList++, OS_PHYSICAL_TO_K0(tris), numTris, texEnabled); + gSPVertexDKR(sMenuCurrDisplayList++, OS_K0_TO_PHYSICAL(verts), numVerts, 0); + gSPPolygon(sMenuCurrDisplayList++, OS_K0_TO_PHYSICAL(tris), numTris, texEnabled); } } } @@ -14711,7 +14710,7 @@ void dialogue_close_stub(void) { /** * Renders ortho geometry if the current dialogue box has anything to draw. */ -f32 dialogue_ortho(UNUSED DialogueBoxBackground *textbox, Gfx **dList, MatrixS **mat, Vertex **verts) { +f32 dialogue_ortho(UNUSED DialogueBoxBackground *textbox, Gfx **dList, Mtx **mat, Vertex **verts) { sMenuCurrDisplayList = *dList; sMenuCurrHudMat = *mat; sMenuCurrHudVerts = *verts; diff --git a/src/menu.h b/src/menu.h index a801cb54..ab1b1607 100644 --- a/src/menu.h +++ b/src/menu.h @@ -467,13 +467,13 @@ typedef struct TrackRenderDetails { extern s32 gShowControllerPakMenu; extern u8 *__ROM_END; -s32 get_random_number_from_range(s32, s32); // No file to pull from yet. +s32 rand_range(s32, s32); // No file to pull from yet. void menu_button_free(void); void menu_geometry_end(void); void reset_title_logo_scale(void); void menu_init(u32 menuId); -s32 menu_loop(Gfx **currDisplayList, MatrixS **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate); +s32 menu_loop(Gfx **currDisplayList, Mtx **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate); void menu_timestamp_render(s32 frameCount, s32 xPos, s32 yPos, u8 red, u8 green, u8 blue, u8 fontID); void postrace_offsets(MenuElement *elements, f32 in, f32 mid, f32 out, s32 textOffset, s32 timestampOffset); void trackmenu_set_records(void); @@ -584,7 +584,7 @@ s32 dialogue_race_defeat(void); s32 trophy_race_cabinet_menu_loop(void); void dialogue_open_stub(void); void dialogue_close_stub(void); -f32 dialogue_ortho(DialogueBoxBackground *arg0, Gfx **dList, MatrixS **mat, Vertex **verts); +f32 dialogue_ortho(DialogueBoxBackground *arg0, Gfx **dList, Mtx **mat, Vertex **verts); u64 *get_eeprom_settings_pointer(void); s32 set_eeprom_settings_value(u64 valueToSet); s32 unset_eeprom_settings_value(u64 valueToUnset); @@ -646,7 +646,7 @@ s32 savemenu_input_message(s32 buttonsPressed, s32 yAxis); void savemenu_render_element(SaveFileData *file, s32 x, s32 y); void trackmenu_render_2D(s32 x, s32 y, char *hubName, char *trackName, s32 rectOpacity, s32 imageId, s32 copyViewPort, DrawTexture *arg7, s32 arg8); void pausemenu_render(UNUSED s32 updateRate); -s32 menu_postrace(Gfx **dList, MatrixS **matrices, Vertex **vertices, s32 updateRate); +s32 menu_postrace(Gfx **dList, Mtx **matrices, Vertex **vertices, s32 updateRate); void ghostmenu_render(UNUSED s32 updateRate); s32 ghostmenu_erase(s32 id); void cheatmenu_render(s32 updateRate); @@ -685,7 +685,7 @@ void func_80080580(Gfx **dList, s32 startX, s32 startY, s32 width, s32 height, s s32 colour, TextureHeader *tex); void fileselect_input_copy(s32 updateRate); -s32 func_8008F618(Gfx **dList, MatrixS **mtx); +s32 func_8008F618(Gfx **dList, Mtx **mtx); void func_80080BC8(Gfx **); void func_80080E90(Gfx **dList, s32 startX, s32 startY, s32 width, s32 height, s32 borderWidth, s32 borderHeight, s32 colour0, s32 colour1, s32 colour2, s32 colour3); diff --git a/src/object_functions.c b/src/object_functions.c index d106c2a5..15eb7944 100644 --- a/src/object_functions.c +++ b/src/object_functions.c @@ -159,7 +159,7 @@ void obj_loop_scenery(Object *obj, s32 updateRate) { if (obj->segment.header->particleCount == 1) { particleFlagShift = 0; } else { - particleFlagShift = get_random_number_from_range(0, obj->segment.header->particleCount - 1); + particleFlagShift = rand_range(0, obj->segment.header->particleCount - 1); } obj->particleEmittersEnabled = OBJ_EMIT_1 << particleFlagShift; obj_spawn_particle(obj, LOGIC_30FPS); @@ -344,7 +344,7 @@ void obj_loop_lasergun(Object *obj, s32 updateRate) { Object *laserBoltObj; f32 distance; ObjectTransform trans; - Matrix mtx; + MtxF mtx; Object *racerObj; f32 diffX; f32 diffZ; @@ -397,13 +397,13 @@ void obj_loop_lasergun(Object *obj, s32 updateRate) { trans.rotation.y_rotation = obj->segment.trans.rotation.y_rotation; trans.rotation.x_rotation = obj->segment.trans.rotation.x_rotation; trans.rotation.z_rotation = 0; - object_transform_to_matrix(mtx, &trans); + mtxf_from_transform(&mtx, &trans); diffX = 30.0f; // Need to use diffX to match. if (lasergun->targeting == FALSE) { diffX = 45.0f; } - guMtxXFMF(mtx, 0.0f, 0.0f, diffX, &laserBoltObj->segment.x_velocity, &laserBoltObj->segment.y_velocity, - &laserBoltObj->segment.z_velocity); + mtxf_transform_point(&mtx, 0.0f, 0.0f, diffX, &laserBoltObj->segment.x_velocity, + &laserBoltObj->segment.y_velocity, &laserBoltObj->segment.z_velocity); } } } @@ -1144,7 +1144,7 @@ void obj_loop_characterflag(Object *obj, UNUSED s32 updateRate) { void try_to_collect_egg(Object *obj, Object_CollectEgg *egg) { Object_64 *racer; Object *interactedObj; - Matrix mat; + MtxF mat; ObjectTransform transF; if (obj->interactObj->distance < 40) { @@ -1162,10 +1162,10 @@ void try_to_collect_egg(Object *obj, Object_CollectEgg *egg) { transF.x_position = -interactedObj->segment.trans.x_position; transF.y_position = -interactedObj->segment.trans.y_position; transF.z_position = -interactedObj->segment.trans.z_position; - object_inverse_transform_to_matrix(mat, &transF); - guMtxXFMF(mat, obj->segment.trans.x_position, obj->segment.trans.y_position, - obj->segment.trans.z_position, &obj->segment.trans.x_position, &obj->segment.trans.y_position, - &obj->segment.trans.z_position); + mtxf_from_inverse_transform(&mat, &transF); + mtxf_transform_point(&mat, obj->segment.trans.x_position, obj->segment.trans.y_position, + obj->segment.trans.z_position, &obj->segment.trans.x_position, + &obj->segment.trans.y_position, &obj->segment.trans.z_position); obj->segment.trans.x_position /= interactedObj->segment.trans.scale; obj->segment.trans.y_position /= interactedObj->segment.trans.scale; obj->segment.trans.z_position /= interactedObj->segment.trans.scale; @@ -1448,9 +1448,9 @@ void obj_init_fish(Object *fishObj, LevelObjectEntry_Fish *fishEntry, s32 param) fish->unk10C = fishEntry->common.y; fish->unk110 = fishEntry->common.z; if (param == 0) { - fish->unkFE = get_random_number_from_range(0, 0x10000); - fish->unk102 = get_random_number_from_range(0, 0x10000); - fish->unk106 = get_random_number_from_range(0, 0x10000); + fish->unkFE = rand_range(0, 0x10000); + fish->unk102 = rand_range(0, 0x10000); + fish->unk106 = rand_range(0, 0x10000); fish->unkFD = 0; } else { fish->unkFE = 0x4000; @@ -1557,10 +1557,10 @@ void obj_loop_fish(Object *fishObj, s32 updateRate) { fish->unkFD = 0; } } else { - randNumber = get_random_number_from_range(0, 7); + randNumber = rand_range(0, 7); if (randNumber == 0 && fish->unk118 >= 1.0f) { - fish->unkFD = get_random_number_from_range(160, 255); - randNumber = get_random_number_from_range(0, fish->unk118); + fish->unkFD = rand_range(160, 255); + randNumber = rand_range(0, fish->unk118); fishObj->segment.y_velocity = fish->unk10C - fishObj->segment.trans.y_position; fishObj->segment.y_velocity = (fishObj->segment.trans.y_position < fish->unk10C) ? (fishObj->segment.y_velocity + randNumber) @@ -1636,8 +1636,7 @@ void obj_loop_lavaspurt(Object *obj, s32 updateRate) { obj->segment.animFrame += updateRate * 4; if (obj->segment.animFrame > 255) { obj->segment.animFrame = 0; - obj->properties.lavaSpurt.actionTimer = - get_random_number_from_range(0, 30) + obj->properties.lavaSpurt.delayTimer; + obj->properties.lavaSpurt.actionTimer = rand_range(0, 30) + obj->properties.lavaSpurt.delayTimer; } } } @@ -1893,8 +1892,8 @@ void obj_loop_wizpigship(Object *wizShipObj, s32 updateRate) { f32 posZ; Object *newObj; ObjectModel *wizShipModel; - Matrix shipMtx; - Matrix laserMtx; + MtxF shipMtx; + MtxF laserMtx; LevelObjectEntryCommon newObject; ObjectTransform trans; @@ -1909,7 +1908,7 @@ void obj_loop_wizpigship(Object *wizShipObj, s32 updateRate) { if ((wizShipObj->unk60 != NULL) && (wizShipObj->properties.fireball.timer == 0)) { if (wizShipObj->particleEmittersEnabled & OBJ_EMIT_1) { wizShipObj->properties.fireball.timer = 20; - object_transform_to_matrix(shipMtx, &wizShipObj->segment.trans); + mtxf_from_transform(&shipMtx, &wizShipObj->segment.trans); trans.x_position = 0.0f; trans.y_position = 0.0f; trans.z_position = 0.0f; @@ -1917,7 +1916,7 @@ void obj_loop_wizpigship(Object *wizShipObj, s32 updateRate) { trans.rotation.y_rotation = wizShipObj->segment.trans.rotation.y_rotation; trans.rotation.x_rotation = wizShipObj->segment.trans.rotation.x_rotation; trans.rotation.z_rotation = 0; - object_transform_to_matrix(laserMtx, &trans); + mtxf_from_transform(&laserMtx, &trans); for (i = 0; i < wizShipObj->unk60->unk0; i++) { index = wizShipObj->unk60->unk2C[i]; @@ -1926,7 +1925,7 @@ void obj_loop_wizpigship(Object *wizShipObj, s32 updateRate) { posX = wizShipObj->curVertData[wizShipModel->unk14[index]].x; posY = wizShipObj->curVertData[wizShipModel->unk14[index]].y; posZ = wizShipObj->curVertData[wizShipModel->unk14[index]].z; - guMtxXFMF(shipMtx, posX, posY, posZ, &posX, &posY, &posZ); + mtxf_transform_point(&shipMtx, posX, posY, posZ, &posX, &posY, &posZ); newObject.x = posX; newObject.y = posY; newObject.z = posZ; @@ -1940,8 +1939,8 @@ void obj_loop_wizpigship(Object *wizShipObj, s32 updateRate) { newObj->segment.trans.rotation.x_rotation = -wizShipObj->segment.trans.rotation.x_rotation; newObj->properties.lasergun.timer = 0x3C; - guMtxXFMF(laserMtx, 0.0f, 0.0f, -30.0f, &newObj->segment.x_velocity, - &newObj->segment.y_velocity, &newObj->segment.z_velocity); + mtxf_transform_point(&laserMtx, 0.0f, 0.0f, -30.0f, &newObj->segment.x_velocity, + &newObj->segment.y_velocity, &newObj->segment.z_velocity); audspat_play_sound_at_position(SOUND_LASER_GUN, wizShipObj->segment.trans.x_position, wizShipObj->segment.trans.y_position, wizShipObj->segment.trans.z_position, @@ -2281,7 +2280,7 @@ void obj_init_bombexplosion(Object *obj, LevelObjectEntry_BombExplosion *entry) LevelObjectEntry_BombExplosion *entry2; obj->segment.animFrame = 0; obj->segment.trans.scale = 0.5f; - obj->segment.object.modelIndex = get_random_number_from_range(0, obj->segment.header->numberOfModelIds - 1); + obj->segment.object.modelIndex = rand_range(0, obj->segment.header->numberOfModelIds - 1); entry2 = entry; // Needed for a match. obj->properties.bombExplosion.timer = 0; obj->properties.bombExplosion.unk4 = 0xFF; @@ -3077,7 +3076,7 @@ void obj_loop_parkwarden(Object *obj, s32 updateRate) { taj->musicFade = 0; music_channel_off(14); if (taj->unk30 == 0) { - taj->unk30 = get_random_number_from_range(600, 900); + taj->unk30 = rand_range(600, 900); taj->unk2C = 0; } } @@ -3085,7 +3084,7 @@ void obj_loop_parkwarden(Object *obj, s32 updateRate) { taj->unk2C += updateRate; if (taj->unk30 < taj->unk2C) { taj->unk36 = 1; - taj->unk2C = get_random_number_from_range(600, 900); + taj->unk2C = rand_range(600, 900); } } else { taj->unk2C = 0; @@ -4854,7 +4853,7 @@ void weapon_projectile(Object *obj, s32 updateRate) { s32 numCheckpoints; Object_Racer *racer; s8 surface; - Matrix mtxf; + MtxF mtxf; ObjectTransform trans; obj->interactObj->flags |= INTERACT_FLAGS_UNK_0100; @@ -4869,9 +4868,9 @@ void weapon_projectile(Object *obj, s32 updateRate) { trans.y_position = 0.0f; trans.z_position = 0.0f; trans.scale = 1.0f; - object_transform_to_matrix(mtxf, &trans); - guMtxXFMF(mtxf, 0.0f, 0.0f, weapon->forwardVel, &obj->segment.x_velocity, &obj->segment.y_velocity, - &obj->segment.z_velocity); + mtxf_from_transform(&mtxf, &trans); + mtxf_transform_point(&mtxf, 0.0f, 0.0f, weapon->forwardVel, &obj->segment.x_velocity, &obj->segment.y_velocity, + &obj->segment.z_velocity); updateRateF = updateRate; if (osTvType == OS_TV_TYPE_PAL) { updateRateF *= 1.2; @@ -6040,7 +6039,7 @@ void obj_loop_butterfly(Object *butterflyObj, s32 updateRate) { butterfly->unkFD = 1; } else { if (var_v1 >= 2) { - var_v1 = get_random_number_from_range(1, var_v1); + var_v1 = rand_range(1, var_v1); } var_v1--; butterfly->unk100 = sp44[var_v1]; @@ -6053,7 +6052,7 @@ void obj_loop_butterfly(Object *butterflyObj, s32 updateRate) { if (((xDiff * xDiff) + (zDiff * zDiff)) > 22500.0f) { butterfly->unkFD = 3; } else { - if (get_random_number_from_range(0, 0x64) >= 0x63) { + if (rand_range(0, 0x64) >= 0x63) { butterfly->unk106 = -butterfly->unk106; } butterflyObj->segment.trans.rotation.y_rotation += updateRate * butterfly->unk106; @@ -6138,7 +6137,7 @@ void obj_init_midifade(Object *obj, LevelObjectEntry_MidiFade *entry) { f32 oz; ObjectModel *objModel; UNUSED s32 pad; - Matrix mtx; + MtxF mtx; f32 sinYRot; f32 tempF3; f32 minX; @@ -6168,8 +6167,8 @@ void obj_init_midifade(Object *obj, LevelObjectEntry_MidiFade *entry) { transform.x_position = 0.0f; transform.y_position = 0.0f; transform.z_position = 0.0f; - object_transform_to_matrix(mtx, &transform); - guMtxXFMF(mtx, 0.0f, 0.0f, 1.0f, &ox, &oy, &oz); + mtxf_from_transform(&mtx, &transform); + mtxf_transform_point(&mtx, 0.0f, 0.0f, 1.0f, &ox, &oy, &oz); obj64->midi_fade.unk8 = ox; obj64->midi_fade.unkC = oy; obj64->midi_fade.unk10 = oz; @@ -6296,7 +6295,7 @@ void obj_init_bubbler(Object *obj, LevelObjectEntry_Bubbler *entry) { * This rolls a random number and starts emitting particles based on that for variable density. */ void obj_loop_bubbler(Object *obj, s32 updateRate) { - if (obj->properties.common.unk0 >= get_random_number_from_range(0, 1024)) { + if (obj->properties.common.unk0 >= rand_range(0, 1024)) { obj->particleEmittersEnabled = OBJ_EMIT_1; } else { obj->particleEmittersEnabled = OBJ_EMIT_NONE; @@ -6446,9 +6445,8 @@ void obj_loop_frog(Object *obj, s32 updateRate) { frog->hopTimer -= updateRate; if (frog->hopTimer < 0) { hopping = TRUE; - frog->forwardVel = get_random_number_from_range(40, 72); - frog->hopDirection = - get_random_number_from_range(-0x4000, 0x4000) + obj->segment.trans.rotation.y_rotation; + frog->forwardVel = rand_range(40, 72); + frog->hopDirection = rand_range(-0x4000, 0x4000) + obj->segment.trans.rotation.y_rotation; } } if (hopping) { @@ -6492,7 +6490,7 @@ void obj_loop_frog(Object *obj, s32 updateRate) { } if (frog->hopFrame < 0) { frog->action = FROG_IDLE; - frog->hopTimer = get_random_number_from_range(0, 300); + frog->hopTimer = rand_range(0, 300); frog->hopFrame = 0; } obj->segment.animFrame = ((32 - frog->hopFrame) << 3) / 3; diff --git a/src/objects.c b/src/objects.c index 02c225a3..2a63b6f2 100644 --- a/src/objects.c +++ b/src/objects.c @@ -274,7 +274,7 @@ s16 gPrevTimeTrialVehicle; // Current Vehicle being used in track? s16 gMapDefaultVehicle; // Vehicle enum s32 D_8011AE88; Gfx *gObjectCurrDisplayList; -MatrixS *gObjectCurrMatrix; +Mtx *gObjectCurrMatrix; Vertex *gObjectCurrVertexList; u8 *D_8011AE98[2]; s32 D_8011AEA0[2]; @@ -376,10 +376,10 @@ void racerfx_alloc(s32 numberOfVertices, s32 numberOfTriangles) { boostObj[i].unk74 = 0.0f; boostObj[i].sprite = tex_load_sprite(boostObj[i].spriteId, 0); boostObj[i].tex = load_texture(boostObj[i].textureId); - boostObj[i].unk72 = get_random_number_from_range(0, 255); + boostObj[i].unk72 = rand_range(0, 255); boostObj[i].unk73 = 0; // This is for shields, not boosts. - gShieldSineTime[i] = get_random_number_from_range(0, 255); + gShieldSineTime[i] = rand_range(0, 255); } D_8011B068[i] = TRUE; } @@ -392,8 +392,8 @@ void racerfx_alloc(s32 numberOfVertices, s32 numberOfTriangles) { gShieldEffectObject = spawn_object(&objEntry.common, OBJECT_SPAWN_NONE); for (i = 0; i < NUMBER_OF_CHARACTERS; i++) { gRacerFXData[i].unk0 = 0; - gRacerFXData[i].unk1 = get_random_number_from_range(0, 255); - gRacerFXData[i].unk2 = get_random_number_from_range(0, 255); + gRacerFXData[i].unk1 = rand_range(0, 255); + gRacerFXData[i].unk2 = rand_range(0, 255); gRacerFXData[i].unk3 = 0; } objEntry.common.objectID = ASSET_OBJECT_ID_AINODE; @@ -451,35 +451,35 @@ void func_8000B38C(Vertex *vertices, Triangle *triangles, ObjectTransform *trans s32 i; s32 height, width; s16 *v; - f32 sp64[3]; + Vec3f sp64; s32 *tri; f32 *ptr; s32 temp; v = (s16 *) vertices; - sp64[2] = -arg4; - f32_vec3_apply_object_rotation3(&trans->rotation, sp64); + sp64.z = -arg4; + vec3f_rotate_py(&trans->rotation, &sp64); // A rather strange way to fill structures - *v++ = sp64[0] + trans->x_position; - *v++ = sp64[1] + trans->y_position; - *v++ = sp64[2] + trans->z_position; + *v++ = sp64.f[0] + trans->x_position; + *v++ = sp64.f[1] + trans->y_position; + *v++ = sp64.f[2] + trans->z_position; *v++ = -1; *v++ = -1; ptr = D_800DC768; for (i = 0; i < 8; i++) { - sp64[0] = *ptr++ * arg3; - sp64[1] = *ptr++ * arg3; - sp64[2] = 0.0f; + sp64.x = *ptr++ * arg3; + sp64.y = *ptr++ * arg3; + sp64.z = 0.0f; - f32_vec3_apply_object_rotation(trans, sp64); + vec3f_rotate(&trans->rotation, &sp64); - *v++ = sp64[0] + trans->x_position; - *v++ = sp64[1] + trans->y_position; - *v++ = sp64[2] + trans->z_position; + *v++ = sp64.f[0] + trans->x_position; + *v++ = sp64.f[1] + trans->y_position; + *v++ = sp64.f[2] + trans->z_position; *v++ = -1; *v++ = -1; } @@ -503,7 +503,7 @@ void func_8000B38C(Vertex *vertices, Triangle *triangles, ObjectTransform *trans } void func_8000B750(Object *racerObj, s32 racerIndex, s32 vehicleIDPrev, s32 boostType, s32 arg4) { - f32 sp74[3]; + Vec3f sp74; f32 temp_f0; f32 var_f2; Object_Boost *boostAsset; @@ -575,13 +575,14 @@ void func_8000B750(Object *racerObj, s32 racerIndex, s32 vehicleIDPrev, s32 boos gBoostEffectObjects[racerIndex]->segment.trans.x_position = 0.0f; gBoostEffectObjects[racerIndex]->segment.trans.y_position = 0.0f; gBoostEffectObjects[racerIndex]->segment.trans.z_position = 0.0f; - sp74[0] = boostData->position.x; - sp74[1] = boostData->position.y; - sp74[2] = boostData->position.z; - f32_vec3_apply_object_rotation(&racerObj->segment.trans, sp74); + sp74.x = boostData->position.x; + sp74.y = boostData->position.y; + sp74.z = boostData->position.z; + vec3f_rotate(&racerObj->segment.trans.rotation, &sp74); ignore_bounds_check(); - move_object(gBoostEffectObjects[racerIndex], racerObj->segment.trans.x_position + sp74[0], - racerObj->segment.trans.y_position + sp74[1], racerObj->segment.trans.z_position + sp74[2]); + move_object(gBoostEffectObjects[racerIndex], racerObj->segment.trans.x_position + sp74.f[0], + racerObj->segment.trans.y_position + sp74.f[1], + racerObj->segment.trans.z_position + sp74.f[2]); } if (arg4 != FALSE) { D_8011B068[racerIndex] = FALSE; @@ -3265,7 +3266,7 @@ void func_80012CE8(Gfx **dList) { * Update the object stack trace, set the draw pointers, then begin rendering the object. * Official Name: objPrintObject */ -void render_object(Gfx **dList, MatrixS **mtx, Vertex **verts, Object *obj) { +void render_object(Gfx **dList, Mtx **mtx, Vertex **verts, Object *obj) { f32 scale; if (obj->segment.trans.flags & (OBJ_FLAGS_INVISIBLE | OBJ_FLAGS_SHADOW_ONLY)) { return; @@ -3592,7 +3593,7 @@ void render_bubble_trap(ObjectTransform *trans, Sprite *gfxData, Object *obj, s3 Camera *cameraSegment; f32 dist; - f32_vec3_apply_object_rotation(trans, &obj->segment.trans.x_position); + vec3f_rotate(&trans->rotation, &obj->segment.trans.x_position); obj->segment.trans.x_position += trans->x_position; obj->segment.trans.y_position += trans->y_position; obj->segment.trans.z_position += trans->z_position; @@ -3617,7 +3618,7 @@ void render_bubble_trap(ObjectTransform *trans, Sprite *gfxData, Object *obj, s3 * Get the racer object data, and fetch set visual shield properties based on that racer. * Afterwards, render the graphics with opacity scaling with the fadetimer. */ -void render_racer_shield(Gfx **dList, MatrixS **mtx, Vertex **vtxList, Object *obj) { +void render_racer_shield(Gfx **dList, Mtx **mtx, Vertex **vtxList, Object *obj) { Object_Racer *racer; Object_68 *gfxData; ObjectModel *mdl; @@ -3689,7 +3690,7 @@ void render_racer_shield(Gfx **dList, MatrixS **mtx, Vertex **vtxList, Object *o * Get the racer object data, and fetch set visual magnet properties based on that racer. * Afterwards, render the graphics with opacity set by the properties. */ -void render_racer_magnet(Gfx **dList, MatrixS **mtx, Vertex **vtxList, Object *obj) { +void render_racer_magnet(Gfx **dList, Mtx **mtx, Vertex **vtxList, Object *obj) { Object_Racer *racer; Object_68 *gfxData; ObjectModel *mdl; @@ -4265,9 +4266,9 @@ void func_80016748(Object *obj0, Object *obj1) { f32 temp; #ifdef AVOID_UB - Matrix obj1TransformMtx; + MtxF obj1TransformMtx; #else - // THIS IS A HACK! Supposed to be a Matrix, but the stack ended up being too big. + // THIS IS A HACK! Supposed to be a MtxF, but the stack ended up being too big. f32 pad[2]; f32 obj1TransformMtx[4][3]; #endif @@ -4291,12 +4292,12 @@ void func_80016748(Object *obj0, Object *obj1) { if (!((objModel->unk3C + 50.0) < sqrtf((xDiff * xDiff) + (yDiff * yDiff) + (zDiff * zDiff)))) { obj0Interact = obj0->interactObj; obj1Interact = obj1->interactObj; - object_transform_to_matrix((float(*)[4]) obj1TransformMtx, &obj1->segment.trans); + mtxf_from_transform((MtxF *) obj1TransformMtx, &obj1->segment.trans); for (i = 0; i < objModel->unk20; i += 2) { xDiff = obj1->curVertData[objModel->unk1C[i]].x; yDiff = obj1->curVertData[objModel->unk1C[i]].y; zDiff = obj1->curVertData[objModel->unk1C[i]].z; - guMtxXFMF((float(*)[4]) obj1TransformMtx, xDiff, yDiff, zDiff, &xDiff, &yDiff, &zDiff); + mtxf_transform_point((MtxF *) obj1TransformMtx, xDiff, yDiff, zDiff, &xDiff, &yDiff, &zDiff); temp = (((f32) objModel->unk1C[i + 1] / 64) * obj1->segment.trans.scale) * 50.0; xDiff -= obj0->segment.trans.x_position; yDiff -= obj0->segment.trans.y_position; @@ -4449,13 +4450,13 @@ void func_8001709C(Object *obj) { ObjectTransform sp78; s32 i; f32 inverseScale; - Matrix *sp6C; - Matrix sp2C; + MtxF *sp6C; + MtxF sp2C; Object_5C *obj5C; obj5C = obj->unk5C; obj5C->unk104 = (obj5C->unk104 + 1) & 1; - sp6C = (Matrix *) &obj5C->_matrices[obj5C->unk104 << 1]; + sp6C = (MtxF *) &obj5C->_matrices[obj5C->unk104 << 1]; sp78.rotation.y_rotation = -obj->segment.trans.rotation.y_rotation; sp78.rotation.x_rotation = -obj->segment.trans.rotation.x_rotation; sp78.rotation.z_rotation = -obj->segment.trans.rotation.z_rotation; @@ -4463,7 +4464,7 @@ void func_8001709C(Object *obj) { sp78.x_position = -obj->segment.trans.x_position; sp78.y_position = -obj->segment.trans.y_position; sp78.z_position = -obj->segment.trans.z_position; - object_inverse_transform_to_matrix((float(*)[4]) sp6C, &sp78); + mtxf_from_inverse_transform(sp6C, &sp78); inverseScale = 1.0 / obj->segment.trans.scale; i = 0; while (i < 16) { @@ -4474,7 +4475,7 @@ void func_8001709C(Object *obj) { sp2C[1][1] = inverseScale; sp2C[2][2] = inverseScale; sp2C[3][3] = 1.0f; - f32_matrix_mult(sp6C, &sp2C, sp6C); + mtxf_mul(sp6C, &sp2C, sp6C); sp78.rotation.y_rotation = obj->segment.trans.rotation.y_rotation; sp78.rotation.x_rotation = obj->segment.trans.rotation.x_rotation; sp78.rotation.z_rotation = obj->segment.trans.rotation.z_rotation; @@ -4482,7 +4483,7 @@ void func_8001709C(Object *obj) { sp78.x_position = obj->segment.trans.x_position; sp78.y_position = obj->segment.trans.y_position; sp78.z_position = obj->segment.trans.z_position; - object_transform_to_matrix(obj5C->_matrices[(obj5C->unk104 + 2) << 1], &sp78); + mtxf_from_transform(obj5C->_matrices[(obj5C->unk104 + 2) << 1], &sp78); obj5C->unk100 = NULL; } @@ -4567,7 +4568,7 @@ void func_80017E98(void) { Object *obj; CheckpointNode *checkpoint; LevelObjectEntry_Checkpoint *checkpointEntry; - f32 mtx[4][4]; + MtxF mtx; ObjectTransform transform; s32 var_t2; @@ -4641,8 +4642,8 @@ void func_80017E98(void) { transform.x_position = 0.0f; transform.y_position = 0.0f; transform.z_position = 0.0f; - object_transform_to_matrix(&mtx[0], &transform); - guMtxXFMF(&mtx[0], 0.0f, 0.0f, 1.0f, &ox, &oy, &oz); + mtxf_from_transform(&mtx, &transform); + mtxf_transform_point(&mtx, 0.0f, 0.0f, 1.0f, &ox, &oy, &oz); checkpoint->rotationXFrac = ox; checkpoint->rotationYFrac = oy; checkpoint->rotationZFrac = oz; @@ -5424,7 +5425,7 @@ Object *get_racer_object_by_port(s32 index) { * Unused function that would've iterated through all active checkpoints to render their visual nodes. * The function it calls is completely stubbed out. */ -UNUSED void debug_render_checkpoints(Gfx **dList, MatrixS **mtx, Vertex **vtx) { +UNUSED void debug_render_checkpoints(Gfx **dList, Mtx **mtx, Vertex **vtx) { s32 i; material_set_no_tex_offset(dList, NULL, RENDER_Z_COMPARE); @@ -5445,7 +5446,7 @@ UNUSED void debug_render_checkpoints(Gfx **dList, MatrixS **mtx, Vertex **vtx) { * visual representation of what these checkpoints would've looked like ingame. */ UNUSED void debug_render_checkpoint_node(UNUSED s32 checkpointID, UNUSED s32 pathID, UNUSED Gfx **dList, - UNUSED MatrixS **mtx, UNUSED Vertex **vtx) { + UNUSED Mtx **mtx, UNUSED Vertex **vtx) { } /** @@ -5993,13 +5994,13 @@ void set_shading_properties(ShadeProperties *arg0, f32 brightness, f32 ambient, arg0->unk0 = 1.0f; arg0->unk24 = angleY; arg0->unk26 = angleZ; - angle.z = angleX; - angle.x = angleZ; - angle.y = angleY; + angle.z_rotation = angleX; + angle.y_rotation = angleZ; + angle.x_rotation = angleY; velocityPos.z = -16384.0f; velocityPos.x = 0.0f; velocityPos.y = 0.0f; - f32_vec3_apply_object_rotation((ObjectTransform *) &angle, (f32 *) &velocityPos); + vec3f_rotate(&angle, &velocityPos); arg0->unk1C = -velocityPos.x; arg0->unk1E = -velocityPos.y; arg0->unk20 = -velocityPos.z; @@ -6097,10 +6098,10 @@ void calc_dynamic_lighting_for_object_1(Object *object, ObjectModel *model, s16 sp94.y_rotation = -object->segment.trans.rotation.y_rotation; sp94.x_rotation = -object->segment.trans.rotation.x_rotation; sp94.z_rotation = -object->segment.trans.rotation.z_rotation; - f32_vec3_apply_object_rotation2(&sp94, &sp5C.f); + vec3f_rotate_ypr(&sp94, &sp5C.f); if (object->segment.header->unk3D != 0 && arg2) { - f32_matrix_dot(get_projection_matrix_f32(), (Matrix *) &sp5C, (Matrix *) &sp5C); + mtxf_transform_dir(get_projection_matrix_f32(), &sp5C, &sp5C); } x1 = -sp5C.x; @@ -6112,9 +6113,9 @@ void calc_dynamic_lighting_for_object_1(Object *object, ObjectModel *model, s16 sp5C.z = object->shading->unk20 << 2; if (arg2) { - f32_matrix_dot(get_projection_matrix_f32(), (Matrix *) &sp5C, (Matrix *) &sp5C); + mtxf_transform_dir(get_projection_matrix_f32(), &sp5C, &sp5C); } - f32_vec3_apply_object_rotation2(&sp94, &sp5C.f); + vec3f_rotate_ypr(&sp94, &sp5C.f); x2 = sp5C.x; y2 = sp5C.y; @@ -6160,8 +6161,8 @@ void calc_dynamic_lighting_for_object_1(Object *object, ObjectModel *model, s16 } void calc_env_mapping_for_object(ObjectModel *model, s16 zRot, s16 xRot, s16 yRot) { - MatrixS objRotMtxS32; - Matrix objRotMtxF32; + MtxS objRotMtxS32; + MtxF objRotMtxF32; ObjectTransform objTrans; s16 k; s16 count; @@ -6188,8 +6189,8 @@ void calc_env_mapping_for_object(ObjectModel *model, s16 zRot, s16 xRot, s16 yRo objTrans.y_position = 0.0f; objTrans.z_position = 0.0f; objTrans.scale = 1.0f; - object_transform_to_matrix(objRotMtxF32, &objTrans); - f32_matrix_to_s32_matrix(&objRotMtxF32, &objRotMtxS32); + mtxf_from_transform(&objRotMtxF32, &objTrans); + mtxf_to_mtxs(&objRotMtxF32, &objRotMtxS32); for (i = 0; i < model->numberOfBatches; i++) { if (model->batches[i].flags & RENDER_ENVMAP) { @@ -6231,9 +6232,9 @@ void calc_env_mapping_for_object(ObjectModel *model, s16 zRot, s16 xRot, s16 yRo gEnvmapPos[1].y = model40Entries[count].y; gEnvmapPos[1].z = model40Entries[count].z; count++; - s16_vec3_mult_by_s32_matrix(objRotMtxS32, &gEnvmapPos[1]); + mtxs_transform_dir(&objRotMtxS32, &gEnvmapPos[1]); if (sp70 == 0) { - s16_matrix_rotate(&gEnvmapPos[0], &gEnvmapPos[1]); + vec3s_reflect(&gEnvmapPos[0], &gEnvmapPos[1]); } var_v0 = gEnvmapPos[1].x; var_v1 = gEnvmapPos[1].y; diff --git a/src/objects.h b/src/objects.h index 2b4f2124..93e9028d 100644 --- a/src/objects.h +++ b/src/objects.h @@ -372,7 +372,7 @@ void func_80012C30(void); void func_80012C3C(Gfx **dList); void func_80012C98(Gfx **dList); void func_80012CE8(Gfx **dList); -void render_object(Gfx **dList, MatrixS **mtx, Vertex **verts, Object *obj); +void render_object(Gfx **dList, Mtx **mtx, Vertex **verts, Object *obj); void object_undo_player_tumble(Object *obj); void render_object_parts(Object *obj); void unset_temp_model_transforms(Object *obj); @@ -400,7 +400,7 @@ Object **get_racer_objects(s32 *numRacers); Object **get_racer_objects_by_port(s32 *numRacers); Object **get_racer_objects_by_position(s32 *numRacers); Object *get_racer_object(s32 index); -void debug_render_checkpoint_node(s32 checkpointID, s32 pathID, Gfx** dList, MatrixS **mtx, Vertex **vtx); +void debug_render_checkpoint_node(s32 checkpointID, s32 pathID, Gfx** dList, Mtx **mtx, Vertex **vtx); Object *spectate_object(s32 cameraIndex); void ainode_enable(void); void ainode_tail_set(s32 nodeID); @@ -441,8 +441,8 @@ void func_80021400(s32 arg0); s32 timetrial_init_player_ghost(s32 playerID); s32 move_object(Object *obj, f32 xPos, f32 yPos, f32 zPos); Object *get_racer_object_by_port(s32 index); -void render_racer_shield(Gfx **dList, MatrixS **mtx, Vertex **vtxList, Object *obj); -void render_racer_magnet(Gfx **dList, MatrixS **mtx, Vertex **vtxList, Object *obj); +void render_racer_shield(Gfx **dList, Mtx **mtx, Vertex **vtxList, Object *obj); +void render_racer_magnet(Gfx **dList, Mtx **mtx, Vertex **vtxList, Object *obj); void update_envmap_position(f32 x, f32 y, f32 z); s32 init_object_water_effect(Object *obj, WaterEffect *waterEffect); s32 timetrial_load_staff_ghost(s32 mapId); diff --git a/src/particles.c b/src/particles.c index a5267cd8..519734c3 100644 --- a/src/particles.c +++ b/src/particles.c @@ -1052,19 +1052,19 @@ void setup_particle_velocity(Particle *particle, Object *obj, ParticleEmitter *e (PARTICLE_RANDOM_VELOCITY_Z | PARTICLE_RANDOM_VELOCITY_Y | PARTICLE_RANDOM_VELOCITY_X); if (randomizationFlags) { if (randomizationFlags & PARTICLE_RANDOM_VELOCITY_X) { - particle->velocity.x += (f32) get_random_number_from_range(-behaviour->velocityModifierRange.x, - behaviour->velocityModifierRange.x) * - 0.00001525878906; + particle->velocity.x += + (f32) rand_range(-behaviour->velocityModifierRange.x, behaviour->velocityModifierRange.x) * + 0.00001525878906; } if (randomizationFlags & PARTICLE_RANDOM_VELOCITY_Y) { - particle->velocity.y += (f32) get_random_number_from_range(-behaviour->velocityModifierRange.y, - behaviour->velocityModifierRange.y) * - 0.00001525878906; + particle->velocity.y += + (f32) rand_range(-behaviour->velocityModifierRange.y, behaviour->velocityModifierRange.y) * + 0.00001525878906; } if (randomizationFlags & PARTICLE_RANDOM_VELOCITY_Z) { - particle->velocity.z += (f32) get_random_number_from_range(-behaviour->velocityModifierRange.z, - behaviour->velocityModifierRange.z) * - 0.00001525878906; + particle->velocity.z += + (f32) rand_range(-behaviour->velocityModifierRange.z, behaviour->velocityModifierRange.z) * + 0.00001525878906; } } @@ -1090,26 +1090,25 @@ void setup_particle_velocity(Particle *particle, Object *obj, ParticleEmitter *e randomizationFlags = behaviour->randomizationFlags; if (randomizationFlags & PARTICLE_RANDOM_EMISSION_SPEED) { sourceVel.z += - (f32) get_random_number_from_range(-behaviour->emissionSpeedRange, behaviour->emissionSpeedRange) * - 0.00001525878906; + (f32) rand_range(-behaviour->emissionSpeedRange, behaviour->emissionSpeedRange) * 0.00001525878906; } if (randomizationFlags & (PARTICLE_RANDOM_EMISSION_DIR_PITCH | PARTICLE_RANDOM_EMISSION_DIR_YAW)) { angle.y_rotation = emitter->emissionDirection.y_rotation; if (randomizationFlags & PARTICLE_RANDOM_EMISSION_DIR_YAW) { - angle.y_rotation += get_random_number_from_range(-behaviour->emissionDirRange.y_rotation, - behaviour->emissionDirRange.y_rotation); + angle.y_rotation += + rand_range(-behaviour->emissionDirRange.y_rotation, behaviour->emissionDirRange.y_rotation); } angle.x_rotation = emitter->emissionDirection.x_rotation; if (randomizationFlags & PARTICLE_RANDOM_EMISSION_DIR_PITCH) { - angle.x_rotation += get_random_number_from_range(-behaviour->emissionDirRange.x_rotation, - behaviour->emissionDirRange.x_rotation); + angle.x_rotation += + rand_range(-behaviour->emissionDirRange.x_rotation, behaviour->emissionDirRange.x_rotation); } - f32_vec3_apply_object_rotation3(&angle, &sourceVel.x); + vec3f_rotate_py(&angle, &sourceVel); } else { - f32_vec3_apply_object_rotation3(&emitter->emissionDirection, &sourceVel.x); + vec3f_rotate_py(&emitter->emissionDirection, &sourceVel); } - f32_vec3_apply_object_rotation((ObjectTransform *) particle->parentObj, &sourceVel.x); + vec3f_rotate(&particle->parentObj->segment.trans.rotation, &sourceVel); particle->velocity.x += sourceVel.x; particle->velocity.y += sourceVel.y; @@ -1132,9 +1131,8 @@ void setup_particle_position(Particle *particle, Object *obj, ParticleEmitter *e // particle->movementParam shares memory with other fields; use the appropriate one based on movement type particle->movementParam = behaviour->movementParam; if (behaviour->randomizationFlags & PARTICLE_RANDOM_MOVEMENT_PARAM) { - particle->movementParam += - (f32) get_random_number_from_range(-behaviour->movementParamRange, behaviour->movementParamRange) * - 0.00001525878906; // 0.00001525878906 ~= 1.0/65536.0 + particle->movementParam += (f32) rand_range(-behaviour->movementParamRange, behaviour->movementParamRange) * + 0.00001525878906; // 0.00001525878906 ~= 1.0/65536.0 } if (behaviour->flags & PARTICLE_SOURCE_OFFSET_ENABLED) { @@ -1144,36 +1142,35 @@ void setup_particle_position(Particle *particle, Object *obj, ParticleEmitter *e randomizationFlags = behaviour->randomizationFlags; if (randomizationFlags & PARTICLE_RANDOM_SOURCE_DISTANCE) { sourcePos.z += - (f32) get_random_number_from_range(-behaviour->sourceDistanceRange, behaviour->sourceDistanceRange) * - 0.00001525878906; + (f32) rand_range(-behaviour->sourceDistanceRange, behaviour->sourceDistanceRange) * 0.00001525878906; } if (randomizationFlags & (PARTICLE_RANDOM_SOURCE_PITCH | PARTICLE_RANDOM_SOURCE_YAW)) { sourceDir.y_rotation = emitter->sourceRotation.y_rotation; if (randomizationFlags & PARTICLE_RANDOM_SOURCE_YAW) { - sourceDir.y_rotation += get_random_number_from_range(-behaviour->sourceDirRange.y_rotation, - behaviour->sourceDirRange.y_rotation); + sourceDir.y_rotation += + rand_range(-behaviour->sourceDirRange.y_rotation, behaviour->sourceDirRange.y_rotation); } sourceDir.x_rotation = emitter->sourceRotation.x_rotation; if (randomizationFlags & PARTICLE_RANDOM_SOURCE_PITCH) { - sourceDir.x_rotation += get_random_number_from_range(-behaviour->sourceDirRange.x_rotation, - behaviour->sourceDirRange.x_rotation); + sourceDir.x_rotation += + rand_range(-behaviour->sourceDirRange.x_rotation, behaviour->sourceDirRange.x_rotation); } - f32_vec3_apply_object_rotation3(&sourceDir, sourcePos.f); + vec3f_rotate_py(&sourceDir, &sourcePos); } else { - f32_vec3_apply_object_rotation((ObjectTransform *) &emitter->sourceRotation, sourcePos.f); + vec3f_rotate(&emitter->sourceRotation, &sourcePos); } particle->localPos.x += sourcePos.x; particle->localPos.y += sourcePos.y; particle->localPos.z += sourcePos.z; } if (particle->movementType != PARTICLE_MOVEMENT_BASIC_PARENT) { - f32_vec3_apply_object_rotation((ObjectTransform *) obj, particle->localPos.f); + vec3f_rotate(&obj->segment.trans.rotation, &particle->localPos); } particle->trans.x_position = particle->localPos.x; particle->trans.y_position = particle->localPos.y; particle->trans.z_position = particle->localPos.z; if (particle->movementType == PARTICLE_MOVEMENT_BASIC_PARENT) { - f32_vec3_apply_object_rotation((ObjectTransform *) obj, &particle->trans.x_position); + vec3f_rotate(&obj->segment.trans.rotation, &particle->trans.x_position); } particle->trans.x_position += obj->segment.trans.x_position; @@ -1381,7 +1378,7 @@ Particle *create_line_particle(Object *obj, ParticleEmitter *emitter) { emitter->lineRefPoint.x = emitter->position.x; emitter->lineRefPoint.y = emitter->position.y; emitter->lineRefPoint.z = emitter->position.z; - f32_vec3_apply_object_rotation(&obj->segment.trans, &emitter->lineRefPoint.x); + vec3f_rotate(&obj->segment.trans.rotation, &emitter->lineRefPoint); emitter->lineRefPoint.x += obj->segment.trans.x_position; emitter->lineRefPoint.y += obj->segment.trans.y_position; emitter->lineRefPoint.z += obj->segment.trans.z_position; @@ -1479,14 +1476,13 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { scale = behaviour->scale; if (behaviour->randomizationFlags & PARTICLE_RANDOM_SCALE) { - scale += (f32) get_random_number_from_range(-behaviour->scaleRange, behaviour->scaleRange) * 0.00001525878906; + scale += (f32) rand_range(-behaviour->scaleRange, behaviour->scaleRange) * 0.00001525878906; } particle->trans.scale = descriptor->scale * scale; scale = behaviour->scaleVelocity; if (behaviour->randomizationFlags & PARTICLE_RANDOM_SCALE_VELOCITY) { - scale += (f32) get_random_number_from_range(-behaviour->scaleVelocityRange, behaviour->scaleVelocityRange) * - 0.00001525878906; + scale += (f32) rand_range(-behaviour->scaleVelocityRange, behaviour->scaleVelocityRange) * 0.00001525878906; } if (behaviour->flags & PARTICLE_SCALE_VELOCITY_INHERITS_PARENT_SPEED) { particle->scaleVelocity = sqrtf((obj->segment.x_velocity * obj->segment.x_velocity) + @@ -1497,8 +1493,7 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { particle->scaleVelocity = descriptor->scale * scale; } - particle->destroyTimer = - get_random_number_from_range(-descriptor->lifeTimeRange, descriptor->lifeTimeRange) + descriptor->lifeTime; + particle->destroyTimer = rand_range(-descriptor->lifeTimeRange, descriptor->lifeTimeRange) + descriptor->lifeTime; particle->unk38 = 0; particle->unk34 = 0.0f; @@ -1524,16 +1519,16 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { PARTICLE_RANDOM_COLOUR_GREEN | PARTICLE_RANDOM_COLOUR_RED); if (randomizationFlags) { if (randomizationFlags & PARTICLE_RANDOM_COLOUR_RED) { - particle->colour.r += get_random_number_from_range(-behaviour->colourRangeR, behaviour->colourRangeR); + particle->colour.r += rand_range(-behaviour->colourRangeR, behaviour->colourRangeR); } if (randomizationFlags & PARTICLE_RANDOM_COLOUR_GREEN) { - particle->colour.g += get_random_number_from_range(-behaviour->colourRangeG, behaviour->colourRangeG); + particle->colour.g += rand_range(-behaviour->colourRangeG, behaviour->colourRangeG); } if (randomizationFlags & PARTICLE_RANDOM_COLOUR_BLUE) { - particle->colour.b += get_random_number_from_range(-behaviour->colourRangeB, behaviour->colourRangeB); + particle->colour.b += rand_range(-behaviour->colourRangeB, behaviour->colourRangeB); } if (randomizationFlags & PARTICLE_RANDOM_COLOUR_ALPHA) { - particle->colour.a += get_random_number_from_range(-behaviour->colourRangeA, behaviour->colourRangeA); + particle->colour.a += rand_range(-behaviour->colourRangeA, behaviour->colourRangeA); } } @@ -1566,7 +1561,7 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { } } if (behaviour->flags & PARTICLE_RANDOM_TEXTURE_FRAME) { - particle->textureFrame = get_random_number_from_range(0, particle->sprite->baseTextureId - 1) << 8; + particle->textureFrame = rand_range(0, particle->sprite->baseTextureId - 1) << 8; if ((particle->descFlags & (PARTICLE_TEXTURE_ANIM_FORWARD_ENABLED | PARTICLE_TEXTURE_ANIM_BACKWARD_ENABLED)) == PARTICLE_TEXTURE_ANIM_BACKWARD_ENABLED) { @@ -1595,7 +1590,7 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { } } if (behaviour->flags & PARTICLE_RANDOM_TEXTURE_FRAME) { - particle->textureFrame = get_random_number_from_range(0, ((*texture)->numOfTextures >> 8) - 1) << 8; + particle->textureFrame = rand_range(0, ((*texture)->numOfTextures >> 8) - 1) << 8; if ((particle->descFlags & (PARTICLE_TEXTURE_ANIM_FORWARD_ENABLED | PARTICLE_TEXTURE_ANIM_BACKWARD_ENABLED)) == PARTICLE_TEXTURE_ANIM_BACKWARD_ENABLED) { @@ -1639,15 +1634,15 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { if (randomizationFlags != 0) { if (randomizationFlags & PARTICLE_RANDOM_YAW) { particle->trans.rotation.y_rotation += - get_random_number_from_range(-behaviour->rotationRange.y_rotation, behaviour->rotationRange.y_rotation); + rand_range(-behaviour->rotationRange.y_rotation, behaviour->rotationRange.y_rotation); } if (randomizationFlags & PARTICLE_RANDOM_PITCH) { particle->trans.rotation.x_rotation += - get_random_number_from_range(-behaviour->rotationRange.x_rotation, behaviour->rotationRange.x_rotation); + rand_range(-behaviour->rotationRange.x_rotation, behaviour->rotationRange.x_rotation); } if (randomizationFlags & PARTICLE_RANDOM_ROLL) { particle->trans.rotation.z_rotation += - get_random_number_from_range(-behaviour->rotationRange.z_rotation, behaviour->rotationRange.z_rotation); + rand_range(-behaviour->rotationRange.z_rotation, behaviour->rotationRange.z_rotation); } } @@ -1659,16 +1654,16 @@ Particle *create_general_particle(Object *obj, ParticleEmitter *emitter) { (PARTCILE_RANDOM_ROLL_VELOCITY | PARTCILE_RANDOM_PITCH_VELOCITY | PARTCILE_RANDOM_YAW_VELOCITY); if (randomizationFlags) { if (randomizationFlags & PARTCILE_RANDOM_YAW_VELOCITY) { - particle->angularVelocity.y_rotation += get_random_number_from_range( - -behaviour->angularVelocityRange.y_rotation, behaviour->angularVelocityRange.y_rotation); + particle->angularVelocity.y_rotation += + rand_range(-behaviour->angularVelocityRange.y_rotation, behaviour->angularVelocityRange.y_rotation); } if (randomizationFlags & PARTCILE_RANDOM_PITCH_VELOCITY) { - particle->angularVelocity.x_rotation += get_random_number_from_range( - -behaviour->angularVelocityRange.x_rotation, behaviour->angularVelocityRange.x_rotation); + particle->angularVelocity.x_rotation += + rand_range(-behaviour->angularVelocityRange.x_rotation, behaviour->angularVelocityRange.x_rotation); } if (randomizationFlags & PARTCILE_RANDOM_ROLL_VELOCITY) { - particle->angularVelocity.z_rotation += get_random_number_from_range( - -behaviour->angularVelocityRange.z_rotation, behaviour->angularVelocityRange.z_rotation); + particle->angularVelocity.z_rotation += + rand_range(-behaviour->angularVelocityRange.z_rotation, behaviour->angularVelocityRange.z_rotation); } } @@ -2054,7 +2049,7 @@ void update_line_particle(Particle *particle) { vtxOffset.y = scale; break; } - f32_vec3_apply_object_rotation((ObjectTransform *) obj, &vtxOffset.x); + vec3f_rotate(&obj->segment.trans.rotation, &vtxOffset); } else { vtxOffset.x = obj->segment.x_velocity; vtxOffset.y = obj->segment.y_velocity; @@ -2273,7 +2268,7 @@ void move_particle_attached_to_parent(Particle *particle) { particle->trans.x_position = 0.0f; particle->trans.y_position = -particle->downOffset; particle->trans.z_position = 0.0f; - f32_vec3_apply_object_rotation(&particle->trans, &particle->trans.x_position); + vec3f_rotate(&particle->trans.rotation, &particle->trans.x_position); particle->trans.x_position += particle->localPos.x; particle->trans.y_position += particle->localPos.y; particle->trans.z_position += particle->localPos.z; @@ -2306,7 +2301,7 @@ void move_particle_with_acceleration(Particle *particle) { acceleration.x = 0.0f; acceleration.y = -particle->downAcceleration; acceleration.z = 0.0f; - f32_vec3_apply_object_rotation(&particle->trans, acceleration.f); + vec3f_rotate(&particle->trans.rotation, &acceleration); particle->velocity.x += acceleration.x; particle->velocity.y += acceleration.y; particle->velocity.y -= particle->gravity; @@ -2344,7 +2339,7 @@ void move_particle_forward(Particle *particle) { particle->velocity.x = 0.0f; particle->velocity.y = 0.0f; particle->velocity.z = -particle->forwardVel; - f32_vec3_apply_object_rotation3(&particle->trans.rotation, particle->velocity.f); + vec3f_rotate_py(&particle->trans.rotation, &particle->velocity); particle->trans.x_position += particle->velocity.x; // Gravity is subtracted here, but velocity isn't actually affected by it — possible bug? // Might cause the particle to drift downward instead of moving straight forward. @@ -2361,7 +2356,7 @@ void move_particle_forward(Particle *particle) { * Iterates through every object and renders it as a particle if applicable. * Only particles with the PARTICLE_UNK_FLAG_8000 flag set will be rendered. */ -UNUSED void render_active_particles(Gfx **dList, MatrixS **mtx, Vertex **vtx) { +UNUSED void render_active_particles(Gfx **dList, Mtx **mtx, Vertex **vtx) { UNUSED s32 pad; UNUSED s32 pad2; Particle **objects; @@ -2381,7 +2376,7 @@ UNUSED void render_active_particles(Gfx **dList, MatrixS **mtx, Vertex **vtx) { /** * Load a texture then render a sprite or a billboard. */ -void render_particle(Particle *particle, Gfx **dList, MatrixS **mtx, Vertex **vtx, s32 flags) { +void render_particle(Particle *particle, Gfx **dList, Mtx **mtx, Vertex **vtx, s32 flags) { s32 renderFlags; s32 alpha; s32 temp; @@ -2504,11 +2499,11 @@ void regenerate_point_particles_mesh(PointParticle *obj) { vec_right.x = particle->base.trans.scale; vec_right.y = 0.0f; vec_right.z = 0.0f; - f32_vec3_apply_object_rotation(&particle->base.trans, vec_right.f); + vec3f_rotate(&particle->base.trans.rotation, &vec_right); vec_up.x = 0.0f; vec_up.y = particle->base.trans.scale; vec_up.z = 0.0f; - f32_vec3_apply_object_rotation(&particle->base.trans, vec_up.f); + vec3f_rotate(&particle->base.trans.rotation, &vec_up); verts = &model->vertices[(particle->modelFrame << 3)]; if (1) {} diff --git a/src/particles.h b/src/particles.h index ba3fc151..2217f852 100644 --- a/src/particles.h +++ b/src/particles.h @@ -308,7 +308,7 @@ void obj_trigger_emitter(Object *obj, ParticleEmitter *emitter); Particle *create_general_particle(Object *obj, ParticleEmitter *emitter); void obj_enable_emitter(Object *obj, s32 emitterIndex); void emitter_change_settings(ParticleEmitter *emitter, s32 behaviourID, s32 particleID, s16 posX, s16 posY, s16 posZ); -void render_particle(Particle *particle, Gfx **dList, MatrixS **mtx, Vertex **vtx, s32 flags); +void render_particle(Particle *particle, Gfx **dList, Mtx **mtx, Vertex **vtx, s32 flags); void increase_emitter_opacity(Object *obj, s32 idx, s32 delta, s32 maxOpacity); void decrease_emitter_opacity(Object *obj, s32 idx, s32 delta, s32 maxOpacity); void obj_spawn_particle(Object *obj, s32 updateRate); diff --git a/src/printf.c b/src/printf.c index 65d47c68..427dd090 100644 --- a/src/printf.c +++ b/src/printf.c @@ -477,7 +477,7 @@ s32 debug_text_character(Gfx **dList, s32 asciiVal) { // Character is a symbol or number and not a letter if (gDebugFontTexture != 0) { if (gDebugTextOn) { - gDPLoadTextureBlock((*dList)++, OS_PHYSICAL_TO_K0(gTexture[0] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 192, 11, + gDPLoadTextureBlock((*dList)++, OS_K0_TO_PHYSICAL(gTexture[0] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 192, 11, 0, 2, 2, 0, 0, 0, 0); } gDebugFontTexture = 0; @@ -487,7 +487,7 @@ s32 debug_text_character(Gfx **dList, s32 asciiVal) { // Character is a upper case letter if (gDebugFontTexture != 1) { if (gDebugTextOn) { - gDPLoadTextureBlock((*dList)++, OS_PHYSICAL_TO_K0(gTexture[1] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 248, 11, + gDPLoadTextureBlock((*dList)++, OS_K0_TO_PHYSICAL(gTexture[1] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 248, 11, 0, 2, 2, 0, 0, 0, 0); } gDebugFontTexture = 1; @@ -497,7 +497,7 @@ s32 debug_text_character(Gfx **dList, s32 asciiVal) { // Character is a lower case letter if (gDebugFontTexture != 2) { if (gDebugTextOn) { - gDPLoadTextureBlock((*dList)++, OS_PHYSICAL_TO_K0(gTexture[2] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 192, 11, + gDPLoadTextureBlock((*dList)++, OS_K0_TO_PHYSICAL(gTexture[2] + 1), G_IM_FMT_IA, G_IM_SIZ_8b, 192, 11, 0, 2, 2, 0, 0, 0, 0); } gDebugFontTexture = 2; diff --git a/src/racer.c b/src/racer.c index a3bd3df9..6550a313 100644 --- a/src/racer.c +++ b/src/racer.c @@ -290,7 +290,7 @@ void func_80042D20(Object *obj, Object_Racer *racer, s32 updateRate) { } if (var_t0 < 7 && get_trophy_race_world_id() == 0 && func_80023568() == 0 && is_taj_challenge() == 0) { if (gRaceStartTimer == 100) { - racer->aiSkill = get_random_number_from_range(AI_MASTER, AI_HARD); + racer->aiSkill = rand_range(AI_MASTER, AI_HARD); } } else { if (get_trophy_race_world_id() != 0) { @@ -653,7 +653,7 @@ void racer_AI_pathing_inputs(Object *obj, Object_Racer *racer, s32 updateRate) { * Effectively, this is to make a 1-100% chance of it returning true, based on the number passed. */ s32 roll_percent_chance(s32 chance) { - return get_random_number_from_range(0, 99) < chance; + return rand_range(0, 99) < chance; } #pragma GLOBAL_ASM("asm/nonmatchings/racer/func_8004447C.s") @@ -928,7 +928,7 @@ void func_80046524(s32 updateRate, f32 updateRateF, Object *obj, Object_Racer *r s8 wave_properties; s8 wheelsOnStone; UNUSED s32 pad3; - Matrix transformedMtx; + MtxF transformedMtx; s8 playerObjectHasMoved; f32 var_f6; @@ -1125,10 +1125,10 @@ void func_80046524(s32 updateRate, f32 updateRateF, Object *obj, Object_Racer *r gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_transform_to_matrix(transformedMtx, &gCurrentRacerTransform); - guMtxXFMF(transformedMtx, 0.0f, 0.0f, 1.0f, &racer->ox1, &racer->oy1, &racer->oz1); - guMtxXFMF(transformedMtx, 0.0f, 1.0f, 0.0f, &racer->ox2, &racer->oy2, &racer->oz2); - guMtxXFMF(transformedMtx, 1.0f, 0.0f, 0.0f, &racer->ox3, &racer->oy3, &racer->oz3); + mtxf_from_transform(&transformedMtx, &gCurrentRacerTransform); + mtxf_transform_point(&transformedMtx, 0.0f, 0.0f, 1.0f, &racer->ox1, &racer->oy1, &racer->oz1); + mtxf_transform_point(&transformedMtx, 0.0f, 1.0f, 0.0f, &racer->ox2, &racer->oy2, &racer->oz2); + mtxf_transform_point(&transformedMtx, 1.0f, 0.0f, 0.0f, &racer->ox3, &racer->oy3, &racer->oz3); if (racer->approachTarget == NULL) { obj->segment.object.animationID = 0; var_v0 = racer->steerAngle; @@ -1547,9 +1547,9 @@ void func_80046524(s32 updateRate, f32 updateRateF, Object *obj, Object_Racer *r gCurrentRacerTransform.x_position = 0.0f; gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; - object_inverse_transform_to_matrix(transformedMtx, &gCurrentRacerTransform); - guMtxXFMF(transformedMtx, obj->segment.x_velocity, obj->segment.y_velocity, obj->segment.z_velocity, - &racer->lateral_velocity, (f32 *) &racer->unk34, &racer->velocity); + mtxf_from_inverse_transform(&transformedMtx, &gCurrentRacerTransform); + mtxf_transform_point(&transformedMtx, obj->segment.x_velocity, obj->segment.y_velocity, obj->segment.z_velocity, + &racer->lateral_velocity, (f32 *) &racer->unk34, &racer->velocity); if (racer->groundedWheels == 0 && racer->waterTimer == 0) { iTemp = (-gCurrentStickY * 0x40) & 0xFFFF; var_v1 = iTemp - (obj->segment.trans.rotation.x_rotation & 0xFFFF); @@ -1812,7 +1812,7 @@ void update_camera_hovercraft(f32 updateRate, Object *obj, Object_Racer *racer) * When on water, apply a rotation effect based on the movement of the waves and turning direction. */ f32 rotate_racer_in_water(Object *obj, Object_Racer *racer, Vec3f *pos, s8 arg3, s32 updateRate, s32 arg5, f32 arg6) { - Matrix mtxF; + MtxF mtxF; f32 velocity; s32 angle; s32 angleVel; @@ -1840,8 +1840,8 @@ f32 rotate_racer_in_water(Object *obj, Object_Racer *racer, Vec3f *pos, s8 arg3, gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_inverse_transform_to_matrix(mtxF, &gCurrentRacerTransform); - guMtxXFMF(mtxF, pos->x, pos->y, pos->z, &pos->x, &pos->y, &pos->z); + mtxf_from_inverse_transform(&mtxF, &gCurrentRacerTransform); + mtxf_transform_point(&mtxF, pos->x, pos->y, pos->z, &pos->x, &pos->y, &pos->z); angle = -((s16) (u16) arctan2_f(pos->x, pos->y)) * velocity; angle = (u16) (angle - (arg5 << 6)) - (u16) racer->x_rotation_vel; angle = angle > 0x8000 ? angle - 0xffff : angle; @@ -2174,7 +2174,7 @@ void update_camera_loop(f32 updateRateF, Object *obj, Object_Racer *racer) { f32 deltaX; f32 deltaY; f32 deltaZ; - Matrix mtx; + MtxF mtx; s32 angleDiff; UpdateRate = (s32) updateRateF; @@ -2202,14 +2202,14 @@ void update_camera_loop(f32 updateRateF, Object *obj, Object_Racer *racer) { gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_transform_to_matrix(mtx, &gCurrentRacerTransform); + mtxf_from_transform(&mtx, &gCurrentRacerTransform); - guMtxXFMF(mtx, 0.0f, 0.0f, gCameraObject->boomLength, &deltaX, &deltaY, &deltaZ); + mtxf_transform_point(&mtx, 0.0f, 0.0f, gCameraObject->boomLength, &deltaX, &deltaY, &deltaZ); gCameraObject->trans.x_position = obj->segment.trans.x_position + deltaX; gCameraObject->trans.y_position = obj->segment.trans.y_position + deltaY; gCameraObject->trans.z_position = obj->segment.trans.z_position + deltaZ; - guMtxXFMF(mtx, 0.0f, sins_f(0x800) * gCameraObject->boomLength, 0.0f, &deltaX, &deltaY, &deltaZ); + mtxf_transform_point(&mtx, 0.0f, sins_f(0x800) * gCameraObject->boomLength, 0.0f, &deltaX, &deltaY, &deltaZ); gCameraObject->trans.x_position += deltaX; gCameraObject->trans.y_position += deltaY; gCameraObject->trans.z_position += deltaZ; @@ -2484,7 +2484,7 @@ void update_player_racer(Object *obj, s32 updateRate) { D_8011D544 = 0.0f; } } else { - tempRacer->unk1C6 = get_random_number_from_range(-60, 60) + 120; + tempRacer->unk1C6 = rand_range(-60, 60) + 120; } if (tempRacer->unk18C > 0) { tempRacer->unk18C -= updateRate; @@ -2595,7 +2595,7 @@ void update_player_racer(Object *obj, s32 updateRate) { tempVar = tempRacer->unk18A & 0xF; tempRacer->unk18A -= updateRate; if (tempVar < (tempRacer->unk18A & 0xF)) { - tempRacer->unk1D1 = get_random_number_from_range(-80, 80); + tempRacer->unk1D1 = rand_range(-80, 80); } gCurrentStickX += tempRacer->unk1D1; } else { @@ -2971,7 +2971,7 @@ void func_8004F7F4(s32 updateRate, f32 updateRateF, Object *racerObj, Object_Rac f32 spA8; f32 spA4; f32 spA0; - Matrix sp60; + MtxF sp60; LevelHeader *currentLevelHeader; Object_Boost *asset20; s32 var_v1; @@ -3132,9 +3132,9 @@ void func_8004F7F4(s32 updateRate, f32 updateRateF, Object *racerObj, Object_Rac gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_inverse_transform_to_matrix(sp60, &gCurrentRacerTransform); - guMtxXFMF(sp60, racer->lateral_velocity, 0.0f, racer->velocity, &racerObj->segment.x_velocity, &spBC, - &racerObj->segment.z_velocity); + mtxf_from_inverse_transform(&sp60, &gCurrentRacerTransform); + mtxf_transform_point(&sp60, racer->lateral_velocity, 0.0f, racer->velocity, &racerObj->segment.x_velocity, + &spBC, &racerObj->segment.z_velocity); } if (racer->magnetTimer != 0) { racerObj->segment.x_velocity = gRacerMagnetVelX; @@ -3188,8 +3188,8 @@ void func_8004F7F4(s32 updateRate, f32 updateRateF, Object *racerObj, Object_Rac gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_inverse_transform_to_matrix(sp60, &gCurrentRacerTransform); - guMtxXFMF(sp60, spB8, 0.0f, spB4, &spAC, &spBC, &spB0); + mtxf_from_inverse_transform(&sp60, &gCurrentRacerTransform); + mtxf_transform_point(&sp60, spB8, 0.0f, spB4, &spAC, &spBC, &spB0); if (racer->unk1D2 != 0) { racer->unk1D2 -= updateRate; if (racer->unk1D2 < 0) { @@ -3229,11 +3229,11 @@ void func_8004F7F4(s32 updateRate, f32 updateRateF, Object *racerObj, Object_Rac } if (gCurrentPlayerIndex != PLAYER_COMPUTER && gNumViewports < 2) { if (racer->buoyancy > 14.0f) { - if (get_random_number_from_range(0, 1) != 0) { + if (rand_range(0, 1) != 0) { racerObj->particleEmittersEnabled |= PARTICLE_RANDOM_COLOUR_RED | PARTICLE_RANDOM_COLOUR_GREEN; } } else if (racer->buoyancy < 6.0f) { - if (racer->velocity > -3.0 && racer->velocity < 0.5 && get_random_number_from_range(0, 1) != 0) { + if (racer->velocity > -3.0 && racer->velocity < 0.5 && rand_range(0, 1) != 0) { racerObj->particleEmittersEnabled |= PARTICLE_RANDOM_SCALE_VELOCITY | PARTICLE_RANDOM_MOVEMENT_PARAM; } @@ -3424,7 +3424,7 @@ void func_80050A28(Object *obj, Object_Racer *racer, s32 updateRate, f32 updateR } } if ((racer->miscAnimCounter & 7) < 2) { - racer->unk1D1 = get_random_number_from_range(-25, 25); + racer->unk1D1 = rand_range(-25, 25); } gCurrentStickX += racer->unk1D1; } @@ -3882,7 +3882,7 @@ void handle_racer_head_turning(Object *obj, Object_Racer *racer, UNUSED s32 upda intendedAngle = 0x2800 - intendedAngle; - racer->headAngleTarget = get_random_number_from_range(-intendedAngle, intendedAngle); + racer->headAngleTarget = rand_range(-intendedAngle, intendedAngle); } } } @@ -4320,7 +4320,7 @@ void handle_car_steering(Object_Racer *racer) { } void func_800535C4(Object *obj, Object_Racer *racer) { - Matrix mf; + MtxF mf; gCurrentRacerTransform.rotation.y_rotation = -racer->steerVisualRotation; gCurrentRacerTransform.rotation.x_rotation = -obj->segment.trans.rotation.x_rotation; @@ -4329,9 +4329,9 @@ void func_800535C4(Object *obj, Object_Racer *racer) { gCurrentRacerTransform.y_position = 0; gCurrentRacerTransform.z_position = 0; gCurrentRacerTransform.scale = 1; - object_inverse_transform_to_matrix(mf, &gCurrentRacerTransform); + mtxf_from_inverse_transform(&mf, &gCurrentRacerTransform); - guMtxXFMF(mf, 0.0f, -1.0f, 0.0f, &racer->roll, &racer->yaw, &racer->pitch); + mtxf_transform_point(&mf, 0.0f, -1.0f, 0.0f, &racer->roll, &racer->yaw, &racer->pitch); } /** @@ -4567,7 +4567,7 @@ void update_onscreen_AI_racer(Object *obj, Object_Racer *racer, s32 updateRate, f32 xTemp; f32 yTemp; f32 zTemp; - Matrix mtx; + MtxF mtx; LevelHeader *header; s32 angle; s32 steerVel; @@ -4642,9 +4642,9 @@ void update_onscreen_AI_racer(Object *obj, Object_Racer *racer, s32 updateRate, gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_inverse_transform_to_matrix(mtx, &gCurrentRacerTransform); - guMtxXFMF(mtx, racer->lateral_velocity, 0.0f, racer->velocity, &obj->segment.x_velocity, &tempVel, - &obj->segment.z_velocity); + mtxf_from_inverse_transform(&mtx, &gCurrentRacerTransform); + mtxf_transform_point(&mtx, racer->lateral_velocity, 0.0f, racer->velocity, &obj->segment.x_velocity, &tempVel, + &obj->segment.z_velocity); } if (racer->magnetTimer) { obj->segment.x_velocity = gRacerMagnetVelX; @@ -4685,8 +4685,8 @@ void update_onscreen_AI_racer(Object *obj, Object_Racer *racer, s32 updateRate, gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_inverse_transform_to_matrix(mtx, &gCurrentRacerTransform); - guMtxXFMF(mtx, xVel, 0.0f, zVel, &hVel, &tempVel, &yVel); + mtxf_from_inverse_transform(&mtx, &gCurrentRacerTransform); + mtxf_transform_point(&mtx, xVel, 0.0f, zVel, &hVel, &tempVel, &yVel); if (racer->unk1D2 != 0) { racer->unk1D2 -= updateRate; if (racer->unk1D2 < 0) { @@ -4887,8 +4887,8 @@ void func_80054FD0(Object *racerObj, Object_Racer *racer, s32 updateRate) { f32 sp108[5]; f32 spF4[5]; f32 spE0[5]; - Matrix spA0; - Matrix sp60; + MtxF spA0; + MtxF sp60; s8 sp5C; s8 sp58[4]; @@ -4904,11 +4904,11 @@ void func_80054FD0(Object *racerObj, Object_Racer *racer, s32 updateRate) { gCurrentRacerTransform.x_position = racerObj->segment.trans.x_position; gCurrentRacerTransform.y_position = racerObj->segment.trans.y_position; gCurrentRacerTransform.z_position = racerObj->segment.trans.z_position; - object_transform_to_matrix(spA0, &gCurrentRacerTransform); + mtxf_from_transform(&spA0, &gCurrentRacerTransform); for (i = 0; i < 4; i++) { - guMtxXFMF(spA0, D_8011D568[i * 4 + 0], D_8011D568[i * 4 + 1], D_8011D568[i * 4 + 2], &sp134[i * 3 + 0], - &sp134[i * 3 + 1], &sp134[i * 3 + 2]); + mtxf_transform_point(&spA0, D_8011D568[i * 4 + 0], D_8011D568[i * 4 + 1], D_8011D568[i * 4 + 2], + &sp134[i * 3 + 0], &sp134[i * 3 + 1], &sp134[i * 3 + 2]); spE0[i] = D_8011D568[i * 4 + 3]; sp58[i] = -1; } @@ -5026,10 +5026,10 @@ void func_80054FD0(Object *racerObj, Object_Racer *racer, s32 updateRate) { gCurrentRacerTransform.x_position = -racerObj->segment.trans.x_position; gCurrentRacerTransform.y_position = -racerObj->segment.trans.y_position; gCurrentRacerTransform.z_position = -racerObj->segment.trans.z_position; - object_inverse_transform_to_matrix(sp60, &gCurrentRacerTransform); + mtxf_from_inverse_transform(&sp60, &gCurrentRacerTransform); for (i = 0; i < 4; i++) { - guMtxXFMF(sp60, ((f32 *) &racer->unkD8)[i * 3 + 0], ((f32 *) &racer->unkD8)[i * 3 + 1], - ((f32 *) &racer->unkD8)[i * 3 + 2], &sp11C[i], &sp108[i], &spF4[i]); + mtxf_transform_point(&sp60, ((f32 *) &racer->unkD8)[i * 3 + 0], ((f32 *) &racer->unkD8)[i * 3 + 1], + ((f32 *) &racer->unkD8)[i * 3 + 2], &sp11C[i], &sp108[i], &spF4[i]); } if (racer->vehicleID != VEHICLE_LOOPDELOOP) { sp180 = sp11C[0] + sp11C[1]; @@ -5681,13 +5681,13 @@ void play_random_character_voice(Object *obj, s32 soundID, s32 range, s32 flags) tempRacer->soundMask = 0; } } - if (tempRacer->soundMask == NULL && (flags != 3 || get_random_number_from_range(0, 1))) { + if (tempRacer->soundMask == NULL && (flags != 3 || rand_range(0, 1))) { tempRacer->unk2A = soundID; soundID += tempRacer->characterId; - soundIndex = (get_random_number_from_range(0, range - 1) * 12) + soundID; + soundIndex = (rand_range(0, range - 1) * 12) + soundID; if (range - 1 > 0) { while (soundIndex == tempRacer->lastSoundID) { - soundIndex = (get_random_number_from_range(0, range - 1) * 12) + soundID; + soundIndex = (rand_range(0, range - 1) * 12) + soundID; } } audspat_play_sound_at_position(soundIndex, obj->segment.trans.x_position, obj->segment.trans.y_position, @@ -5815,7 +5815,7 @@ f32 handle_racer_top_speed(Object *obj, Object_Racer *racer) { } void func_800575EC(Object *obj, Object_Racer *racer) { - Matrix mtxF; + MtxF mtxF; gCurrentRacerTransform.rotation.y_rotation = obj->segment.trans.rotation.y_rotation; gCurrentRacerTransform.rotation.x_rotation = obj->segment.trans.rotation.x_rotation; @@ -5824,10 +5824,10 @@ void func_800575EC(Object *obj, Object_Racer *racer) { gCurrentRacerTransform.y_position = 0.0f; gCurrentRacerTransform.z_position = 0.0f; gCurrentRacerTransform.scale = 1.0f; - object_transform_to_matrix(mtxF, &gCurrentRacerTransform); - guMtxXFMF(mtxF, 0.0f, 0.0f, 1.0f, &racer->ox1, &racer->oy1, &racer->oz1); - guMtxXFMF(mtxF, 0.0f, 1.0f, 0.0f, &racer->ox2, &racer->oy2, &racer->oz2); - guMtxXFMF(mtxF, 1.0f, 0.0f, 0.0f, &racer->ox3, &racer->oy3, &racer->oz3); + mtxf_from_transform(&mtxF, &gCurrentRacerTransform); + mtxf_transform_point(&mtxF, 0.0f, 0.0f, 1.0f, &racer->ox1, &racer->oy1, &racer->oz1); + mtxf_transform_point(&mtxF, 0.0f, 1.0f, 0.0f, &racer->ox2, &racer->oy2, &racer->oz2); + mtxf_transform_point(&mtxF, 1.0f, 0.0f, 0.0f, &racer->ox3, &racer->oy3, &racer->oz3); } /** @@ -5838,8 +5838,8 @@ void drop_bananas(Object *obj, Object_Racer *racer, s32 number) { LevelObjectEntryCommon newObject; Object_Banana *banana; s32 i; - s16 angle[3]; - s16 pos[3]; + RPYAngles angle; + Vec3s pos; Object *bananaObj; f32 variance; @@ -5849,16 +5849,16 @@ void drop_bananas(Object *obj, Object_Racer *racer, s32 number) { number = racer->bananas; } if (number > 0 && number < 3) { - angle[0] = racer->x_rotation_vel; - angle[1] = obj->segment.trans.rotation.x_rotation; - angle[2] = racer->steerVisualRotation; - pos[0] = 0; - pos[1] = 8; - pos[2] = 12; - s16_vec3_apply_object_rotation((ObjectTransform *) angle, pos); - newObject.x = pos[0] + (s32) obj->segment.trans.x_position; - newObject.y = pos[1] + (s32) obj->segment.trans.y_position; - newObject.z = pos[2] + (s32) obj->segment.trans.z_position; + angle.z_rotation = racer->x_rotation_vel; + angle.x_rotation = obj->segment.trans.rotation.x_rotation; + angle.y_rotation = racer->steerVisualRotation; + pos.x = 0; + pos.y = 8; + pos.z = 12; + vec3s_rotate_rpy(&angle, &pos); + newObject.x = pos.x + (s32) obj->segment.trans.x_position; + newObject.y = pos.y + (s32) obj->segment.trans.y_position; + newObject.z = pos.z + (s32) obj->segment.trans.z_position; newObject.size = sizeof(LevelObjectEntryCommon); newObject.objectID = ASSET_OBJECT_ID_COIN; i = number; @@ -6954,7 +6954,7 @@ void update_AI_racer(Object *obj, Object_Racer *racer, s32 updateRate, f32 updat racer->unk1F6 = 0; } if (gRaceStartTimer != 0) { - racer->unk1C6 = get_random_number_from_range(-60, 60) + 120; + racer->unk1C6 = rand_range(-60, 60) + 120; } if (racer->unk18C > 0) { racer->unk18C -= updateRate; diff --git a/src/rcp_dkr.c b/src/rcp_dkr.c index 1024f5ef..c6dcba48 100644 --- a/src/rcp_dkr.c +++ b/src/rcp_dkr.c @@ -21,7 +21,7 @@ TextureHeader *gTexBGTex1 = NULL; TextureHeader *gTexBGTex2 = NULL; s32 gChequerBGEnabled = FALSE; -BackgroundFunction gBGDrawFunc = { NULL }; +BackgroundFunction gBGDrawFunc = NULL; s32 gGfxBufCounter = 0; s32 gGfxBufCounter2 = 0; s32 gGfxTaskIsRunning = FALSE; @@ -407,7 +407,7 @@ void bgdraw_fillcolour(s32 red, s32 green, s32 blue) { * over clearing the colour buffer. * Official Name: rcpClearScreen */ -void bgdraw_render(Gfx **dList, MatrixS **mtx, s32 drawBG) { +void bgdraw_render(Gfx **dList, Mtx **mtx, s32 drawBG) { s32 widthAndHeight; s32 w; s32 h; @@ -435,8 +435,8 @@ void bgdraw_render(Gfx **dList, MatrixS **mtx, s32 drawBG) { bgdraw_chequer(dList); // Unused } else if (gTexBGTex1) { bgdraw_texture(dList); - } else if (gBGDrawFunc.ptr != NULL) { - gBGDrawFunc.function(dList, mtx); + } else if (gBGDrawFunc != NULL) { + gBGDrawFunc(dList, mtx); } else { gDPSetFillColor((*dList)++, sBackgroundFillColour); gDPFillRectangle((*dList)++, 0, 0, w - 1, h - 1); @@ -455,8 +455,8 @@ void bgdraw_render(Gfx **dList, MatrixS **mtx, s32 drawBG) { bgdraw_chequer(dList); // Unused } else if (gTexBGTex1) { bgdraw_texture(dList); - } else if (gBGDrawFunc.ptr != NULL) { - gBGDrawFunc.function(dList, mtx); + } else if (gBGDrawFunc != NULL) { + gBGDrawFunc(dList, mtx); } else { gDPSetFillColor((*dList)++, (GPACK_RGBA5551(sBGPrimColourR, sBGPrimColourG, sBGPrimColourB, 1) << 16) | GPACK_RGBA5551(sBGPrimColourR, sBGPrimColourG, sBGPrimColourB, 1)); @@ -530,7 +530,7 @@ void bgdraw_texture(Gfx **dList) { if (gTexBGTex2 == NULL) { // Fill the background with a single texture - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(gTexBGTex1->cmd), gTexBGTex1->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(gTexBGTex1->cmd), gTexBGTex1->numberOfCommands); videoWidth <<= 2; videoHeight <<= 2; texWidth = gTexBGTex1->width << 2; @@ -549,7 +549,7 @@ void bgdraw_texture(Gfx **dList) { } } else { // The screen is filled with alternating horizontal stripes of two textures - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(gTexBGTex1->cmd), gTexBGTex1->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(gTexBGTex1->cmd), gTexBGTex1->numberOfCommands); videoWidth <<= 2; videoHeight <<= 2; uly = 0; @@ -569,7 +569,7 @@ void bgdraw_texture(Gfx **dList) { xOffset = (xOffset + gTexBGShiftX) & (texWidth - 1); } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(gTexBGTex2->cmd), gTexBGTex2->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(gTexBGTex2->cmd), gTexBGTex2->numberOfCommands); // Width and height are mistakenly multiplied by 4 again, but it doesn't cause any issues videoWidth <<= 2; videoHeight <<= 2; @@ -656,8 +656,8 @@ void bgdraw_chequer(Gfx **dList) { * Sets the function pointer to whatever's passed through. * If nonzero, will override the background drawing section. */ -void bgdraw_set_func(void *func) { - gBGDrawFunc.ptr = func; +void bgdraw_set_func(BackgroundFunction func) { + gBGDrawFunc = func; } /** @@ -695,7 +695,7 @@ void texrect_draw(Gfx **dList, DrawTexture *element, s32 xPos, s32 yPos, u8 red, t = -(uly << 3); uly = 0; } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(tex->cmd), tex->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(tex->cmd), tex->numberOfCommands); gSPTextureRectangle((*dList)++, ulx, uly, lrx, lry, G_TX_RENDERTILE, s, t, 1024, 1024); } } @@ -741,7 +741,7 @@ void texrect_draw_scaled(Gfx **dList, DrawTexture *element, f32 xPos, f32 yPos, } gSPDisplayList((*dList)++, dScaledRectangleBaseModes); - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dmaDlist), numberOfGfxCommands(dTextureRectangleScaledOpa[0])); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dmaDlist), numberOfGfxCommands(dTextureRectangleScaledOpa[0])); gDPSetPrimColorRGBA((*dList)++, colour); bFlipX = flags & TEXRECT_FLIP_X; @@ -795,7 +795,7 @@ void texrect_draw_scaled(Gfx **dList, DrawTexture *element, f32 xPos, f32 yPos, uly = 0; } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(tex->cmd), tex->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(tex->cmd), tex->numberOfCommands); gSPTextureRectangle((*dList)++, ulx, uly, lrx, lry, G_TX_RENDERTILE, s, t, dsdx, dtdy); } } diff --git a/src/rcp_dkr.h b/src/rcp_dkr.h index dc515bf1..921db31a 100644 --- a/src/rcp_dkr.h +++ b/src/rcp_dkr.h @@ -20,10 +20,7 @@ enum TextureRectangleFlags { TEXRECT_FLIP_Y = (1 << 13), }; -typedef union { - void (*function)(Gfx **, MatrixS **); - void *ptr; -} BackgroundFunction; +typedef s32 (*BackgroundFunction)(Gfx **, Mtx **); typedef struct DKR_OSTask { struct DKR_OSTask *next; @@ -74,8 +71,8 @@ void gfxtask_run_fifo(Gfx* dlBegin, Gfx* dlEnd, s32 recvMesg); void texrect_draw(Gfx **dList, DrawTexture *element, s32 xPos, s32 yPos, u8 red, u8 green, u8 blue, u8 alpha); void bgdraw_chequer(Gfx** dList); -void bgdraw_render(Gfx **dList, MatrixS **mtx, s32 drawBG); -void bgdraw_set_func(void *func); +void bgdraw_render(Gfx **dList, Mtx **mtx, s32 drawBG); +void bgdraw_set_func(BackgroundFunction func); void texrect_draw_scaled(Gfx **dList, DrawTexture *element, f32 xPos, f32 yPos, f32 xScale, f32 yScale, u32 colour, s32 flags); diff --git a/src/screen_asset.c b/src/screen_asset.c index af3f31c8..de2e14ab 100644 --- a/src/screen_asset.c +++ b/src/screen_asset.c @@ -64,7 +64,7 @@ UNUSED void screenimage_draw(Gfx **dList, u8 *screenAddress) { y_pos = 0; while (y_pos != SCREEN_HEIGHT) { // Load the texture. - gDPLoadTextureBlockS((*dList)++, OS_PHYSICAL_TO_K0(screenAddress), G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, + gDPLoadTextureBlockS((*dList)++, OS_K0_TO_PHYSICAL(screenAddress), G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, SCREEN_HEIGHT_PART, 0, G_TX_CLAMP, G_TX_CLAMP, 0, 0, 0, 0); // Draw the texture. diff --git a/src/textures_sprites.c b/src/textures_sprites.c index 09038b60..634a868d 100644 --- a/src/textures_sprites.c +++ b/src/textures_sprites.c @@ -647,7 +647,7 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) flags |= texhead->flags; if (texhead != gCurrentTextureHeader) { - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(texhead->cmd), texhead->numberOfCommands); + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(texhead->cmd), texhead->numberOfCommands); gCurrentTextureHeader = texhead; doPipeSync = FALSE; } @@ -695,14 +695,14 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) if (flags & RENDER_VTX_ALPHA) { gDkrDmaDisplayList( (*dList)++, - OS_PHYSICAL_TO_K0( + OS_K0_TO_PHYSICAL( dRenderSettingsSolidColourVtxAlpha[flags & (RENDER_ANTI_ALIASING | RENDER_Z_COMPARE)]), numberOfGfxCommands(dRenderSettingsSolidColourVtxAlpha[0])); return; } gDkrDmaDisplayList( (*dList)++, - OS_PHYSICAL_TO_K0(dRenderSettingsSolidColour[flags & (RENDER_FOG_ACTIVE | RENDER_SEMI_TRANSPARENT | + OS_K0_TO_PHYSICAL(dRenderSettingsSolidColour[flags & (RENDER_FOG_ACTIVE | RENDER_SEMI_TRANSPARENT | RENDER_Z_COMPARE | RENDER_ANTI_ALIASING)]), numberOfGfxCommands(dRenderSettingsSolidColour[0])); return; @@ -720,14 +720,14 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) if (flags & RENDER_COLOUR_INDEX) { dlIndex |= 4; // Colour Index } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsPrimOverlay[dlIndex]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsPrimOverlay[dlIndex]), numberOfGfxCommands(dRenderSettingsPrimOverlay[0])); return; } if (flags & RENDER_COLOUR_INDEX) { flags = (flags ^ RENDER_COLOUR_INDEX) | RENDER_FOG_ACTIVE; } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsPrimCol[flags]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsPrimCol[flags]), numberOfGfxCommands(dRenderSettingsPrimCol[0])); return; } @@ -746,7 +746,7 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) if (flags & RENDER_COLOUR_INDEX) { dlIndex |= 8; // Colour Index } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsDecal[dlIndex]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsDecal[dlIndex]), numberOfGfxCommands(dRenderSettingsDecal[0])); return; } @@ -756,7 +756,7 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) if (flags & RENDER_FOG_ACTIVE) { dlIndex |= 8; // Fog } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsCutout[dlIndex]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsCutout[dlIndex]), numberOfGfxCommands(dRenderSettingsCutout[0])); return; } @@ -770,12 +770,12 @@ void material_set(Gfx **dList, TextureHeader *texhead, s32 flags, s32 texOffset) gSPSetGeometryMode((*dList)++, G_ZBUFFER); gCurrentRenderFlags |= RENDER_Z_COMPARE; } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsVtxAlpha[dlIndex]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsVtxAlpha[dlIndex]), numberOfGfxCommands(dRenderSettingsVtxAlpha[0])); return; } - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsCommon[flags]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsCommon[flags]), numberOfGfxCommands(dRenderSettingsCommon[0])); return; } @@ -852,15 +852,15 @@ void material_load_simple(Gfx **dList, s32 flags) { flags &= ~RENDER_DECAL; if (gSpriteOpaque == FALSE) { if (gCurrentRenderFlags & RENDER_PRESERVE_COVERAGE) { - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsSpriteCld[(flags >> 1) & 1]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsSpriteCld[(flags >> 1) & 1]), numberOfGfxCommands(dRenderSettingsSpriteCld[0])); } else { // fake ^ 0 required for some reason - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsSpriteXlu[(flags - 16) ^ 0]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsSpriteXlu[(flags - 16) ^ 0]), numberOfGfxCommands(dRenderSettingsSpriteXlu[0])); } } else { - gDkrDmaDisplayList((*dList)++, OS_PHYSICAL_TO_K0(dRenderSettingsCommon[flags]), + gDkrDmaDisplayList((*dList)++, OS_K0_TO_PHYSICAL(dRenderSettingsCommon[flags]), numberOfGfxCommands(dRenderSettingsCommon[0])); } gCurrentTextureHeader = NULL; @@ -1402,14 +1402,14 @@ void material_init(TextureHeader *tex, Gfx *_dList) { if (!(tex->flags & RENDER_LINE_SWAP)) { // If it is not swapped, then use the regular loadTexBlock macros. if (texFormat == TEX_FORMAT_RGBA32) { - gDPLoadTextureBlock(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, cms, + gDPLoadTextureBlock(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); if (texRenderMode == TRANSPARENT || texRenderMode == TRANSPARENT_2) { tex->flags |= RENDER_SEMI_TRANSPARENT; } } if (texFormat == TEX_FORMAT_RGBA16) { - gDPLoadTextureBlock(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, cms, + gDPLoadTextureBlock(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); if (texRenderMode == TRANSPARENT || texRenderMode == TRANSPARENT_2) { tex->flags |= RENDER_SEMI_TRANSPARENT; @@ -1417,7 +1417,7 @@ void material_init(TextureHeader *tex, Gfx *_dList) { } if (texFormat == TEX_FORMAT_CI4) { texLut = tex_palette_id(tex->ciPaletteOffset); - gDPLoadTextureBlock_4b(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_CI, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4b(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_CI, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); gDPLoadTLUT_pal16(dList++, 0, texLut); @@ -1427,40 +1427,40 @@ void material_init(TextureHeader *tex, Gfx *_dList) { } } if (texFormat == TEX_FORMAT_IA16) { - gDPLoadTextureBlock(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, G_IM_SIZ_16b, width, height, 0, cms, + gDPLoadTextureBlock(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, G_IM_SIZ_16b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_IA8) { - gDPLoadTextureBlock(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, cms, + gDPLoadTextureBlock(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_IA4) { - gDPLoadTextureBlock_4b(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4b(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_I8) { - gDPLoadTextureBlock(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_I, G_IM_SIZ_8b, width, height, 0, cms, + gDPLoadTextureBlock(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_I, G_IM_SIZ_8b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); } if (texFormat == TEX_FORMAT_I4) { - gDPLoadTextureBlock_4b(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_I, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4b(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_I, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); } tex->numberOfCommands = dList - tex->cmd; } else { // Textures are swapped, so we need to use the LoadTextureBlockS macros. if (texFormat == TEX_FORMAT_RGBA32) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); if (texRenderMode == TRANSPARENT || texRenderMode == TRANSPARENT_2) { tex->flags |= RENDER_SEMI_TRANSPARENT; } } if (texFormat == TEX_FORMAT_RGBA16) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); if (texRenderMode == TRANSPARENT || texRenderMode == TRANSPARENT_2) { tex->flags |= RENDER_SEMI_TRANSPARENT; @@ -1468,7 +1468,7 @@ void material_init(TextureHeader *tex, Gfx *_dList) { } if (texFormat == TEX_FORMAT_CI4) { texLut = tex_palette_id(tex->ciPaletteOffset); - gDPLoadTextureBlock_4bS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_CI, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4bS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_CI, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); gDPLoadTLUT_pal16(dList++, 0, texLut); @@ -1478,26 +1478,26 @@ void material_init(TextureHeader *tex, Gfx *_dList) { } } if (texFormat == TEX_FORMAT_IA16) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, G_IM_SIZ_16b, width, height, 0, cms, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, G_IM_SIZ_16b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_IA8) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, cms, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_IA4) { - gDPLoadTextureBlock_4bS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_IA, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4bS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_IA, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); tex->flags |= RENDER_SEMI_TRANSPARENT; } if (texFormat == TEX_FORMAT_I8) { - gDPLoadTextureBlockS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_I, G_IM_SIZ_8b, width, height, 0, cms, + gDPLoadTextureBlockS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_I, G_IM_SIZ_8b, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); } if (texFormat == TEX_FORMAT_I4) { - gDPLoadTextureBlock_4bS(dList++, OS_PHYSICAL_TO_K0(tex + 1), G_IM_FMT_I, width, height, 0, cms, cmt, masks, + gDPLoadTextureBlock_4bS(dList++, OS_K0_TO_PHYSICAL(tex + 1), G_IM_FMT_I, width, height, 0, cms, cmt, masks, maskt, G_TX_NOLOD, G_TX_NOLOD); } tex->numberOfCommands = dList - tex->cmd; @@ -1525,7 +1525,7 @@ void tex_animate_texture(TextureHeader *texture, u32 *triangleBatchInfoFlags, s3 bit25Set = *triangleBatchInfoFlags & RENDER_UNK_2000000; if (bit23Set) { if (!bit25Set) { - if (get_random_number_from_range(0, 1000) > 985) { + if (rand_range(0, 1000) > 985) { *triangleBatchInfoFlags &= ~RENDER_UNK_4000000; *triangleBatchInfoFlags |= RENDER_UNK_2000000; } @@ -1715,7 +1715,7 @@ void gfx_init_basic_xlu(Gfx **dList, u32 index, u32 primitiveColor, u32 environm gfxTemp = *dList; gSPDisplayList(gfxTemp++, tempDlist); - gDkrDmaDisplayList(gfxTemp++, OS_PHYSICAL_TO_K0(dBasicRenderModes[tempIndex]), + gDkrDmaDisplayList(gfxTemp++, OS_K0_TO_PHYSICAL(dBasicRenderModes[tempIndex]), numberOfGfxCommands(dBasicRenderModes[0])); gDPSetPrimColorRGBA(gfxTemp++, primitiveColor); gDPSetEnvColorRGBA(gfxTemp++, environmentColor); diff --git a/src/thread3_main.c b/src/thread3_main.c index f1f43874..dc6670a4 100644 --- a/src/thread3_main.c +++ b/src/thread3_main.c @@ -103,8 +103,8 @@ FadeTransition D_800DD424 = FADE_TRANSITION(FADE_FULLSCREEN, FADE_FLAG_NONE, FAD Gfx *gDisplayLists[2]; Gfx *gCurrDisplayList; UNUSED s32 D_801211FC; -MatrixS *gMatrixHeap[2]; -MatrixS *gGameCurrMatrix; +Mtx *gMatrixHeap[2]; +Mtx *gGameCurrMatrix; Vertex *gVertexHeap[2]; Vertex *gGameCurrVertexList; Triangle *gTriangleHeap[2]; @@ -1375,7 +1375,7 @@ void alloc_displaylist_heap(s32 numberOfPlayers) { mempool_free_timer(0); mempool_free(gDisplayLists[0]); mempool_free(gDisplayLists[1]); - totalSize = ((gNumF3dCmdsPerPlayer[num] * sizeof(Gwords))) + ((gNumHudMatPerPlayer[num] * sizeof(Matrix))) + + totalSize = ((gNumF3dCmdsPerPlayer[num] * sizeof(Gfx))) + ((gNumHudMatPerPlayer[num] * sizeof(Mtx))) + ((gNumHudVertsPerPlayer[num] * sizeof(Vertex))) + ((gNumHudTrisPerPlayer[num] * sizeof(Triangle))); gDisplayLists[0] = (Gfx *) mempool_alloc_fixed(totalSize, (u8 *) gDisplayLists[0], COLOUR_TAG_RED); gDisplayLists[1] = (Gfx *) mempool_alloc_fixed(totalSize, (u8 *) gDisplayLists[1], COLOUR_TAG_YELLOW); @@ -1390,11 +1390,11 @@ void alloc_displaylist_heap(s32 numberOfPlayers) { } default_alloc_displaylist_heap(); } - gMatrixHeap[0] = (MatrixS *) ((u8 *) gDisplayLists[0] + ((gNumF3dCmdsPerPlayer[num] * sizeof(Gwords)))); - gTriangleHeap[0] = (Triangle *) ((u8 *) gMatrixHeap[0] + ((gNumHudMatPerPlayer[num] * sizeof(Matrix)))); + gMatrixHeap[0] = (Mtx *) ((u8 *) gDisplayLists[0] + ((gNumF3dCmdsPerPlayer[num] * sizeof(Gfx)))); + gTriangleHeap[0] = (Triangle *) ((u8 *) gMatrixHeap[0] + ((gNumHudMatPerPlayer[num] * sizeof(Mtx)))); gVertexHeap[0] = (Vertex *) ((u8 *) gTriangleHeap[0] + ((gNumHudTrisPerPlayer[num] * sizeof(Triangle)))); - gMatrixHeap[1] = (MatrixS *) ((u8 *) gDisplayLists[1] + ((gNumF3dCmdsPerPlayer[num] * sizeof(Gwords)))); - gTriangleHeap[1] = (Triangle *) ((u8 *) gMatrixHeap[1] + ((gNumHudMatPerPlayer[num] * sizeof(Matrix)))); + gMatrixHeap[1] = (Mtx *) ((u8 *) gDisplayLists[1] + ((gNumF3dCmdsPerPlayer[num] * sizeof(Gfx)))); + gTriangleHeap[1] = (Triangle *) ((u8 *) gMatrixHeap[1] + ((gNumHudMatPerPlayer[num] * sizeof(Mtx)))); gVertexHeap[1] = (Vertex *) ((u8 *) gTriangleHeap[1] + ((gNumHudTrisPerPlayer[num] * sizeof(Triangle)))); gCurrNumF3dCmdsPerPlayer = gNumF3dCmdsPerPlayer[num]; gCurrNumHudMatPerPlayer = gNumHudMatPerPlayer[num]; @@ -1432,19 +1432,19 @@ void default_alloc_displaylist_heap(void) { numberOfPlayers = FOUR_PLAYERS; gPrevPlayerCount = numberOfPlayers; - totalSize = (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gwords)) + - (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Matrix)) + + totalSize = (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gfx)) + + (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Mtx)) + (gNumHudVertsPerPlayer[numberOfPlayers] * sizeof(Vertex)) + (gNumHudTrisPerPlayer[numberOfPlayers] * sizeof(Triangle)); gDisplayLists[0] = (Gfx *) mempool_alloc_safe(totalSize, COLOUR_TAG_RED); - gMatrixHeap[0] = (MatrixS *) ((u8 *) gDisplayLists[0] + (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gwords))); - gVertexHeap[0] = (Vertex *) ((u8 *) gMatrixHeap[0] + (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Matrix))); + gMatrixHeap[0] = (Mtx *) ((u8 *) gDisplayLists[0] + (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gfx))); + gVertexHeap[0] = (Vertex *) ((u8 *) gMatrixHeap[0] + (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Mtx))); gTriangleHeap[0] = (Triangle *) ((u8 *) gVertexHeap[0] + (gNumHudVertsPerPlayer[numberOfPlayers] * sizeof(Vertex))); gDisplayLists[1] = (Gfx *) mempool_alloc_safe(totalSize, COLOUR_TAG_YELLOW); - gMatrixHeap[1] = (MatrixS *) ((u8 *) gDisplayLists[1] + (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gwords))); - gVertexHeap[1] = (Vertex *) ((u8 *) gMatrixHeap[1] + (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Matrix))); + gMatrixHeap[1] = (Mtx *) ((u8 *) gDisplayLists[1] + (gNumF3dCmdsPerPlayer[numberOfPlayers] * sizeof(Gfx))); + gVertexHeap[1] = (Vertex *) ((u8 *) gMatrixHeap[1] + (gNumHudMatPerPlayer[numberOfPlayers] * sizeof(Mtx))); gTriangleHeap[1] = (Triangle *) ((u8 *) gVertexHeap[1] + (gNumHudVertsPerPlayer[numberOfPlayers] * sizeof(Vertex))); gCurrNumF3dCmdsPerPlayer = gNumF3dCmdsPerPlayer[numberOfPlayers]; diff --git a/src/tracks.c b/src/tracks.c index 8f53b4f9..58eaf7a2 100644 --- a/src/tracks.c +++ b/src/tracks.c @@ -65,7 +65,7 @@ u8 D_800DC92C[24] = { /************ .bss ************/ Gfx *gSceneCurrDisplayList; -MatrixS *gSceneCurrMatrix; +Mtx *gSceneCurrMatrix; Vertex *gSceneCurrVertexList; Triangle *gSceneCurrTriList; @@ -286,7 +286,7 @@ void init_track(u32 geometry, u32 skybox, s32 numberOfPlayers, Vehicle vehicle, * The root function for rendering the entire scene. * Handles drawing the track, objects and the majority of the HUD in single player. */ -void render_scene(Gfx **dList, MatrixS **mtx, Vertex **vtx, Triangle **tris, s32 updateRate) { +void render_scene(Gfx **dList, Mtx **mtx, Vertex **vtx, Triangle **tris, s32 updateRate) { s32 i; s32 numViewports; s32 tempUpdateRate; @@ -2198,7 +2198,7 @@ void func_8002A31C(void) { f32 ox3; f32 oy3; f32 oz3; - Matrix *cameraMatrix; + MtxF *cameraMatrix; f32 inverseMagnitude; f32 x; f32 y; @@ -2214,21 +2214,21 @@ void func_8002A31C(void) { ox1 = x; oy1 = y; oz1 = z; - guMtxXFMF(*cameraMatrix, x, y, z, &ox1, &oy1, &oz1); + mtxf_transform_point(cameraMatrix, x, y, z, &ox1, &oy1, &oz1); x = D_800DC8AC[i][1].x; y = D_800DC8AC[i][1].y; z = D_800DC8AC[i][1].z; ox2 = x; oy2 = y; oz2 = z; - guMtxXFMF(*cameraMatrix, x, y, z, &ox2, &oy2, &oz2); + mtxf_transform_point(cameraMatrix, x, y, z, &ox2, &oy2, &oz2); x = D_800DC8AC[i][2].x; y = D_800DC8AC[i][2].y; z = D_800DC8AC[i][2].z; ox3 = x; oy3 = y; oz3 = z; - guMtxXFMF(*cameraMatrix, x, y, z, &ox3, &oy3, &oz3); + mtxf_transform_point(cameraMatrix, x, y, z, &ox3, &oy3, &oz3); x = ((oz2 - oz3) * oy1) + (oy2 * (oz3 - oz1)) + (oy3 * (oz1 - oz2)); y = ((ox2 - ox3) * oz1) + (oz2 * (ox3 - ox1)) + (oz3 * (ox1 - ox2)); z = ((oy2 - oy3) * ox1) + (ox2 * (oy3 - oy1)) + (ox3 * (oy1 - oy2)); @@ -3590,10 +3590,10 @@ void func_8002DE30(Object *obj) { } } if (maxYPos >= sp90 && sp94 >= minYPos) { - if (point_triangle_2d_xz_intersection( - obj->segment.trans.x_position, obj->segment.trans.z_position, - &vertices[triangle->verticesArray[1]].x, &vertices[triangle->verticesArray[2]].x, - &vertices[triangle->verticesArray[3]].x)) { + if (tri2d_xz_contains_point(obj->segment.trans.x_position, obj->segment.trans.z_position, + &vertices[triangle->verticesArray[1]].x, + &vertices[triangle->verticesArray[2]].x, + &vertices[triangle->verticesArray[3]].x)) { foundResult = TRUE; obj->shading->unk0 += (((1.0f - D_800DC884[batchFlags]) - obj->shading->unk0) * 0.2); } @@ -4473,7 +4473,7 @@ UNUSED void update_perspective_and_envmap(void) { * Take the current camera position and calculate the perspective position, for envmapping. */ void compute_scene_camera_transform_matrix(void) { - Matrix mtx; + MtxF mtx; ObjectTransform trans; f32 x = 0.0f; @@ -4488,8 +4488,8 @@ void compute_scene_camera_transform_matrix(void) { trans.z_position = 0.0f; trans.scale = 1.0f; - object_transform_to_matrix(mtx, &trans); - guMtxXFMF(mtx, x, y, z, &x, &y, &z); + mtxf_from_transform(&mtx, &trans); + mtxf_transform_point(&mtx, x, y, z, &x, &y, &z); // Store x/y/z as integers gScenePerspectivePos.x = x; diff --git a/src/tracks.h b/src/tracks.h index e94f9ac4..95f28a73 100644 --- a/src/tracks.h +++ b/src/tracks.h @@ -159,7 +159,7 @@ void obj_loop_fogchanger(Object* obj); void initialise_player_viewport_vars(s32 updateRate); s32 get_wave_properties(f32 yPos, f32 *waterHeight, Vec3f *rotation); void render_level_segment(s32 segmentId, s32 nonOpaque); -void render_scene(Gfx** dList, MatrixS** mtx, Vertex** vtx, Triangle** tris, s32 updateRate); +void render_scene(Gfx** dList, Mtx** mtx, Vertex** vtx, Triangle** tris, s32 updateRate); void set_fog(s32 fogIdx, s16 near, s16 far, u8 red, u8 green, u8 blue); void slowly_change_fog(s32 fogIdx, s32 red, s32 green, s32 blue, s32 near, s32 far, s32 switchTimer); s32 func_8002FD74(f32 x0, f32 z0, f32 x1, f32 x2, s32 count, Vec4f *arg5); @@ -179,7 +179,7 @@ void initialise_player_viewport_vars(s32); void func_8002A31C(void); void update_colour_cycle(LevelHeader_70 *arg0, s32 updateRate); void waves_update(s32); -void waves_render(Gfx**, MatrixS**, s32); +void waves_render(Gfx**, Mtx**, s32); void func_8002DE30(Object*); void shadow_generate(Object*, s32); void func_8002E904(LevelModelSegment *, s32, s32 arg2); diff --git a/src/vehicle_smokey.c b/src/vehicle_smokey.c index a0c9bfb8..4efa9f06 100644 --- a/src/vehicle_smokey.c +++ b/src/vehicle_smokey.c @@ -317,7 +317,7 @@ void spawn_boss_hazard(Object *obj, Object_Racer *racer, f32 offset, s32 objectI newObj->segment.z_velocity = obj->segment.z_velocity; newObj->properties.racer.unk0 = tempObj; newObj->properties.racer.unk4 = (s8) entry->animation.y_rotation * 60; - newObj->segment.animFrame = get_random_number_from_range(0, 255); + newObj->segment.animFrame = rand_range(0, 255); audspat_play_sound_at_position(soundID, newObj->segment.trans.x_position, newObj->segment.trans.y_position, newObj->segment.trans.z_position, 4, NULL); diff --git a/src/vehicle_tricky.c b/src/vehicle_tricky.c index c4ceb017..f52abfc4 100644 --- a/src/vehicle_tricky.c +++ b/src/vehicle_tricky.c @@ -227,7 +227,7 @@ void set_boss_voice_clip_offset(u16 *soundID) { * Also has worldspace values. */ void racer_boss_sound_spatial(f32 x, f32 y, f32 z, s32 offset) { - s8 randomOffset = get_random_number_from_range(0, 1); + s8 randomOffset = rand_range(0, 1); if (offset == 0) { randomOffset = 0; } @@ -239,7 +239,7 @@ void racer_boss_sound_spatial(f32 x, f32 y, f32 z, s32 offset) { * Add a random amount to offset, then play a random voice clip within that range. */ void play_random_boss_sound(s32 offset) { - s8 randomOffset = get_random_number_from_range(0, 1); + s8 randomOffset = rand_range(0, 1); if (offset == 0) { randomOffset = 0; } diff --git a/src/waves.c b/src/waves.c index 76e47945..06539a26 100644 --- a/src/waves.c +++ b/src/waves.c @@ -64,7 +64,7 @@ const char D_800E91AC[] = "\n\nBlock may be specified using 'P' on water group n /************ .bss ************/ Gfx *gWaveDL; -MatrixS *gWaveMtx; +Mtx *gWaveMtx; WaveControl gWaveController; // holds lots of control information used in this file s32 gWaveVertexFlip; // either 1 or 0, toggled in waves_update, used to index vertices and triangles f32 gWaveLowerY; // is set to lowest value of gWaveHeightTable @@ -280,13 +280,13 @@ void waves_init(LevelModel *model, LevelHeader *header, s32 playerCount) { sineVar2 += sineStep2; }; save_rng_seed(); - set_rng_seed(0x57415646); + set_rng_seed('WAVF'); var_s5 = 0; for (i_2 = 0; i_2 < gWaveController.tileCount; i_2++) { for (j_2 = 0; j_2 < gWaveController.tileCount; j_2++) { - gWaveHeightIndices[var_s5].s[0] = get_random_number_from_range(0, gWaveController.seedSize - 1); - gWaveHeightIndices[var_s5].s[1] = get_random_number_from_range(0, gWaveController.seedSize - 1); + gWaveHeightIndices[var_s5].s[0] = rand_range(0, gWaveController.seedSize - 1); + gWaveHeightIndices[var_s5].s[1] = rand_range(0, gWaveController.seedSize - 1); var_s5++; } } @@ -945,15 +945,15 @@ void wave_load_material(TextureHeader *tex, s32 rtile) { // difference is G_IM_SIZ_32b vs G_IM_SIZ_16b if (TEX_FORMAT(tex->format) == TEX_FORMAT_RGBA32) { - gDPLoadMultiBlock(gWaveDL++, OS_PHYSICAL_TO_K0(tex + 1), tmem, rtile, G_IM_FMT_RGBA, G_IM_SIZ_32b, texWidth, + gDPLoadMultiBlock(gWaveDL++, OS_K0_TO_PHYSICAL(tex + 1), tmem, rtile, G_IM_FMT_RGBA, G_IM_SIZ_32b, texWidth, texWidth, 0, 0, 0, txmask, txmask, 0, 0); } else { - gDPLoadMultiBlock(gWaveDL++, OS_PHYSICAL_TO_K0(tex + 1), tmem, rtile, G_IM_FMT_RGBA, G_IM_SIZ_16b, texWidth, + gDPLoadMultiBlock(gWaveDL++, OS_K0_TO_PHYSICAL(tex + 1), tmem, rtile, G_IM_FMT_RGBA, G_IM_SIZ_16b, texWidth, texWidth, 0, 0, 0, txmask, txmask, 0, 0); } } -void waves_render(Gfx **dList, MatrixS **mtx, s32 viewportID) { +void waves_render(Gfx **dList, Mtx **mtx, s32 viewportID) { s32 sp11C; Vertex *vtx; Triangle *tri; diff --git a/src/weather.c b/src/weather.c index 0eb2afa9..1b3cf97a 100644 --- a/src/weather.c +++ b/src/weather.c @@ -132,11 +132,11 @@ s32 gSnowVertOffset; s32 gSnowTriCount; s32 gSnowVertexFlip; Gfx *gCurrWeatherDisplayList; -MatrixS *gCurrWeatherMatrix; +Mtx *gCurrWeatherMatrix; Vertex *gCurrWeatherVertexList; Triangle *gCurrWeatherTriList; Camera *gWeatherCamera; -Matrix *gWeatherCameraMatrix; +MtxF *gWeatherCameraMatrix; LensFlareData *gLensFlareSet1; LensFlareData *gLensFlareSet2; LensFlareData *gLensFlareLarge; @@ -287,13 +287,13 @@ void weather_reset(s32 weatherType, s32 density, s32 velX, s32 velY, s32 velZ, s gSnowTriIndices = (s16 *) mempool_alloc_safe(numOfElements * (sizeof(s16)), COLOUR_TAG_LIGHT_ORANGE); gSnowPhysics = (SnowPosData *) mempool_alloc_safe(numOfElements * (sizeof(SnowPosData)), COLOUR_TAG_LIGHT_ORANGE); for (i = 0; i < gSnowDensity; i++) { - gSnowPhysics[i].x_position = get_random_number_from_range(0, gSnowGfx.radiusX); - gSnowPhysics[i].y_position = get_random_number_from_range(0, gSnowGfx.radiusY); - gSnowPhysics[i].z_position = get_random_number_from_range(0, gSnowGfx.radiusZ); - gSnowPhysics[i].unused_C = 1 << (get_random_number_from_range(0, 32) + 5); - gSnowPhysics[i].unused_D = 1 << (get_random_number_from_range(0, 32) + 5); - gSnowPhysics[i].unused_E = 1 << (get_random_number_from_range(0, 32) + 5); - gSnowPhysics[i].index = get_random_number_from_range(0, gSnowGfx.size - 1); + gSnowPhysics[i].x_position = rand_range(0, gSnowGfx.radiusX); + gSnowPhysics[i].y_position = rand_range(0, gSnowGfx.radiusY); + gSnowPhysics[i].z_position = rand_range(0, gSnowGfx.radiusZ); + gSnowPhysics[i].unused_C = 1 << (rand_range(0, 32) + 5); + gSnowPhysics[i].unused_D = 1 << (rand_range(0, 32) + 5); + gSnowPhysics[i].unused_E = 1 << (rand_range(0, 32) + 5); + gSnowPhysics[i].index = rand_range(0, gSnowGfx.size - 1); } numOfElements = numOfElements * 4; @@ -395,7 +395,7 @@ void weather_set(s32 velX, s32 velY, s32 velZ, s32 intensity, s32 opacity, s32 t * The root function for handling all weather. * Decide whether to perform rain or snow logic, execute it, then set it to render right after. */ -void weather_update(Gfx **currDisplayList, MatrixS **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, +void weather_update(Gfx **currDisplayList, Mtx **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate) { UNUSED s32 unused; gCurrWeatherDisplayList = *currDisplayList; @@ -471,7 +471,7 @@ void snow_update(s32 updateRate) { */ void snow_vertices(void) { s16 pos[3]; - f32 posF[3]; + Vec3f posF; s32 i; Vertex *verts; s32 camX; @@ -484,14 +484,14 @@ void snow_vertices(void) { gSnowVertCount = 0; verts = gSnowVerts; for (i = 0; i < gSnowParticleCount; i++) { - posF[0] = (((gSnowPhysics[i].x_position - camX) & gSnowGfx.radiusX) + gSnowGfx.offsetX) * (1.0f / 65536.0f); - posF[1] = (((gSnowPhysics[i].y_position - camy) & gSnowGfx.radiusY) + gSnowGfx.offsetY) * (1.0f / 65536.0f); - posF[2] = (((gSnowPhysics[i].z_position - camz) & gSnowGfx.radiusZ) + gSnowGfx.offsetZ) * (1.0f / 65536.0f); - f32_matrix_dot(gWeatherCameraMatrix, (Matrix *) &posF, (Matrix *) &posF); - pos[2] = posF[2]; + posF.f[0] = (((gSnowPhysics[i].x_position - camX) & gSnowGfx.radiusX) + gSnowGfx.offsetX) * (1.0f / 65536.0f); + posF.f[1] = (((gSnowPhysics[i].y_position - camy) & gSnowGfx.radiusY) + gSnowGfx.offsetY) * (1.0f / 65536.0f); + posF.f[2] = (((gSnowPhysics[i].z_position - camz) & gSnowGfx.radiusZ) + gSnowGfx.offsetZ) * (1.0f / 65536.0f); + mtxf_transform_dir(gWeatherCameraMatrix, &posF, &posF); + pos[2] = posF.f[2]; if (pos[2] < gSnowPlane.near && gSnowPlane.current < pos[2]) { - pos[0] = posF[0]; - pos[1] = posF[1]; + pos[0] = posF.f[0]; + pos[1] = posF.f[1]; verts[0].x = pos[0] - gSnowGfx.vertOffsetW; verts[0].y = pos[1] + gSnowGfx.vertOffsetH; verts[0].z = pos[2]; @@ -516,27 +516,27 @@ void snow_vertices(void) { */ void snow_render(void) { s32 i; - u32 mtx; - u32 vtx; + Mtx *mtx; + Vertex *vtx; if (gSnowGfx.texture != NULL) { gSnowVertOffset = 4; gSnowTriCount = 2; if (gSnowVertCount >= 4) { i = 0; - mtx = (u32) get_projection_matrix_s16(); - gSPMatrixDKR(gCurrWeatherDisplayList++, OS_PHYSICAL_TO_K0(mtx ^ 0), G_MTX_DKR_INDEX_0); + mtx = get_projection_matrix_s16(); + gSPMatrixDKR(gCurrWeatherDisplayList++, OS_K0_TO_PHYSICAL(mtx), G_MTX_DKR_INDEX_0); gSPSelectMatrixDKR(gCurrWeatherDisplayList++, G_MTX_DKR_INDEX_0); material_set_no_tex_offset(&gCurrWeatherDisplayList, gSnowGfx.texture, RENDER_Z_COMPARE); while (i + gSnowVertOffset < gSnowVertCount) { - vtx = (u32) &gSnowVerts[i]; - gSPVertexDKR(gCurrWeatherDisplayList++, OS_PHYSICAL_TO_K0(vtx), gSnowVertOffset, 0); - gSPPolygon(gCurrWeatherDisplayList++, OS_PHYSICAL_TO_K0(gSnowTriangles), gSnowTriCount, 1); + vtx = &gSnowVerts[i]; + gSPVertexDKR(gCurrWeatherDisplayList++, OS_K0_TO_PHYSICAL(vtx), gSnowVertOffset, 0); + gSPPolygon(gCurrWeatherDisplayList++, OS_K0_TO_PHYSICAL(gSnowTriangles), gSnowTriCount, 1); i += gSnowVertOffset; } - vtx = (u32) &gSnowVerts[i]; - gSPVertexDKR(gCurrWeatherDisplayList++, OS_PHYSICAL_TO_K0(vtx), (gSnowVertCount - i), 0); - gSPPolygon(gCurrWeatherDisplayList++, OS_PHYSICAL_TO_K0(gSnowTriangles), ((s32) (gSnowVertCount - i) >> 1), + vtx = &gSnowVerts[i]; + gSPVertexDKR(gCurrWeatherDisplayList++, OS_K0_TO_PHYSICAL(vtx), (gSnowVertCount - i), 0); + gSPPolygon(gCurrWeatherDisplayList++, OS_K0_TO_PHYSICAL(gSnowTriangles), ((s32) (gSnowVertCount - i) >> 1), 1); } } @@ -624,7 +624,7 @@ void lensflare_init(Object *obj) { gLensFlarePos.x = 0; gLensFlarePos.y = 0; gLensFlarePos.z = -1.0f; - f32_vec3_apply_object_rotation3(&angle, gLensFlarePos.f); + vec3f_rotate_py(&angle, &gLensFlarePos); gLensFlarePos.x = -gLensFlarePos.x; gLensFlarePos.y = -gLensFlarePos.y; gLensFlarePos.z = -gLensFlarePos.z; @@ -634,7 +634,7 @@ void lensflare_init(Object *obj) { * Based on face direction, start rendering lens flare effects on screen. * Each element is shifted based on the preset to create the effect of the sun shining in your face. */ -void lensflare_render(Gfx **dList, MatrixS **mats, Vertex **verts, Camera *camera) { +void lensflare_render(Gfx **dList, Mtx **mats, Vertex **verts, Camera *camera) { u16 height; f32 mag2; UNUSED s32 pad; @@ -655,7 +655,7 @@ void lensflare_render(Gfx **dList, MatrixS **mats, Vertex **verts, Camera *camer pos[1].x = 0.0f; pos[1].y = 0.0f; pos[1].z = -1.0f; - f32_matrix_dot(get_projection_matrix_f32(), (Matrix *) &pos[1].x, (Matrix *) &pos[1].x); + mtxf_transform_dir(get_projection_matrix_f32(), &pos[1], &pos[1]); magnitude = ((gLensFlarePos.x * pos[1].x) + (gLensFlarePos.y * pos[1].y)) + (gLensFlarePos.z * pos[1].z); if (magnitude > 0.0f) { viewport_main(dList, mats); @@ -941,9 +941,8 @@ void rain_render_splashes(s32 updateRate) { } } if (firstIndexWithoutFlags >= 0) { - randYRot = get_random_number_from_range(-0x2000, 0x2000) + - racer->segment.trans.rotation.y_rotation + 0x8000; - randFloat = (f32) get_random_number_from_range(50, 500); + randYRot = rand_range(-0x2000, 0x2000) + racer->segment.trans.rotation.y_rotation + 0x8000; + randFloat = (f32) rand_range(50, 500); xPos = (sins_f(randYRot) * randFloat) + racer->segment.trans.x_position; zPos = (coss_f(randYRot) * randFloat) + racer->segment.trans.z_position; i = func_8002B0F4( @@ -987,7 +986,7 @@ void rain_render_splashes(s32 updateRate) { gRainSplashSegments[firstIndexWithoutFlags].animFrame = 0; gRainSplashSegments[firstIndexWithoutFlags].trans.flags = OBJ_FLAGS_UNK_0001; gRainSplashSegments[firstIndexWithoutFlags].opacity = - get_random_number_from_range(128, (temp_t0 >> 10) + 191); + rand_range(128, (temp_t0 >> 10) + 191); gRainSplashDelay = (gRainSplashDelay - (temp_t0 >> 10)) + 64; if (gRainSplashDelay < 0) { gRainSplashDelay = 0; @@ -1043,7 +1042,7 @@ void rain_lightning(s32 updateRate) { } else { sound_play(SOUND_THUNDER, NULL); gThunderTimer = 600 - ((gLightningFrequency + -48000) >> 5); - gLightningTimer = get_random_number_from_range(900, 1140) - ((gLightningFrequency + -48000) >> 5); + gLightningTimer = rand_range(900, 1140) - ((gLightningFrequency + -48000) >> 5); } } } @@ -1151,9 +1150,9 @@ void rain_render(RainGfxData *rainGfx, s32 time) { gfx_init_basic_xlu(&curDL, 0, COLOUR_RGBA32(rainGfx->primitiveRed, rainGfx->primitiveGreen, rainGfx->primitiveBlue, opacity), COLOUR_RGBA32(rainGfx->environmentRed, rainGfx->environmentGreen, rainGfx->environmentBlue, 0)); - gDkrDmaDisplayList(curDL++, OS_PHYSICAL_TO_K0(tex->cmd), tex->numberOfCommands); - gSPVertexDKR(curDL++, OS_PHYSICAL_TO_K0(gRainVertices + gRainVertexFlip), 4, 0); - gSPPolygon(curDL++, OS_PHYSICAL_TO_K0(gCurrWeatherTriList), 2, 1); + gDkrDmaDisplayList(curDL++, OS_K0_TO_PHYSICAL(tex->cmd), tex->numberOfCommands); + gSPVertexDKR(curDL++, OS_K0_TO_PHYSICAL(gRainVertices + gRainVertexFlip), 4, 0); + gSPPolygon(curDL++, OS_K0_TO_PHYSICAL(gCurrWeatherTriList), 2, 1); gDPPipeSync(curDL++); gRainVertexFlip = (gRainVertexFlip + 4) & 0xF; gCurrWeatherDisplayList = curDL; diff --git a/src/weather.h b/src/weather.h index e30580ba..170c000c 100644 --- a/src/weather.h +++ b/src/weather.h @@ -112,7 +112,7 @@ void rain_sound(s32 updateRate); void rain_render_splashes(s32 updateRate); void rain_lightning(s32 updateRate); void rain_render(RainGfxData*, s32); -void weather_update(Gfx **currDisplayList, MatrixS **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate); +void weather_update(Gfx **currDisplayList, Mtx **currHudMat, Vertex **currHudVerts, Triangle **currHudTris, s32 updateRate); void snow_render(void); void weather_free(void); void weather_set(s32 velX, s32 velY, s32 velZ, s32 intensity, s32 opacity, s32 time); @@ -123,7 +123,7 @@ void rain_init(s32 intensity, s32 opacity); void weather_init(void); void snow_vertices(void); void lensflare_init(Object *); -void lensflare_render(Gfx**, MatrixS**, Vertex**, Camera*); +void lensflare_render(Gfx**, Mtx**, Vertex**, Camera*); void weather_reset(s32 weatherType, s32 density, s32 velX, s32 velY, s32 velZ, s32 intensity, s32 opacity); #endif diff --git a/ver/symbols/symbol_addrs.jpn.v79.txt b/ver/symbols/symbol_addrs.jpn.v79.txt index 866e1bd2..7d76b2cf 100644 --- a/ver/symbols/symbol_addrs.jpn.v79.txt +++ b/ver/symbols/symbol_addrs.jpn.v79.txt @@ -1050,37 +1050,37 @@ interrupts_disable = 0x8006F5F0; interrupts_enable = 0x8006F61C; set_gIntDisFlag = 0x8006F644; get_gIntDisFlag = 0x8006F650; -s32_matrix_to_s16_matrix = 0x8006F65C; -f32_matrix_to_s32_matrix = 0x8006F6C0; -guMtxXFMF = 0x8006F72C; -f32_matrix_dot = 0x8006F7CC; -f32_matrix_mult = 0x8006F848; -f32_matrix_to_s16_matrix = 0x8006F950; +mtx_to_mtxs = 0x8006F65C; +mtxf_to_mtxs = 0x8006F6C0; +mtxf_transform_point = 0x8006F72C; +mtxf_transform_dir = 0x8006F7CC; +mtxf_mul = 0x8006F848; +mtxf_to_mtx = 0x8006F950; set_rng_seed = 0x8006F9EC; save_rng_seed = 0x8006F9F8; load_rng_seed = 0x8006FA0C; get_rng_seed = 0x8006FA20; -get_random_number_from_range = 0x8006FA2C; -s16_matrix_rotate = 0x8006FA98; -s16_matrix_to_s32_matrix = 0x8006FB20; -s16_vec3_mult_by_s32_matrix_full = 0x8006FB58; -s16_vec3_mult_by_s32_matrix = 0x8006FC40; -object_transform_to_matrix = 0x8006FD10; -f32_matrix_scale_y_axis = 0x8006FEE4; -f32_matrix_translate_y_axis = 0x8006FF10; -object_inverse_transform_to_matrix = 0x8006FF54; +rand_range = 0x8006FA2C; +vec3s_reflect = 0x8006FA98; +mtx_to_mtxs_2 = 0x8006FB20; +mtxs_transform_point = 0x8006FB58; +mtxs_transform_dir = 0x8006FC40; +mtxf_from_transform = 0x8006FD10; +mtxf_scale_y = 0x8006FEE4; +mtxf_translate_y = 0x8006FF10; +mtxf_from_inverse_transform = 0x8006FF54; func_80070058 = 0x80070138; -f32_matrix_from_rotation_and_scale = 0x80070210; -s16_vec3_apply_object_rotation = 0x800702C4; -f32_vec3_apply_object_rotation = 0x80070400; -f32_vec3_apply_object_rotation2 = 0x800704B8; -f32_vec3_apply_object_rotation3 = 0x80070570; -point_triangle_2d_xz_intersection = 0x800705D0; -f32_matrix_from_position = 0x800706D8; -f32_matrix_from_scale = 0x80070718; +mtxf_billboard = 0x80070210; +vec3s_rotate_rpy = 0x800702C4; +vec3f_rotate = 0x80070400; +vec3f_rotate_ypr = 0x800704B8; +vec3f_rotate_py = 0x80070570; +tri2d_xz_contains_point = 0x800705D0; +mtxf_from_translation = 0x800706D8; +mtxf_from_scale = 0x80070718; atan2s = 0x8007074C; arctan2_f = 0x80070830; -s32_matrix_cell_sqrt = 0x80070860; +fix32_sqrt = 0x80070860; bad_int_sqrt = 0x8007088C; sins_f = 0x800708A4; coss_f = 0x800708D8; @@ -3956,14 +3956,14 @@ gModelMatrixViewY = 0x801227B0; gModelMatrixViewZ = 0x801227C8; perspNorm = 0x801227DC; gModelMatrixF = 0x801227E0; -gModelMatrixS = 0x801227F8; +gModelMatrix = 0x801227F8; D_80120DA0 = 0x80122810; gPerspectiveMatrixF = 0x80122950; gViewMatrixF = 0x80122990; gCameraMatrixF = 0x801229D0; gProjectionMatrixF = 0x80122A10; -gProjectionMatrixS = 0x80122A50; -gUnusedProjectionMatrixS = 0x80122A90; +gProjectionMatrix = 0x80122A50; +gUnusedProjectionMatrix = 0x80122A90; gCurrentModelMatrixF = 0x80122AD0; gCurrentModelMatrixS = 0x80122B10; diff --git a/ver/symbols/symbol_addrs.pal.v77.txt b/ver/symbols/symbol_addrs.pal.v77.txt index c721aab5..fa44f44a 100644 --- a/ver/symbols/symbol_addrs.pal.v77.txt +++ b/ver/symbols/symbol_addrs.pal.v77.txt @@ -1048,37 +1048,37 @@ interrupts_disable = 0x8006F510; interrupts_enable = 0x8006F53C; set_gIntDisFlag = 0x8006F564; get_gIntDisFlag = 0x8006F570; -s32_matrix_to_s16_matrix = 0x8006F57C; -f32_matrix_to_s32_matrix = 0x8006F5E0; -guMtxXFMF = 0x8006F64C; -f32_matrix_dot = 0x8006F6EC; -f32_matrix_mult = 0x8006F768; -f32_matrix_to_s16_matrix = 0x8006F870; +mtx_to_mtxs = 0x8006F57C; +mtxf_to_mtxs = 0x8006F5E0; +mtxf_transform_point = 0x8006F64C; +mtxf_transform_dir = 0x8006F6EC; +mtxf_mul = 0x8006F768; +mtxf_to_mtx = 0x8006F870; set_rng_seed = 0x8006F90C; save_rng_seed = 0x8006F918; load_rng_seed = 0x8006F92C; get_rng_seed = 0x8006F940; -get_random_number_from_range = 0x8006F94C; -s16_matrix_rotate = 0x8006F9B8; -s16_matrix_to_s32_matrix = 0x8006FA40; -s16_vec3_mult_by_s32_matrix_full = 0x8006FA78; -s16_vec3_mult_by_s32_matrix = 0x8006FB60; -object_transform_to_matrix = 0x8006FC30; -f32_matrix_scale_y_axis = 0x8006FE04; -f32_matrix_translate_y_axis = 0x8006FE30; -object_inverse_transform_to_matrix = 0x8006FE74; +rand_range = 0x8006F94C; +vec3s_reflect = 0x8006F9B8; +mtx_to_mtxs_2 = 0x8006FA40; +mtxs_transform_point = 0x8006FA78; +mtxs_transform_dir = 0x8006FB60; +mtxf_from_transform = 0x8006FC30; +mtxf_scale_y = 0x8006FE04; +mtxf_translate_y = 0x8006FE30; +mtxf_from_inverse_transform = 0x8006FE74; func_80070058 = 0x80070058; -f32_matrix_from_rotation_and_scale = 0x80070130; -s16_vec3_apply_object_rotation = 0x800701E4; -f32_vec3_apply_object_rotation = 0x80070320; -f32_vec3_apply_object_rotation2 = 0x800703D8; -f32_vec3_apply_object_rotation3 = 0x80070490; -point_triangle_2d_xz_intersection = 0x800704F0; -f32_matrix_from_position = 0x800705F8; -f32_matrix_from_scale = 0x80070638; +mtxf_billboard = 0x80070130; +vec3s_rotate_rpy = 0x800701E4; +vec3f_rotate = 0x80070320; +vec3f_rotate_ypr = 0x800703D8; +vec3f_rotate_py = 0x80070490; +tri2d_xz_contains_point = 0x800704F0; +mtxf_from_translation = 0x800705F8; +mtxf_from_scale = 0x80070638; atan2s = 0x8007066C; arctan2_f = 0x80070750; -s32_matrix_cell_sqrt = 0x80070780; +fix32_sqrt = 0x80070780; bad_int_sqrt = 0x800707AC; sins_f = 0x800707C4; coss_f = 0x800707F8; @@ -3666,14 +3666,14 @@ gModelMatrixViewY = 0x80120DD0; gModelMatrixViewZ = 0x80120DE8; perspNorm = 0x80120DFC; gModelMatrixF = 0x80120E00; -gModelMatrixS = 0x80120E18; +gModelMatrix = 0x80120E18; D_80120DA0 = 0x80120E30; gPerspectiveMatrixF = 0x80120F70; gViewMatrixF = 0x80120FB0; gCameraMatrixF = 0x80120FF0; gProjectionMatrixF = 0x80121030; -gProjectionMatrixS = 0x80121070; -gUnusedProjectionMatrixS = 0x801210B0; +gProjectionMatrix = 0x80121070; +gUnusedProjectionMatrix = 0x801210B0; gCurrentModelMatrixF = 0x801210F0; gCurrentModelMatrixS = 0x80121130; sSIMesgQueue = 0x80121170; diff --git a/ver/symbols/symbol_addrs.pal.v80.txt b/ver/symbols/symbol_addrs.pal.v80.txt index 4cabffb3..e934eeba 100644 --- a/ver/symbols/symbol_addrs.pal.v80.txt +++ b/ver/symbols/symbol_addrs.pal.v80.txt @@ -986,37 +986,37 @@ interrupts_disable = 0x8006F750; interrupts_enable = 0x8006F77C; set_gIntDisFlag = 0x8006F7A4; get_gIntDisFlag = 0x8006F7B0; -s32_matrix_to_s16_matrix = 0x8006F7BC; -f32_matrix_to_s32_matrix = 0x8006F820; -guMtxXFMF = 0x8006F88C; -f32_matrix_dot = 0x8006F92C; -f32_matrix_mult = 0x8006F9A8; -f32_matrix_to_s16_matrix = 0x8006FAB0; +mtx_to_mtxs = 0x8006F7BC; +mtxf_to_mtxs = 0x8006F820; +mtxf_transform_point = 0x8006F88C; +mtxf_transform_dir = 0x8006F92C; +mtxf_mul = 0x8006F9A8; +mtxf_to_mtx = 0x8006FAB0; set_rng_seed = 0x8006FB4C; save_rng_seed = 0x8006FB58; load_rng_seed = 0x8006FB6C; get_rng_seed = 0x8006FB80; -get_random_number_from_range = 0x8006FB8C; -s16_matrix_rotate = 0x8006FBF8; -s16_matrix_to_s32_matrix = 0x8006FC80; -s16_vec3_mult_by_s32_matrix_full = 0x8006FCB8; -s16_vec3_mult_by_s32_matrix = 0x8006FDA0; -object_transform_to_matrix = 0x8006FE70; -f32_matrix_scale_y_axis = 0x80070044; -f32_matrix_translate_y_axis = 0x80070070; -object_inverse_transform_to_matrix = 0x800700B4; +rand_range = 0x8006FB8C; +vec3s_reflect = 0x8006FBF8; +mtx_to_mtxs_2 = 0x8006FC80; +mtxs_transform_point = 0x8006FCB8; +mtxs_transform_dir = 0x8006FDA0; +mtxf_from_transform = 0x8006FE70; +mtxf_scale_y = 0x80070044; +mtxf_translate_y = 0x80070070; +mtxf_from_inverse_transform = 0x800700B4; func_80070058 = 0x80070298; -f32_matrix_from_rotation_and_scale = 0x80070370; -s16_vec3_apply_object_rotation = 0x80070424; -f32_vec3_apply_object_rotation = 0x80070560; -f32_vec3_apply_object_rotation2 = 0x80070618; -f32_vec3_apply_object_rotation3 = 0x800706D0; -point_triangle_2d_xz_intersection = 0x80070730; -f32_matrix_from_position = 0x80070838; -f32_matrix_from_scale = 0x80070878; +mtxf_billboard = 0x80070370; +vec3s_rotate_rpy = 0x80070424; +vec3f_rotate = 0x80070560; +vec3f_rotate_ypr = 0x80070618; +vec3f_rotate_py = 0x800706D0; +tri2d_xz_contains_point = 0x80070730; +mtxf_from_translation = 0x80070838; +mtxf_from_scale = 0x80070878; atan2s = 0x800708AC; arctan2_f = 0x80070990; -s32_matrix_cell_sqrt = 0x800709C0; +fix32_sqrt = 0x800709C0; bad_int_sqrt = 0x800709EC; sins_f = 0x80070A04; coss_f = 0x80070A38; @@ -3596,14 +3596,14 @@ gModelMatrixViewY = 0x80121350; gModelMatrixViewZ = 0x80121368; perspNorm = 0x8012137C; gModelMatrixF = 0x80121380; -gModelMatrixS = 0x80121398; +gModelMatrix = 0x80121398; D_80120DA0 = 0x801213B0; gPerspectiveMatrixF = 0x801214F0; gViewMatrixF = 0x80121530; gCameraMatrixF = 0x80121570; gProjectionMatrixF = 0x801215B0; -gProjectionMatrixS = 0x801215F0; -gUnusedProjectionMatrixS = 0x80121630; +gProjectionMatrix = 0x801215F0; +gUnusedProjectionMatrix = 0x80121630; gCurrentModelMatrixF = 0x80121670; gCurrentModelMatrixS = 0x801216B0; sSIMesgQueue = 0x801216F0; diff --git a/ver/symbols/symbol_addrs.us.v77.txt b/ver/symbols/symbol_addrs.us.v77.txt index aa31c707..54692654 100644 --- a/ver/symbols/symbol_addrs.us.v77.txt +++ b/ver/symbols/symbol_addrs.us.v77.txt @@ -1048,37 +1048,37 @@ interrupts_disable = 0x8006F510; interrupts_enable = 0x8006F53C; set_gIntDisFlag = 0x8006F564; get_gIntDisFlag = 0x8006F570; -s32_matrix_to_s16_matrix = 0x8006F57C; -f32_matrix_to_s32_matrix = 0x8006F5E0; -guMtxXFMF = 0x8006F64C; -f32_matrix_dot = 0x8006F6EC; -f32_matrix_mult = 0x8006F768; -f32_matrix_to_s16_matrix = 0x8006F870; +mtx_to_mtxs = 0x8006F57C; +mtxf_to_mtxs = 0x8006F5E0; +mtxf_transform_point = 0x8006F64C; +mtxf_transform_dir = 0x8006F6EC; +mtxf_mul = 0x8006F768; +mtxf_to_mtx = 0x8006F870; set_rng_seed = 0x8006F90C; save_rng_seed = 0x8006F918; load_rng_seed = 0x8006F92C; get_rng_seed = 0x8006F940; -get_random_number_from_range = 0x8006F94C; -s16_matrix_rotate = 0x8006F9B8; -s16_matrix_to_s32_matrix = 0x8006FA40; -s16_vec3_mult_by_s32_matrix_full = 0x8006FA78; -s16_vec3_mult_by_s32_matrix = 0x8006FB60; -object_transform_to_matrix = 0x8006FC30; -f32_matrix_scale_y_axis = 0x8006FE04; -f32_matrix_translate_y_axis = 0x8006FE30; -object_inverse_transform_to_matrix = 0x8006FE74; +rand_range = 0x8006F94C; +vec3s_reflect = 0x8006F9B8; +mtx_to_mtxs_2 = 0x8006FA40; +mtxs_transform_point = 0x8006FA78; +mtxs_transform_dir = 0x8006FB60; +mtxf_from_transform = 0x8006FC30; +mtxf_scale_y = 0x8006FE04; +mtxf_translate_y = 0x8006FE30; +mtxf_from_inverse_transform = 0x8006FE74; func_80070058 = 0x80070058; -f32_matrix_from_rotation_and_scale = 0x80070130; -s16_vec3_apply_object_rotation = 0x800701E4; -f32_vec3_apply_object_rotation = 0x80070320; -f32_vec3_apply_object_rotation2 = 0x800703D8; -f32_vec3_apply_object_rotation3 = 0x80070490; -point_triangle_2d_xz_intersection = 0x800704F0; -f32_matrix_from_position = 0x800705F8; -f32_matrix_from_scale = 0x80070638; +mtxf_billboard = 0x80070130; +vec3s_rotate_rpy = 0x800701E4; +vec3f_rotate = 0x80070320; +vec3f_rotate_ypr = 0x800703D8; +vec3f_rotate_py = 0x80070490; +tri2d_xz_contains_point = 0x800704F0; +mtxf_from_translation = 0x800705F8; +mtxf_from_scale = 0x80070638; atan2s = 0x8007066C; arctan2_f = 0x80070750; -s32_matrix_cell_sqrt = 0x80070780; +fix32_sqrt = 0x80070780; bad_int_sqrt = 0x800707AC; sins_f = 0x800707C4; coss_f = 0x800707F8; @@ -4071,14 +4071,14 @@ gModelMatrixViewY = 0x80120D40; gModelMatrixViewZ = 0x80120D58; perspNorm = 0x80120D6C; gModelMatrixF = 0x80120D70; -gModelMatrixS = 0x80120D88; +gModelMatrix = 0x80120D88; D_80120DA0 = 0x80120DA0; gPerspectiveMatrixF = 0x80120EE0; gViewMatrixF = 0x80120F20; gCameraMatrixF = 0x80120F60; gProjectionMatrixF = 0x80120FA0; -gProjectionMatrixS = 0x80120FE0; -gUnusedProjectionMatrixS = 0x80121020; +gProjectionMatrix = 0x80120FE0; +gUnusedProjectionMatrix = 0x80121020; gCurrentModelMatrixF = 0x80121060; gCurrentModelMatrixS = 0x801210A0; diff --git a/ver/symbols/symbol_addrs.us.v80.txt b/ver/symbols/symbol_addrs.us.v80.txt index 1656733f..bb45b920 100644 --- a/ver/symbols/symbol_addrs.us.v80.txt +++ b/ver/symbols/symbol_addrs.us.v80.txt @@ -986,37 +986,37 @@ interrupts_disable = 0x8006F750; interrupts_enable = 0x8006F77C; set_gIntDisFlag = 0x8006F7A4; get_gIntDisFlag = 0x8006F7B0; -s32_matrix_to_s16_matrix = 0x8006F7BC; -f32_matrix_to_s32_matrix = 0x8006F820; -guMtxXFMF = 0x8006F88C; -f32_matrix_dot = 0x8006F92C; -f32_matrix_mult = 0x8006F9A8; -f32_matrix_to_s16_matrix = 0x8006FAB0; +mtx_to_mtxs = 0x8006F7BC; +mtxf_to_mtxs = 0x8006F820; +mtxf_transform_point = 0x8006F88C; +mtxf_transform_dir = 0x8006F92C; +mtxf_mul = 0x8006F9A8; +mtxf_to_mtx = 0x8006FAB0; set_rng_seed = 0x8006FB4C; save_rng_seed = 0x8006FB58; load_rng_seed = 0x8006FB6C; get_rng_seed = 0x8006FB80; -get_random_number_from_range = 0x8006FB8C; -s16_matrix_rotate = 0x8006FBF8; -s16_matrix_to_s32_matrix = 0x8006FC80; -s16_vec3_mult_by_s32_matrix_full = 0x8006FCB8; -s16_vec3_mult_by_s32_matrix = 0x8006FDA0; -object_transform_to_matrix = 0x8006FE70; -f32_matrix_scale_y_axis = 0x80070044; -f32_matrix_translate_y_axis = 0x80070070; -object_inverse_transform_to_matrix = 0x800700B4; +rand_range = 0x8006FB8C; +vec3s_reflect = 0x8006FBF8; +mtx_to_mtxs_2 = 0x8006FC80; +mtxs_transform_point = 0x8006FCB8; +mtxs_transform_dir = 0x8006FDA0; +mtxf_from_transform = 0x8006FE70; +mtxf_scale_y = 0x80070044; +mtxf_translate_y = 0x80070070; +mtxf_from_inverse_transform = 0x800700B4; func_80070058 = 0x80070298; -f32_matrix_from_rotation_and_scale = 0x80070370; -s16_vec3_apply_object_rotation = 0x80070424; -f32_vec3_apply_object_rotation = 0x80070560; -f32_vec3_apply_object_rotation2 = 0x80070618; -f32_vec3_apply_object_rotation3 = 0x800706D0; -point_triangle_2d_xz_intersection = 0x80070730; -f32_matrix_from_position = 0x80070838; -f32_matrix_from_scale = 0x80070878; +mtxf_billboard = 0x80070370; +vec3s_rotate_rpy = 0x80070424; +vec3f_rotate = 0x80070560; +vec3f_rotate_ypr = 0x80070618; +vec3f_rotate_py = 0x800706D0; +tri2d_xz_contains_point = 0x80070730; +mtxf_from_translation = 0x80070838; +mtxf_from_scale = 0x80070878; atan2s = 0x800708AC; arctan2_f = 0x80070990; -s32_matrix_cell_sqrt = 0x800709C0; +fix32_sqrt = 0x800709C0; bad_int_sqrt = 0x800709EC; sins_f = 0x80070A04; coss_f = 0x80070A38; @@ -3592,14 +3592,14 @@ gModelMatrixViewY = 0x801212C0; gModelMatrixViewZ = 0x801212D8; perspNorm = 0x801212EC; gModelMatrixF = 0x801212F0; -gModelMatrixS = 0x80121308; +gModelMatrix = 0x80121308; D_80120DA0 = 0x80121320; gPerspectiveMatrixF = 0x80121460; gViewMatrixF = 0x801214A0; gCameraMatrixF = 0x801214E0; gProjectionMatrixF = 0x80121520; -gProjectionMatrixS = 0x80121560; -gUnusedProjectionMatrixS = 0x801215A0; +gProjectionMatrix = 0x80121560; +gUnusedProjectionMatrix = 0x801215A0; gCurrentModelMatrixF = 0x801215E0; gCurrentModelMatrixS = 0x80121620; sSIMesgQueue = 0x80121660;