diff --git a/src/actors/banana/render.inc.c b/src/actors/banana/render.inc.c index f51bc6aa6..abd2fa7b7 100644 --- a/src/actors/banana/render.inc.c +++ b/src/actors/banana/render.inc.c @@ -15,8 +15,8 @@ void render_actor_banana(Camera* camera, UNUSED Mat4 arg1, struct BananaActor* b Vec3s sp7C; Mat4 sp3C; - f32 temp = is_within_render_distance(camera->pos, banana->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], - 490000.0f); + f32 temp = + distance_if_visible(camera->pos, banana->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 490000.0f); if (temp < 0.0f) { actor_not_rendered(camera, (struct Actor*) banana); return; @@ -34,12 +34,12 @@ void render_actor_banana(Camera* camera, UNUSED Mat4 arg1, struct BananaActor* b actor_rendered(camera, (struct Actor*) banana); if (banana->state == 5) { - mtxf_pos_rotation_xyz(sp3C, banana->pos, banana->rot); + mtxf_rotate_zxy_translate(sp3C, banana->pos, banana->rot); } else { sp7C[0] = 0; sp7C[1] = 0; sp7C[2] = 0; - mtxf_pos_rotation_xyz(sp3C, banana->pos, sp7C); + mtxf_rotate_zxy_translate(sp3C, banana->pos, sp7C); } maxObjectsReached = render_set_position(sp3C, 0) == 0; diff --git a/src/actors/banana/update.inc.c b/src/actors/banana/update.inc.c index d3bbc6563..e96c2d502 100644 --- a/src/actors/banana/update.inc.c +++ b/src/actors/banana/update.inc.c @@ -72,7 +72,7 @@ void update_actor_banana(struct BananaActor* banana) { temp_f0 = (player->speed * 0.75f) + 3.5f + pad3; } vec3f_set(someVelocity, 0, pad3, temp_f0); - func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(someVelocity, player->rotation[1] + player->unk_0C0); banana->velocity[0] = someVelocity[0]; banana->velocity[1] = someVelocity[1]; banana->velocity[2] = someVelocity[2]; @@ -121,7 +121,7 @@ void update_actor_banana(struct BananaActor* banana) { someVelocity[0] = 0.0f; someVelocity[1] = 0.0f; someVelocity[2] = -5.0f; - func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(someVelocity, player->rotation[1] + player->unk_0C0); unkX = player->pos[0] + someVelocity[0]; unkY = player->pos[1] + someVelocity[1]; unkZ = player->pos[2] + someVelocity[2]; diff --git a/src/actors/blue_and_red_shells/update.inc.c b/src/actors/blue_and_red_shells/update.inc.c index c479ef3bd..4835c53ef 100644 --- a/src/actors/blue_and_red_shells/update.inc.c +++ b/src/actors/blue_and_red_shells/update.inc.c @@ -172,9 +172,9 @@ s16 func_802B3FD0(Player* owner, struct ShellActor* shell) { if (gPlayerBalloonCount[playerIndex] < 0) { continue; } - // func_802B51E8 is not quite a 3D distance function, it doubles (rather than squares) the Z difference of the + // dist_squared_bugged is not quite a 3D distance function, it doubles (rather than squares) the Z difference of the // positions - playerToShellDistance = func_802B51E8(player->pos, shell->pos); + playerToShellDistance = dist_squared_bugged(player->pos, shell->pos); if (playerToShellDistance < smallestDistance) { smallestDistance = playerToShellDistance; playerId = player - gPlayerOne; @@ -250,7 +250,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) { somePosVel[0] = 0.0f; somePosVel[1] = player->boundingBoxSize; somePosVel[2] = -(player->boundingBoxSize + shell->boundingBoxSize + 2.0f); - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); shell->pos[0] = player->pos[0] + somePosVel[0]; pad7 = player->pos[1] - somePosVel[1]; shell->pos[2] = player->pos[2] + somePosVel[2]; @@ -323,7 +323,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) { somePosVel[0] = 0.0f; somePosVel[1] = 0.0f; somePosVel[2] = height; - func_802B64C4(somePosVel, (s16) (player->rotation[1] + player->unk_0C0)); + vec3f_rotate_y(somePosVel, (s16) (player->rotation[1] + player->unk_0C0)); shell->velocity[0] = somePosVel[0]; shell->velocity[1] = somePosVel[1]; shell->velocity[2] = somePosVel[2]; @@ -331,7 +331,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) { somePosVel[0] = sins(shell->rotAngle) * 8.0f; somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize; somePosVel[2] = coss(shell->rotAngle) * 8.0f; - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); shell->pos[0] = player->pos[0] + somePosVel[0]; shell->pos[1] = player->pos[1] + somePosVel[1]; shell->pos[2] = player->pos[2] + somePosVel[2]; @@ -437,7 +437,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) { somePosVel[0] = sins(shell->rotAngle) * 8.0f; somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize; somePosVel[2] = coss(shell->rotAngle) * 8.0f; - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); origPos[0] = shell->pos[0]; origPos[1] = shell->pos[1]; origPos[2] = shell->pos[2]; diff --git a/src/actors/box_truck/render.inc.c b/src/actors/box_truck/render.inc.c index 9d03c369b..f4ab446e7 100644 --- a/src/actors/box_truck/render.inc.c +++ b/src/actors/box_truck/render.inc.c @@ -17,7 +17,7 @@ void render_actor_box_truck(Camera* arg0, struct Actor* arg1) { Mat4 spD8; UNUSED s32 pad2[32]; f32 temp_f0 = - is_within_render_distance(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); + distance_if_visible(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); if (temp_f0 < 0.0f) { return; } @@ -25,7 +25,7 @@ void render_actor_box_truck(Camera* arg0, struct Actor* arg1) { gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(spD8, arg1->pos, arg1->rot); + mtxf_rotate_zxy_translate(spD8, arg1->pos, arg1->rot); if (render_set_position(spD8, 0) != 0) { switch (arg1->state) { diff --git a/src/actors/car/render.inc.c b/src/actors/car/render.inc.c index 73de7ee3e..87980f80c 100644 --- a/src/actors/car/render.inc.c +++ b/src/actors/car/render.inc.c @@ -15,14 +15,14 @@ void render_actor_car(Camera* arg0, struct Actor* arg1) { Mat4 spC8; UNUSED s32 pad2[32]; f32 temp_f0 = - is_within_render_distance(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); + distance_if_visible(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); if (!(temp_f0 < 0.0f)) { gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(spC8, arg1->pos, arg1->rot); + mtxf_rotate_zxy_translate(spC8, arg1->pos, arg1->rot); mtxf_scale(spC8, 0.1f); if (render_set_position(spC8, 0) != 0) { diff --git a/src/actors/cow/render.inc.c b/src/actors/cow/render.inc.c index 769801f66..a313043d6 100644 --- a/src/actors/cow/render.inc.c +++ b/src/actors/cow/render.inc.c @@ -13,7 +13,7 @@ * @param arg2 */ void render_actor_cow(Camera* camera, Mat4 arg1, struct Actor* arg2) { - if (is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], + if (distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f) < 0) { return; } diff --git a/src/actors/fake_item_box/render.inc.c b/src/actors/fake_item_box/render.inc.c index a8cfd64e6..36e4cf9e0 100644 --- a/src/actors/fake_item_box/render.inc.c +++ b/src/actors/fake_item_box/render.inc.c @@ -24,8 +24,8 @@ void render_actor_fake_item_box(Camera* camera, struct FakeItemBox* fakeItemBox) f32 temp_f2_2; f32 someMultiplier; - if (is_within_render_distance(camera->pos, fakeItemBox->pos, camera->rot[1], 2500.0f, gCameraZoom[camera - camera1], - 1000000.0f) < 0) { + if (distance_if_visible(camera->pos, fakeItemBox->pos, camera->rot[1], 2500.0f, gCameraZoom[camera - camera1], + 1000000.0f) < 0) { actor_not_rendered(camera, (struct Actor*) fakeItemBox); return; } @@ -42,7 +42,7 @@ void render_actor_fake_item_box(Camera* camera, struct FakeItemBox* fakeItemBox) someRot[0] = 0; someRot[1] = fakeItemBox->rot[1]; someRot[2] = 0; - mtxf_pos_rotation_xyz(someMatrix2, fakeItemBox->pos, someRot); + mtxf_rotate_zxy_translate(someMatrix2, fakeItemBox->pos, someRot); mtxf_scale(someMatrix2, fakeItemBox->sizeScaling); if (fakeItemBox->state != 2) { @@ -51,7 +51,7 @@ void render_actor_fake_item_box(Camera* camera, struct FakeItemBox* fakeItemBox) } gSPDisplayList(gDisplayListHead++, common_model_fake_itembox); - mtxf_pos_rotation_xyz(someMatrix2, fakeItemBox->pos, fakeItemBox->rot); + mtxf_rotate_zxy_translate(someMatrix2, fakeItemBox->pos, fakeItemBox->rot); mtxf_scale(someMatrix2, fakeItemBox->sizeScaling); if (!render_set_position(someMatrix2, 0)) { @@ -78,7 +78,7 @@ void render_actor_fake_item_box(Camera* camera, struct FakeItemBox* fakeItemBox) gSPClearGeometryMode(gDisplayListHead++, G_CULL_BACK); gDPSetBlendMask(gDisplayListHead++, 0xFF); thing = fakeItemBox->someTimer; - mtxf_pos_rotation_xyz(someMatrix2, fakeItemBox->pos, fakeItemBox->rot); + mtxf_rotate_zxy_translate(someMatrix2, fakeItemBox->pos, fakeItemBox->rot); if (thing < 10.0f) { someMultiplier = 1.0f; } else { diff --git a/src/actors/falling_rock/render.inc.c b/src/actors/falling_rock/render.inc.c index 2bbca1d04..5b3e09927 100644 --- a/src/actors/falling_rock/render.inc.c +++ b/src/actors/falling_rock/render.inc.c @@ -20,8 +20,8 @@ void render_actor_falling_rock(Camera* camera, struct FallingRock* rock) { return; } - height = is_within_render_distance(camera->pos, rock->pos, camera->rot[1], 400.0f, gCameraZoom[camera - camera1], - 4000000.0f); + height = distance_if_visible(camera->pos, rock->pos, camera->rot[1], 400.0f, gCameraZoom[camera - camera1], + 4000000.0f); if (height < 0.0f) { return; @@ -37,14 +37,14 @@ void render_actor_falling_rock(Camera* camera, struct FallingRock* rock) { sp98[1] = 0; sp98[2] = 0; sp8C[1] = height + 2.0f; - mtxf_pos_rotation_xyz(sp4C, sp8C, sp98); + mtxf_rotate_zxy_translate(sp4C, sp8C, sp98); if (render_set_position(sp4C, 0) == 0) { return; } gSPDisplayList(gDisplayListHead++, d_course_choco_mountain_dl_6F88); } } - mtxf_pos_rotation_xyz(sp4C, rock->pos, rock->rot); + mtxf_rotate_zxy_translate(sp4C, rock->pos, rock->rot); if (render_set_position(sp4C, 0) == 0) { return; } diff --git a/src/actors/green_shell/update.inc.c b/src/actors/green_shell/update.inc.c index 8dd5e277d..7231af183 100644 --- a/src/actors/green_shell/update.inc.c +++ b/src/actors/green_shell/update.inc.c @@ -43,7 +43,7 @@ void update_actor_green_shell(struct ShellActor* shell) { somePosVel[0] = 0.0f; somePosVel[1] = player->boundingBoxSize; somePosVel[2] = -(player->boundingBoxSize + shell->boundingBoxSize + 2.0f); - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); shell->pos[0] = player->pos[0] + somePosVel[0]; pad2 = player->pos[1] - somePosVel[1]; shell->pos[2] = player->pos[2] + somePosVel[2]; @@ -66,7 +66,7 @@ void update_actor_green_shell(struct ShellActor* shell) { somePosVel[0] = 0.0f; somePosVel[1] = 0.0f; somePosVel[2] = -var_f2; - func_802B64C4(somePosVel, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(somePosVel, player->rotation[1] + player->unk_0C0); shell->velocity[0] = somePosVel[0]; shell->velocity[1] = somePosVel[1]; shell->velocity[2] = somePosVel[2]; @@ -118,7 +118,7 @@ void update_actor_green_shell(struct ShellActor* shell) { somePosVel[0] = 0.0f; somePosVel[1] = 0.0f; somePosVel[2] = var_f2; - func_802B64C4(somePosVel, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(somePosVel, player->rotation[1] + player->unk_0C0); shell->velocity[0] = somePosVel[0]; shell->velocity[1] = somePosVel[1]; shell->velocity[2] = somePosVel[2]; @@ -126,7 +126,7 @@ void update_actor_green_shell(struct ShellActor* shell) { somePosVel[0] = sins(shell->rotAngle) * 6.0f; somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize; somePosVel[2] = coss(shell->rotAngle) * 6.0f; - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); shell->pos[0] = player->pos[0] + somePosVel[0]; shell->pos[1] = player->pos[1] + somePosVel[1]; shell->pos[2] = player->pos[2] + somePosVel[2]; @@ -168,7 +168,7 @@ void update_actor_green_shell(struct ShellActor* shell) { somePosVel[0] = sins(shell->rotAngle) * 8.0f; somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize; somePosVel[2] = coss(shell->rotAngle) * 8.0f; - mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix); + mtxf_transform_vec3f_mat3(somePosVel, player->orientationMatrix); somePos2[0] = shell->pos[0]; somePos2[1] = shell->pos[1]; somePos2[2] = shell->pos[2]; diff --git a/src/actors/item_box/render.inc.c b/src/actors/item_box/render.inc.c index 7024709d7..d0288a637 100644 --- a/src/actors/item_box/render.inc.c +++ b/src/actors/item_box/render.inc.c @@ -26,8 +26,8 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { f32 temp_f2_2; f32 someMultiplier; - temp_f0 = is_within_render_distance(camera->pos, item_box->pos, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], - 4000000.0f); + temp_f0 = distance_if_visible(camera->pos, item_box->pos, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], + 4000000.0f); if (!(temp_f0 < 0.0f) && !(600000.0f < temp_f0)) { if ((item_box->state == 2) && (temp_f0 < 100000.0f)) { someRot[0] = 0; @@ -36,7 +36,7 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { someVec2[0] = item_box->pos[0]; someVec2[1] = item_box->resetDistance + 2.0f; someVec2[2] = item_box->pos[2]; - mtxf_pos_rotation_xyz(someMatrix1, someVec2, someRot); + mtxf_rotate_zxy_translate(someMatrix1, someVec2, someRot); if (!render_set_position(someMatrix1, 0)) { return; @@ -45,7 +45,7 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { gSPDisplayList(gDisplayListHead++, D_0D002EE8); someRot[1] = item_box->rot[1] * 2; someVec2[1] = item_box->pos[1]; - mtxf_pos_rotation_xyz(someMatrix1, someVec2, someRot); + mtxf_rotate_zxy_translate(someMatrix1, someVec2, someRot); if (!render_set_position(someMatrix1, 0)) { return; @@ -54,7 +54,7 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { gSPDisplayList(gDisplayListHead++, itemBoxQuestionMarkModel); } if (item_box->state == 5) { - mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot); + mtxf_rotate_zxy_translate(someMatrix1, item_box->pos, item_box->rot); if (!render_set_position(someMatrix1, 0)) { return; @@ -63,7 +63,7 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { gSPDisplayList(gDisplayListHead++, itemBoxQuestionMarkModel); } if (item_box->state != 3) { - mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot); + mtxf_rotate_zxy_translate(someMatrix1, item_box->pos, item_box->rot); if (!render_set_position(someMatrix1, 0)) { return; @@ -90,7 +90,7 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) { gSPClearGeometryMode(gDisplayListHead++, G_CULL_BACK); gDPSetBlendMask(gDisplayListHead++, 0xFF); thing = item_box->someTimer; - mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot); + mtxf_rotate_zxy_translate(someMatrix1, item_box->pos, item_box->rot); if (thing < 10.0f) { someMultiplier = 1.0f; } else { diff --git a/src/actors/mario_sign/render.inc.c b/src/actors/mario_sign/render.inc.c index 8c31370ee..f9e7eb59e 100644 --- a/src/actors/mario_sign/render.inc.c +++ b/src/actors/mario_sign/render.inc.c @@ -19,11 +19,11 @@ void render_actor_mario_sign(Camera* arg0, UNUSED Mat4 arg1, struct Actor* arg2) return; } - unk = is_within_render_distance(arg0->pos, arg2->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 16000000.0f); + unk = distance_if_visible(arg0->pos, arg2->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 16000000.0f); if (!(unk < 0.0f)) { gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(sp40, arg2->pos, arg2->rot); + mtxf_rotate_zxy_translate(sp40, arg2->pos, arg2->rot); if (render_set_position(sp40, 0) != 0) { gSPDisplayList(gDisplayListHead++, d_course_mario_raceway_dl_sign); } diff --git a/src/actors/paddle_boat/render.inc.c b/src/actors/paddle_boat/render.inc.c index 13b423fd4..fdd16a2e4 100644 --- a/src/actors/paddle_boat/render.inc.c +++ b/src/actors/paddle_boat/render.inc.c @@ -28,8 +28,8 @@ void render_actor_paddle_boat(Camera* arg0, struct PaddleWheelBoat* boat, UNUSED return; } - temp = is_within_render_distance(arg0->pos, boat->pos, arg0->rot[1], 90000.0f, gCameraZoom[arg0 - camera1], - 9000000.0f); + temp = + distance_if_visible(arg0->pos, boat->pos, arg0->rot[1], 90000.0f, gCameraZoom[arg0 - camera1], 9000000.0f); if (temp < 0.0f) { return; @@ -38,7 +38,7 @@ void render_actor_paddle_boat(Camera* arg0, struct PaddleWheelBoat* boat, UNUSED gSPSetLights1(gDisplayListHead++, D_800DC610[1]); gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_LIGHTING | G_SHADING_SMOOTH); - mtxf_pos_rotation_xyz(spE0, boat->pos, boat->boatRot); + mtxf_rotate_zxy_translate(spE0, boat->pos, boat->boatRot); if (render_set_position(spE0, 1) != 0) { // Render the boat diff --git a/src/actors/palm_tree/render.inc.c b/src/actors/palm_tree/render.inc.c index f3f92c453..60690e4e3 100644 --- a/src/actors/palm_tree/render.inc.c +++ b/src/actors/palm_tree/render.inc.c @@ -21,13 +21,13 @@ void render_actor_palm_tree(Camera* arg0, UNUSED Mat4 arg1, struct PalmTree* arg } temp_f0 = - is_within_render_distance(arg0->pos, arg2->pos, arg0->rot[1], 0.0f, gCameraZoom[arg0 - camera1], 4000000.0f); + distance_if_visible(arg0->pos, arg2->pos, arg0->rot[1], 0.0f, gCameraZoom[arg0 - camera1], 4000000.0f); if (!(temp_f0 < 0.0f)) { if (((temp_v0 & 0x400) == 0) && (temp_f0 < 250000.0f)) { func_8029794C(arg2->pos, arg2->rot, 2.0f); } - mtxf_pos_rotation_xyz(sp68, arg2->pos, spA8); + mtxf_rotate_zxy_translate(sp68, arg2->pos, spA8); if (render_set_position(sp68, 0) != 0) { gDPSetTextureLUT(gDisplayListHead++, G_TT_NONE); diff --git a/src/actors/piranha_plant/render.inc.c b/src/actors/piranha_plant/render.inc.c index aae1a59a0..6c98bd599 100644 --- a/src/actors/piranha_plant/render.inc.c +++ b/src/actors/piranha_plant/render.inc.c @@ -25,7 +25,7 @@ void render_actor_piranha_plant(Camera* arg0, Mat4 arg1, struct PiranhaPlant* ar return; } - temp_f0 = is_within_render_distance(arg0->pos, arg2->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 1000000.0f); + temp_f0 = distance_if_visible(arg0->pos, arg2->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 1000000.0f); if (temp_f0 < 0.0f) { diff --git a/src/actors/railroad_crossing/render.inc.c b/src/actors/railroad_crossing/render.inc.c index f92680915..674bc3da5 100644 --- a/src/actors/railroad_crossing/render.inc.c +++ b/src/actors/railroad_crossing/render.inc.c @@ -13,11 +13,11 @@ void render_actor_railroad_crossing(Camera* arg0, struct RailroadCrossing* rr_crossing) { UNUSED Vec3s sp80 = { 0, 0, 0 }; Mat4 sp40; - f32 unk = is_within_render_distance(arg0->pos, rr_crossing->pos, arg0->rot[1], 0.0f, gCameraZoom[arg0 - camera1], - 4000000.0f); + f32 unk = distance_if_visible(arg0->pos, rr_crossing->pos, arg0->rot[1], 0.0f, gCameraZoom[arg0 - camera1], + 4000000.0f); if (!(unk < 0.0f)) { - mtxf_pos_rotation_xyz(sp40, rr_crossing->pos, rr_crossing->rot); + mtxf_rotate_zxy_translate(sp40, rr_crossing->pos, rr_crossing->rot); if (render_set_position(sp40, 0) != 0) { gSPSetGeometryMode(gDisplayListHead++, G_LIGHTING); diff --git a/src/actors/school_bus/render.inc.c b/src/actors/school_bus/render.inc.c index 2be09bee1..81cccd8c4 100644 --- a/src/actors/school_bus/render.inc.c +++ b/src/actors/school_bus/render.inc.c @@ -18,7 +18,7 @@ void render_actor_school_bus(Camera* arg0, struct Actor* arg1) { f32 temp_f0; temp_f0 = - is_within_render_distance(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); + distance_if_visible(arg0->pos, arg1->pos, arg0->rot[1], 2500.0f, gCameraZoom[arg0 - camera1], 9000000.0f); if (temp_f0 < 0.0f) { return; } @@ -26,7 +26,7 @@ void render_actor_school_bus(Camera* arg0, struct Actor* arg1) { gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(spC8, arg1->pos, arg1->rot); + mtxf_rotate_zxy_translate(spC8, arg1->pos, arg1->rot); if (render_set_position(spC8, 0) != 0) { if (gActiveScreenMode == SCREEN_MODE_1P) { diff --git a/src/actors/tanker_truck/render.inc.c b/src/actors/tanker_truck/render.inc.c index 765b19a14..1703b99c9 100644 --- a/src/actors/tanker_truck/render.inc.c +++ b/src/actors/tanker_truck/render.inc.c @@ -14,15 +14,15 @@ void render_actor_tanker_truck(Camera* camera, struct Actor* arg1) { UNUSED s32 pad[6]; Mat4 spC8; UNUSED s32 pad2[32]; - f32 temp_f0 = is_within_render_distance(camera->pos, arg1->pos, camera->rot[1], 2500.0f, - gCameraZoom[camera - camera1], 9000000.0f); + f32 temp_f0 = distance_if_visible(camera->pos, arg1->pos, camera->rot[1], 2500.0f, + gCameraZoom[camera - camera1], 9000000.0f); if (!(temp_f0 < 0.0f)) { gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(spC8, arg1->pos, arg1->rot); + mtxf_rotate_zxy_translate(spC8, arg1->pos, arg1->rot); if (render_set_position(spC8, 0) != 0) { if (gActiveScreenMode == SCREEN_MODE_1P) { diff --git a/src/actors/train/render.inc.c b/src/actors/train/render.inc.c index 440bcca25..c5b8dfc7c 100644 --- a/src/actors/train/render.inc.c +++ b/src/actors/train/render.inc.c @@ -19,8 +19,8 @@ void render_actor_train_engine(Camera* camera, struct TrainCar* actor) { Mat4 spE0; Mat4 spA0; - f32 distance = is_within_render_distance(camera->pos, actor->pos, camera->rot[1], 2500.0f, - gCameraZoom[camera - camera1], 9000000.0f); + f32 distance = distance_if_visible(camera->pos, actor->pos, camera->rot[1], 2500.0f, + gCameraZoom[camera - camera1], 9000000.0f); if (distance < 0.0f) { return; @@ -28,7 +28,7 @@ void render_actor_train_engine(Camera* camera, struct TrainCar* actor) { gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(sp120, actor->pos, actor->rot); + mtxf_rotate_zxy_translate(sp120, actor->pos, actor->rot); maxObjectsReached = render_set_position(sp120, 0) == 0; if (maxObjectsReached) { return; @@ -166,8 +166,8 @@ void render_actor_train_tender(Camera* camera, struct TrainCar* actor) { Mat4 spE0; Mat4 spA0; - f32 temp_f0 = is_within_render_distance(camera->pos, actor->pos, camera->rot[1], 625.0f, - gCameraZoom[camera - camera1], 9000000.0f); + f32 temp_f0 = distance_if_visible(camera->pos, actor->pos, camera->rot[1], 625.0f, + gCameraZoom[camera - camera1], 9000000.0f); if (temp_f0 < 0.0f) { return; @@ -175,7 +175,7 @@ void render_actor_train_tender(Camera* camera, struct TrainCar* actor) { gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(sp120, actor->pos, actor->rot); + mtxf_rotate_zxy_translate(sp120, actor->pos, actor->rot); if (render_set_position(sp120, 0) == 0) { return; } @@ -251,8 +251,8 @@ void render_actor_train_passenger_car(Camera* camera, struct TrainCar* actor) { Mat4 spE0; Mat4 spA0; - f32 temp_f0 = is_within_render_distance(camera->pos, actor->pos, camera->rot[1], 2025.0f, - gCameraZoom[camera - camera1], 9000000.0f); + f32 temp_f0 = distance_if_visible(camera->pos, actor->pos, camera->rot[1], 2025.0f, + gCameraZoom[camera - camera1], 9000000.0f); if (temp_f0 < 0.0f) { return; @@ -260,7 +260,7 @@ void render_actor_train_passenger_car(Camera* camera, struct TrainCar* actor) { gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(sp120, actor->pos, actor->rot); + mtxf_rotate_zxy_translate(sp120, actor->pos, actor->rot); if (render_set_position(sp120, 0) == 0) { return; diff --git a/src/actors/trees/render.inc.c b/src/actors/trees/render.inc.c index f8d2c6003..f7b6cea3a 100644 --- a/src/actors/trees/render.inc.c +++ b/src/actors/trees/render.inc.c @@ -19,8 +19,8 @@ void render_actor_tree_mario_raceway(Camera* camera, Mat4 arg1, struct Actor* ar return; } - temp_f0 = is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], - 16000000.0f); + temp_f0 = + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 16000000.0f); if (temp_f0 < 0.0f) { return; @@ -55,7 +55,7 @@ void render_actor_tree_yoshi_valley(Camera* camera, Mat4 arg1, struct Actor* arg } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -90,7 +90,7 @@ void render_actor_tree_royal_raceway(Camera* camera, Mat4 arg1, struct Actor* ar } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -125,7 +125,7 @@ void render_actor_tree_moo_moo_farm(Camera* camera, Mat4 arg1, struct Actor* arg } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 6250000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 6250000.0f); if (temp_f0 < 0.0f) { return; @@ -154,7 +154,7 @@ void func_80299864(Camera* camera, Mat4 arg1, struct Actor* arg2) { } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -193,7 +193,7 @@ void render_actor_tree_bowser_castle(Camera* camera, Mat4 arg1, struct Actor* ar } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -228,7 +228,7 @@ void render_actor_bush_bowser_castle(Camera* camera, Mat4 arg1, struct Actor* ar } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 640000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 640000.0f); if (temp_f0 < 0.0f) { return; @@ -263,7 +263,7 @@ void render_actor_tree_frappe_snowland(Camera* camera, Mat4 arg1, struct Actor* } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -297,7 +297,7 @@ void render_actor_tree_cactus1_kalimari_desert(Camera* camera, Mat4 arg1, struct } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -331,7 +331,7 @@ void render_actor_tree_cactus2_kalimari_desert(Camera* camera, Mat4 arg1, struct } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; @@ -365,7 +365,7 @@ void render_actor_tree_cactus3_kalimari_desert(Camera* camera, Mat4 arg1, struct } temp_f0 = - is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); + distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 < 0.0f) { return; diff --git a/src/actors/wario_sign/render.inc.c b/src/actors/wario_sign/render.inc.c index 14ee040f0..46058d050 100644 --- a/src/actors/wario_sign/render.inc.c +++ b/src/actors/wario_sign/render.inc.c @@ -12,14 +12,13 @@ */ void render_actor_wario_sign(Camera* arg0, struct Actor* arg1) { Mat4 sp38; - f32 unk = - is_within_render_distance(arg0->pos, arg1->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 16000000.0f); + f32 unk = distance_if_visible(arg0->pos, arg1->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 16000000.0f); if (!(unk < 0.0f)) { gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - mtxf_pos_rotation_xyz(sp38, arg1->pos, arg1->rot); + mtxf_rotate_zxy_translate(sp38, arg1->pos, arg1->rot); if (render_set_position(sp38, 0) != 0) { gSPDisplayList(gDisplayListHead++, d_course_wario_stadium_dl_sign); diff --git a/src/actors/yoshi_egg/render.inc.c b/src/actors/yoshi_egg/render.inc.c index 8663bc53c..c5e0db9b4 100644 --- a/src/actors/yoshi_egg/render.inc.c +++ b/src/actors/yoshi_egg/render.inc.c @@ -20,8 +20,8 @@ void render_actor_yoshi_egg(Camera* arg0, Mat4 arg1, struct YoshiValleyEgg* egg, f32 temp_f0; if (gGamestate != CREDITS_SEQUENCE) { - temp_f0 = is_within_render_distance(arg0->pos, egg->pos, arg0->rot[1], 200.0f, gCameraZoom[arg0 - camera1], - 16000000.0f); + temp_f0 = distance_if_visible(arg0->pos, egg->pos, arg0->rot[1], 200.0f, gCameraZoom[arg0 - camera1], + 16000000.0f); if (temp_f0 < 0.0f) { return; } @@ -42,7 +42,7 @@ void render_actor_yoshi_egg(Camera* arg0, Mat4 arg1, struct YoshiValleyEgg* egg, sp5C[0] = 0; sp5C[1] = egg->eggRot; sp5C[2] = 0; - mtxf_pos_rotation_xyz(sp60, egg->pos, sp5C); + mtxf_rotate_zxy_translate(sp60, egg->pos, sp5C); if (render_set_position(sp60, 0) == 0) { return; } diff --git a/src/camera.c b/src/camera.c index 4fb9bf656..20f3efd80 100644 --- a/src/camera.c +++ b/src/camera.c @@ -185,7 +185,7 @@ void camera_init(f32 posX, f32 posY, f32 posZ, UNUSED s16 rot, u32 arg4, s32 cam } break; } - func_802B7F7C(camera->pos, camera->lookAt, camera->rot); + planar_angles(camera->pos, camera->lookAt, camera->rot); } void func_8001CA10(Camera* camera) { @@ -234,7 +234,7 @@ void func_8001CA78(UNUSED Player* player, Camera* camera, Vec3f arg2, f32* arg3, arg2[1] = camera->lookAt[1]; arg2[2] = camera->lookAt[2]; calculate_orientation_matrix(sp74, 0, 1, 0, -0x00008000); - mtxf_translate_vec3f_mat3(sp5C, sp74); + mtxf_transform_vec3f_mat3(sp5C, sp74); if (gCurrentCourseId == COURSE_TOADS_TURNPIKE) { var_f14 = sp5C[0]; } else { @@ -245,7 +245,7 @@ void func_8001CA78(UNUSED Player* player, Camera* camera, Vec3f arg2, f32* arg3, arg2[0] += (var_f14 - camera->lookAt[0]) * 1; arg2[1] += (temp_f18 - camera->lookAt[1]) * 1; arg2[2] += (temp_f16 - camera->lookAt[2]) * 1; - mtxf_translate_vec3f_mat3(sp68, sp74); + mtxf_transform_vec3f_mat3(sp68, sp74); if (gCurrentCourseId == COURSE_TOADS_TURNPIKE) { var_f14 = sp68[0]; } else { @@ -366,7 +366,7 @@ void func_8001CCEC(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a sp84[2] /= 3.0f; } calculate_orientation_matrix(sp9C, 0, 1, 0, arg7); - mtxf_translate_vec3f_mat3(sp84, sp9C); + mtxf_transform_vec3f_mat3(sp84, sp9C); x = player->pos[0] + sp84[0]; z = player->pos[2] + sp84[2]; @@ -380,7 +380,7 @@ void func_8001CCEC(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a } else { arg2[1] += ((y - camera->lookAt[1]) * 0.5); } - mtxf_translate_vec3f_mat3(sp90, sp9C); + mtxf_transform_vec3f_mat3(sp90, sp9C); x = player->pos[0] + sp90[0]; z = player->pos[2] + sp90[2]; if ((player->effects & UNKNOWN_EFFECT_0x1000000) != UNKNOWN_EFFECT_0x1000000) { @@ -434,14 +434,14 @@ void func_8001D53C(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a arg2[1] = camera->lookAt[1]; arg2[2] = camera->lookAt[2]; calculate_orientation_matrix(sp74, 0.0f, 1.0f, 0.0f, arg6); - mtxf_translate_vec3f_mat3(sp5C, sp74); + mtxf_transform_vec3f_mat3(sp5C, sp74); stackPadding0 = player->pos[0] + sp5C[0]; stackPadding2 = player->pos[2] + sp5C[2]; stackPadding1 = player->pos[1] + sp5C[1]; arg2[0] += (stackPadding0 - camera->lookAt[0]) * 1; arg2[2] += (stackPadding2 - camera->lookAt[2]) * 1; arg2[1] += (stackPadding1 - camera->lookAt[1]) * 1; - mtxf_translate_vec3f_mat3(sp68, sp74); + mtxf_transform_vec3f_mat3(sp68, sp74); stackPadding0 = player->pos[0] + sp68[0]; stackPadding2 = player->pos[2] + sp68[2]; stackPadding1 = sp68[1] + (player->unk_074 + 1.5); @@ -477,7 +477,7 @@ void func_8001D794(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a arg2[2] = camera->lookAt[2]; calculate_orientation_matrix(sp6C, 0, 1, 0, arg6); - mtxf_translate_vec3f_mat3(sp54, sp6C); + mtxf_transform_vec3f_mat3(sp54, sp6C); test1 = player->pos[0] + sp54[0]; test3 = player->pos[2] + sp54[2]; @@ -486,7 +486,7 @@ void func_8001D794(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a arg2[1] += (test2 - camera->lookAt[1]) * 1; arg2[2] += (test3 - camera->lookAt[2]) * 1; - mtxf_translate_vec3f_mat3(sp60, sp6C); + mtxf_transform_vec3f_mat3(sp60, sp6C); test1 = player->pos[0] + sp60[0]; test3 = player->pos[2] + sp60[2]; @@ -586,7 +586,7 @@ void func_8001D944(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a sp84[2] /= 3.0f; } calculate_orientation_matrix(sp9C, 0, 1, 0, arg7); - mtxf_translate_vec3f_mat3(sp84, sp9C); + mtxf_transform_vec3f_mat3(sp84, sp9C); x = player->pos[0] + sp84[0]; z = player->pos[2] + sp84[2]; @@ -600,7 +600,7 @@ void func_8001D944(Player* player, Camera* camera, Vec3f arg2, f32* arg3, f32* a } else { arg2[1] += ((y - camera->lookAt[1]) * 0.5); } - mtxf_translate_vec3f_mat3(sp90, sp9C); + mtxf_transform_vec3f_mat3(sp90, sp9C); x = player->pos[0] + sp90[0]; z = player->pos[2] + sp90[2]; if ((player->effects & UNKNOWN_EFFECT_0x1000000) != UNKNOWN_EFFECT_0x1000000) { diff --git a/src/code_8003DC40.c b/src/code_8003DC40.c index 87c557f97..47c5d7d24 100644 --- a/src/code_8003DC40.c +++ b/src/code_8003DC40.c @@ -35,7 +35,7 @@ UNUSED void func_8003DC50(Player* player, Vec3f arg1) { arg1[2] = thing2; } arg1[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } UNUSED void func_8003DE4C(Player* player, Vec3f arg1) { @@ -59,7 +59,7 @@ UNUSED void func_8003DE4C(Player* player, Vec3f arg1) { arg1[2] = thing2; } arg1[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } // Stick to ground? @@ -87,7 +87,7 @@ void func_8003E048(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 arg3[2] = (-(player->slopeAccel / 182) * 0x32); } arg3[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003E37C(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { @@ -116,7 +116,7 @@ void func_8003E37C(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 arg3[2] = (-(player->slopeAccel / 182) * 0x32); } arg3[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003E6EC(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { @@ -138,7 +138,7 @@ void func_8003E6EC(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 arg3[2] = (-(player->slopeAccel / 182) * 0x32); } arg3[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003E9EC(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { @@ -173,7 +173,7 @@ void func_8003E9EC(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 } } arg3[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003EE2C(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { @@ -195,7 +195,7 @@ void func_8003EE2C(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 arg3[2] = (-(player->slopeAccel / 182) * 0x32); } arg3[1] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003F138(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { @@ -223,7 +223,7 @@ void func_8003F138(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4 } arg3[1] = 0.0f; arg3[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg3, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg3, player->orientationMatrix); } void func_8003F46C(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { diff --git a/src/cpu_vehicles_camera_path.c b/src/cpu_vehicles_camera_path.c index 83d32524a..952247f26 100644 --- a/src/cpu_vehicles_camera_path.c +++ b/src/cpu_vehicles_camera_path.c @@ -556,7 +556,7 @@ s16 get_angle_between_path(Vec3f arg0, Vec3f arg1) { s16 temp_ret; s16 phi_v1; - temp_ret = get_angle_between_points(arg0, arg1); + temp_ret = get_xz_angle_between_points(arg0, arg1); phi_v1 = temp_ret; if (gIsMirrorMode != 0) { phi_v1 = -temp_ret; @@ -1553,7 +1553,7 @@ void update_player(s32 playerId) { set_track_offset_position(pathIndex, D_80163090[playerId], gPlayerPathIndex); } } - player->rotation[1] = -get_angle_between_points(player->pos, gOffsetPosition); + player->rotation[1] = -get_xz_angle_between_points(player->pos, gOffsetPosition); } else { player->rotation[1] = gPathExpectedRotation[gPlayerPathIndex] @@ -1568,7 +1568,7 @@ void update_player(s32 playerId) { player->effects |= UNKNOWN_EFFECT_0x10; } if (D_801630E8[playerId] != 0) { - sPlayerAngle[playerId] = -get_angle_between_points(player->oldPos, player->pos); + sPlayerAngle[playerId] = -get_xz_angle_between_points(player->oldPos, player->pos); var_a0_2 = (gCurrentPathPointExpectedRotationPath[(sSomeNearestPathPoint + 2) % gSelectedPathCount] * 0x168) / @@ -1670,7 +1670,7 @@ void update_player(s32 playerId) { minAngle = onePointFive * 182.0f; maxAngle = -onePointFive * 182.0f; - angle = -get_angle_between_points(player->pos, gOffsetPosition); + angle = -get_xz_angle_between_points(player->pos, gOffsetPosition); angle -= (newAngle = player->rotation[1]); if ((s16) minAngle < angle) { angle = minAngle; diff --git a/src/cpu_vehicles_camera_path/bomb_kart.inc.c b/src/cpu_vehicles_camera_path/bomb_kart.inc.c index f2facdcdf..64fb2905f 100644 --- a/src/cpu_vehicles_camera_path/bomb_kart.inc.c +++ b/src/cpu_vehicles_camera_path/bomb_kart.inc.c @@ -183,7 +183,7 @@ void func_8000DF8C(s32 bombKartId) { D_80162FC0[0] = temp_v0_2->posX + sp118; D_80162FC0[1] = temp_v0_2->posY; D_80162FC0[2] = temp_v0_2->posZ + temp_f0_3; - spC2 = (get_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; + spC2 = (get_xz_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; break; case 2: var_s1 = (var_s1 + 4) % 360; @@ -203,7 +203,7 @@ void func_8000DF8C(s32 bombKartId) { D_80162FC0[0] = temp_v0_2->posX + sp118; D_80162FC0[1] = temp_v0_2->posY; D_80162FC0[2] = temp_v0_2->posZ + temp_f0_3; - spC2 = (get_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; + spC2 = (get_xz_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; break; case 3: var_f20 = bombKart->yPos + 3.5f; @@ -227,7 +227,7 @@ void func_8000DF8C(s32 bombKartId) { D_80162FC0[0] = temp_v0_4->posX; D_80162FC0[1] = temp_v0_4->posY; D_80162FC0[2] = temp_v0_4->posZ; - spC2 = (get_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; + spC2 = (get_xz_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; } else { D_80162FB0[0] = var_f22; D_80162FB0[1] = var_f20; @@ -235,7 +235,7 @@ void func_8000DF8C(s32 bombKartId) { D_80162FC0[0] = -2409.197f; D_80162FC0[1] = 0.0f; D_80162FC0[2] = -355.254f; - spC2 = (get_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; + spC2 = (get_xz_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; } temp_f14 = ((D_80162FB0[0] + D_80162FC0[0]) * 0.5f) - var_f22; temp_f16 = ((D_80162FB0[2] + D_80162FC0[2]) * 0.5f) - var_f24; @@ -265,7 +265,7 @@ void func_8000DF8C(s32 bombKartId) { D_80162FC0[1] = temp_v0_4->posY; D_80162FC0[2] = temp_v0_4->posZ; var_f20 += 3.0f - (var_s1 * 0.3f); - spC2 = (get_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; + spC2 = (get_xz_angle_between_points(D_80162FB0, D_80162FC0) * 0xFFFF) / 65520; break; default: break; diff --git a/src/cpu_vehicles_camera_path/path_calc.inc.c b/src/cpu_vehicles_camera_path/path_calc.inc.c index 0a61d2b89..fab0c3a6e 100644 --- a/src/cpu_vehicles_camera_path/path_calc.inc.c +++ b/src/cpu_vehicles_camera_path/path_calc.inc.c @@ -243,7 +243,7 @@ s16 calculate_angle_path(s32 pathIndex, s32 pathPointIndex) { sp24[0] = temp_v0->posX; sp24[1] = temp_v0->posY; sp24[2] = temp_v0->posZ; - ret = get_angle_between_points(sp30, sp24); + ret = get_xz_angle_between_points(sp30, sp24); return -ret; } diff --git a/src/cpu_vehicles_camera_path/vehicle_utils.inc.c b/src/cpu_vehicles_camera_path/vehicle_utils.inc.c index 2ecad9c47..07cf96cb9 100644 --- a/src/cpu_vehicles_camera_path/vehicle_utils.inc.c +++ b/src/cpu_vehicles_camera_path/vehicle_utils.inc.c @@ -754,7 +754,7 @@ void update_vehicle_follow_path_point(VehicleStuff* vehicle) { sp34[0] = vehicle->position[1]; sp34[1] = 0.0f; sp34[2] = sqrtf((temp_f0_3 * temp_f0_3) + (temp_f2_2 * temp_f2_2)); - thing = get_angle_between_points(sp40, sp34); + thing = get_xz_angle_between_points(sp40, sp34); adjust_angle(&vehicle->rotation[0], -thing, 100); vehicle->velocity[0] = vehicle->position[0] - sp5C; vehicle->velocity[1] = vehicle->position[1] - sp58; diff --git a/src/data/some_data.c b/src/data/some_data.c index f41c9a52f..88bff8bf6 100644 --- a/src/data/some_data.c +++ b/src/data/some_data.c @@ -1,6 +1,6 @@ #include "some_data.h" -Vtx D_800E49C0[] = { +Vtx gPlayerOneVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -19,7 +19,7 @@ Vtx D_800E49C0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E4AC0[] = { +Vtx gPlayerTwoVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -38,7 +38,7 @@ Vtx D_800E4AC0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E4BC0[] = { +Vtx gPlayerThreeVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -57,7 +57,7 @@ Vtx D_800E4BC0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E4CC0[] = { +Vtx gPlayerFourVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -76,7 +76,7 @@ Vtx D_800E4CC0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E4DC0[] = { +Vtx gPlayerFiveVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -95,7 +95,7 @@ Vtx D_800E4DC0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E4EC0[] = { +Vtx gPlayerSixVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -112,10 +112,10 @@ Vtx D_800E4EC0[] = { { { { 9, 0, -6 }, 0, { 0, 1792 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 0, -6 }, 0, { 4032, 1792 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, - { { { -9, 9, -6 }, 0, { 0, 0 }, { 0xFF, 0xFF, 0xFF, 0x60 } } }, + { { { -9, 9, -6 }, 0, { 0, 0 }, { 0xFF, 0xFF, 0xFF, 0x60 } } }, // useless }; -Vtx D_800E4FD0[] = { +Vtx gPlayerSevenVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, @@ -134,7 +134,7 @@ Vtx D_800E4FD0[] = { { { { -9, 9, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, }; -Vtx D_800E50D0[] = { +Vtx gPlayerEightVtx[] = { { { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { 9, 9, -6 }, 0, { 4032, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, { { { -9, 9, -6 }, 0, { 0, 1984 }, { 0xFF, 0xFF, 0xFF, 0xFF } } }, diff --git a/src/data/some_data.h b/src/data/some_data.h index ea3854583..d1ec8262b 100644 --- a/src/data/some_data.h +++ b/src/data/some_data.h @@ -6,14 +6,14 @@ #include "data/other_textures.h" #include "objects.h" -extern Vtx D_800E49C0[]; -extern Vtx D_800E4AC0[]; -extern Vtx D_800E4BC0[]; -extern Vtx D_800E4CC0[]; -extern Vtx D_800E4DC0[]; -extern Vtx D_800E4EC0[]; -extern Vtx D_800E4FD0[]; -extern Vtx D_800E50D0[]; +extern Vtx gPlayerOneVtx[]; +extern Vtx gPlayerTwoVtx[]; +extern Vtx gPlayerThreeVtx[]; +extern Vtx gPlayerFourVtx[]; +extern Vtx gPlayerFiveVtx[]; +extern Vtx gPlayerSixVtx[]; +extern Vtx gPlayerSevenVtx[]; +extern Vtx gPlayerEightVtx[]; extern Vtx D_800E51D0[]; extern Vtx D_800E5210[]; extern Vtx gBalloonVertexPlane1[]; diff --git a/src/effects.c b/src/effects.c index 586b02246..ba2f79a15 100644 --- a/src/effects.c +++ b/src/effects.c @@ -1893,7 +1893,7 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { case 2: func_80090178(player, playerId, sp44, sp38); // Fakematch found by Verti, who knows what's going on here - player->rotation[1] = (u16) -get_angle_between_points(sp44, sp38) & 0xFFFF; + player->rotation[1] = (u16) -get_xz_angle_between_points(sp44, sp38) & 0xFFFF; player->pos[0] = sp44[0]; player->pos[1] = sp44[1] + 40.0f; player->pos[2] = sp44[2]; diff --git a/src/player_controller.c b/src/player_controller.c index cd4e2c3f0..2d28f7399 100644 --- a/src/player_controller.c +++ b/src/player_controller.c @@ -728,9 +728,9 @@ void func_8002934C(Player* player, Camera* camera, s8 screenId, s8 playerId) { temp_f0 = player->unk_230 - player->unk_23C; if ((player->effects & 8) != 8) { if ((player->effects & LIGHTNING_EFFECT) == LIGHTNING_EFFECT) { - player->unk_0CC[screenId] = (s16) ((s32) (((f64) func_802B7C40(temp_f0 / temp_f2)) * 1.6)); + player->unk_0CC[screenId] = (s16) ((s32) (((f64) atan1s(temp_f0 / temp_f2)) * 1.6)); } else { - player->unk_0CC[screenId] = func_802B7C40(temp_f0 / temp_f2) * 2; + player->unk_0CC[screenId] = atan1s(temp_f0 / temp_f2) * 2; } } if ((player->effects & HIT_EFFECT) == HIT_EFFECT) { @@ -738,14 +738,14 @@ void func_8002934C(Player* player, Camera* camera, s8 screenId, s8 playerId) { } if ((player->effects & 8) != 8) { temp_f0 = player->unk_1F8 - player->unk_1FC; - player->unk_0D4[screenId] = (((func_802B7C40(temp_f0 / temp_f2)) * 0.9)); + player->unk_0D4[screenId] = (((atan1s(temp_f0 / temp_f2)) * 0.9)); } else { if (((player->animFrameSelector[screenId]) >= 0) && ((player->animFrameSelector[screenId]) < 0x101)) { var_f0 = player->oldPos[1] - player->pos[1]; } else { var_f0 = player->pos[1] - player->oldPos[1]; } - player->unk_0D4[screenId] = (s16) ((s32) (((f64) func_802B7C40(var_f0 / temp_f2)) * 0.5)); + player->unk_0D4[screenId] = (s16) ((s32) (((f64) atan1s(var_f0 / temp_f2)) * 0.5)); } if ((player->effects & HIT_EFFECT) == HIT_EFFECT) { player->unk_0D4[screenId] = (s16) ((s32) player->unk_D9C); @@ -874,7 +874,7 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { sp8C[0] = var_f12 - 3.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = var_f12 - 2.0f; - mtxf_translate_vec3f_mat3(sp8C, sp5C); + mtxf_transform_vec3f_mat3(sp8C, sp5C); sp80[0] = player->tyres[FRONT_LEFT].pos[0]; sp80[1] = player->tyres[FRONT_LEFT].pos[1]; sp80[2] = player->tyres[FRONT_LEFT].pos[2]; @@ -885,7 +885,7 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { sp8C[0] = (-var_f12) + 3.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = var_f12 - 2.0f; - mtxf_translate_vec3f_mat3(sp8C, sp5C); + mtxf_transform_vec3f_mat3(sp8C, sp5C); sp80[0] = player->tyres[FRONT_RIGHT].pos[0]; sp80[1] = player->tyres[FRONT_RIGHT].pos[1]; sp80[2] = player->tyres[FRONT_RIGHT].pos[2]; @@ -896,7 +896,7 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { sp8C[0] = var_f12 - 2.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = (-var_f12) + 4.0f; - mtxf_translate_vec3f_mat3(sp8C, sp5C); + mtxf_transform_vec3f_mat3(sp8C, sp5C); sp80[0] = player->tyres[BACK_LEFT].pos[0]; sp80[1] = player->tyres[BACK_LEFT].pos[1]; sp80[2] = player->tyres[BACK_LEFT].pos[2]; @@ -907,7 +907,7 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { sp8C[0] = (-var_f12) + 2.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = (-var_f12) + 4.0f; - mtxf_translate_vec3f_mat3(sp8C, sp5C); + mtxf_transform_vec3f_mat3(sp8C, sp5C); sp80[0] = player->tyres[BACK_RIGHT].pos[0]; sp80[1] = player->tyres[BACK_RIGHT].pos[1]; sp80[2] = player->tyres[BACK_RIGHT].pos[2]; @@ -930,16 +930,16 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { } temp_f2_3 = ((gCharacterSize[player->characterId] * 18.0f) + 1.0f) * player->size; temp_f0_2 = player->unk_23C - player->unk_230; - player->unk_206 = -func_802B7C40(temp_f0_2 / temp_f2_3); + player->unk_206 = -atan1s(temp_f0_2 / temp_f2_3); if (((player->unk_0CA & 2) == 2) || (player->effects & 8)) { player->unk_206 = 0; } if ((player->effects & 8) != 8) { temp_f0_2 = player->unk_1F8 - player->unk_1FC; - move_s16_towards(&player->slopeAccel, func_802B7C40(temp_f0_2 / temp_f2_3), 0.5f); + move_s16_towards(&player->slopeAccel, atan1s(temp_f0_2 / temp_f2_3), 0.5f); } else { temp_f0_2 = player->oldPos[1] - arg2; - temp_v0 = func_802B7C40(temp_f0_2 / temp_f2_3); + temp_v0 = atan1s(temp_f0_2 / temp_f2_3); if (temp_f0_2 >= 0.0f) { temp_v0 /= 4; } else { @@ -1017,13 +1017,13 @@ void func_8002A194(Player* player, f32 x, f32 y, f32 z) { player->tyres[FRONT_LEFT].surfaceType = player->surfaceType; var_f20 = (gCharacterSize[player->characterId] * 18) + 1; temp_f0 = (player->unk_23C - player->unk_230); - player->unk_206 = -func_802B7C40(temp_f0 / var_f20); + player->unk_206 = -atan1s(temp_f0 / var_f20); if ((player->effects & 8) != 8) { temp_f0 = (player->unk_1F8 - player->unk_1FC); - move_s16_towards(&player->slopeAccel, func_802B7C40(temp_f0 / var_f20), 0.5f); + move_s16_towards(&player->slopeAccel, atan1s(temp_f0 / var_f20), 0.5f); } else { temp_f0 = player->oldPos[1] - y; - temp_v0 = func_802B7C40(temp_f0 / var_f20); + temp_v0 = atan1s(temp_f0 / var_f20); if (temp_f0 >= 0.0f) { var_a1 = temp_v0 * 2; } else { @@ -1548,7 +1548,7 @@ void func_8002B9CC(Player* player, s8 playerIndex, UNUSED s32 arg2) { func_8008C73C(player, playerIndex); } } - temp = (-(s16) get_angle_between_points(player->pos, &player->oldPos[0])); + temp = (-(s16) get_xz_angle_between_points(player->pos, &player->oldPos[0])); temp2 = (player->rotation[1] - player->unk_0C0); temp = temp - temp2; player->unk_234 = temp / 182; @@ -1582,15 +1582,15 @@ void func_8002BB9C(Player* player, f32* arg1, f32* arg2, UNUSED s8 arg3, UNUSED sp58[1] = 0; sp58[2] = *arg2; - mtxf_translate_vec3f_mat3(sp58, sp64); + mtxf_transform_vec3f_mat3(sp58, sp64); sp4C[0] = player->oldPos[0]; sp4C[1] = 0; sp4C[2] = player->oldPos[2]; - mtxf_translate_vec3f_mat3(sp4C, sp64); + mtxf_transform_vec3f_mat3(sp4C, sp64); - var_v0 = -(s16) get_angle_between_points(sp58, sp4C); + var_v0 = -(s16) get_xz_angle_between_points(sp58, sp4C); t0 = player->rotation[1]; var_v0 = 0x10000 + (t0 - var_v0); var_v0 /= 182; @@ -2005,7 +2005,7 @@ void func_8002D028(Player* player, s8 playerIndex) { sp4C[1] = 0; sp4C[2] = D_80165230[D_80165270[playerIndex]]; - temp = -(s16) get_angle_between_points(player->pos, sp4C); + temp = -(s16) get_xz_angle_between_points(player->pos, sp4C); temp2 = player->rotation[1]; temp = (temp - temp2); @@ -2136,12 +2136,12 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player sp178[2] = 0.0f; } sp178[1] = 0.0f; - mtxf_translate_vec3f_mat3(sp178, player->orientationMatrix); + mtxf_transform_vec3f_mat3(sp178, player->orientationMatrix); gravityX += sp178[0]; gravityZ += sp178[2]; func_8002C7E4(player, playerId, screenId); sp184[2] = func_80030150(player, playerId); - mtxf_translate_vec3f_mat3(sp184, player->orientationMatrix); + mtxf_transform_vec3f_mat3(sp184, player->orientationMatrix); newVelocity[0] = player->velocity[0]; newVelocity[1] = player->velocity[1]; newVelocity[2] = player->velocity[2]; @@ -2436,9 +2436,9 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } spEC[2] = func_80030150(player, playerId); if (sp46 == 1) { - mtxf_translate_vec3f_mat3(spEC, player->unk_150); + mtxf_transform_vec3f_mat3(spEC, player->unk_150); } else { - mtxf_translate_vec3f_mat3(spEC, player->orientationMatrix); + mtxf_transform_vec3f_mat3(spEC, player->orientationMatrix); } newVelocity[0] = player->velocity[0]; newVelocity[1] = player->velocity[1]; @@ -2657,7 +2657,7 @@ void control_cpu_movement(Player* player, UNUSED Camera* camera, s8 screenId, s8 player->unk_256 = 0; player->effects &= ~0x8000; spF4[2] = func_80030150(player, playerId); - mtxf_translate_vec3f_mat3(spF4, player->orientationMatrix); + mtxf_transform_vec3f_mat3(spF4, player->orientationMatrix); newVelocity[0] = player->velocity[0]; newVelocity[1] = 0; newVelocity[2] = player->velocity[2]; @@ -2731,7 +2731,7 @@ void func_8002F730(Player* player, UNUSED Camera* camera, UNUSED s8 screenId, s8 sp7C = player->unk_064[2] * 0; spF4[2] = func_80030150(player, playerId); - mtxf_translate_vec3f_mat3(spF4, player->orientationMatrix); + mtxf_transform_vec3f_mat3(spF4, player->orientationMatrix); newVelocity[0] = player->velocity[0]; newVelocity[1] = player->velocity[1]; @@ -4239,7 +4239,7 @@ void func_80036DB4(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if (((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) && ((player->effects & 2) != 2)) { var_f18 = player->unk_208 + ((-(player->speed / 18.0f) * 216.0f) * 3.0f) + (-player->unk_20C * 10.0f); @@ -4280,7 +4280,7 @@ void func_80036DB4(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = (player->unk_090 + var_f18) * player->speed; arg1[1] = 0.0f; arg1[2] = player->speed * sp20; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4297,7 +4297,7 @@ void func_800371F4(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if (((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) && ((player->effects & 2) != 2)) { var_f18 = player->unk_208 + ((-(player->speed / 18.0f) * 216.0f) * 3.0f) + (-player->unk_20C * 50.0f); @@ -4341,7 +4341,7 @@ void func_800371F4(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = -(player->unk_090 + var_f18) * player->speed; arg1[1] = 0.0f; arg1[2] = player->speed * sp20; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4356,7 +4356,7 @@ void func_80037614(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if (((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) && ((player->effects & 2) != 2)) { var_f2 = ((-(player->speed / 18.0f) * 216.0f) * 2) + -80.0f; @@ -4368,7 +4368,7 @@ void func_80037614(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = (var_f2 + 28.0f) * player->speed; arg1[1] = 0.0f; arg1[2] = var_f12 * player->speed; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4384,7 +4384,7 @@ void func_8003777C(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if (((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) && ((player->effects & 2) != 2)) { var_f2 = ((-(player->speed / 18.0f) * 216.0f) * 2) + -80.0f; @@ -4396,7 +4396,7 @@ void func_8003777C(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = -(var_f2 + 28.0f) * player->speed; arg1[1] = 0.0f; arg1[2] = var_f12 * player->speed; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4411,7 +4411,7 @@ void func_800378E8(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if ((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) { var_f2 = player->unk_208 + (-(player->speed / 18.0f) * 216.0f * 5.0f) + (-player->unk_20C * 10.0f); @@ -4423,7 +4423,7 @@ void func_800378E8(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = (player->unk_090 + var_f2) * player->speed; arg1[1] = 0.0f; arg1[2] = player->speed * var_f12; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4438,7 +4438,7 @@ void func_80037A4C(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = 0.0f; arg1[1] = 0.0f; arg1[2] = 0.0f; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } else { if ((player->effects & UNKNOWN_EFFECT_0x10) == UNKNOWN_EFFECT_0x10) { var_f2 = player->unk_208 + (-(player->speed / 18.0f) * 216.0f * 5.0f) + (-player->unk_20C * 50.0f); @@ -4450,7 +4450,7 @@ void func_80037A4C(Player* player, Vec3f arg1, Vec3f arg2) { arg1[0] = -(player->unk_090 + var_f2) * player->speed; arg1[1] = 0.0f; arg1[2] = player->speed * var_f12; - mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); + mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix); } arg2[0] = arg1[0]; arg2[1] = arg1[1]; @@ -4840,11 +4840,11 @@ void func_80038C6C(Player* player, UNUSED Camera* camera, s8 screenId, s8 player sp108[2] = 0; sp108[1] = 0; sp108[0] = 0; - mtxf_translate_vec3f_mat3(sp108, player->orientationMatrix); + mtxf_transform_vec3f_mat3(sp108, player->orientationMatrix); spA4 += sp108[0]; sp9C += sp108[2]; sp114[2] = player->unk_08C; - mtxf_translate_vec3f_mat3(sp114, player->orientationMatrix); + mtxf_transform_vec3f_mat3(sp114, player->orientationMatrix); newVelocity[0] = player->velocity[0]; newVelocity[1] = player->velocity[1]; diff --git a/src/racing/actors.c b/src/racing/actors.c index 5d43bd6ac..dd10cb589 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -424,7 +424,7 @@ void func_8029794C(Vec3f pos, Vec3s rot, f32 scale) { Mat4 sp20; pos[1] += 2.0f; - mtxf_pos_rotation_xyz(sp20, pos, rot); + mtxf_rotate_zxy_translate(sp20, pos, rot); mtxf_scale(sp20, scale); if (render_set_position(sp20, 0) != 0) { gSPDisplayList(gDisplayListHead++, D_0D007B20); @@ -489,8 +489,8 @@ void render_cows(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { sp88[0] = var_s1->pos[0] * gCourseDirection; sp88[1] = var_s1->pos[1]; sp88[2] = var_s1->pos[2]; - temp_f0 = is_within_render_distance(camera->pos, sp88, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], - 4000000.0f); + temp_f0 = + distance_if_visible(camera->pos, sp88, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], 4000000.0f); if (temp_f0 > 0.0f) { if (temp_f0 < D_8015F704) { D_8015F704 = temp_f0; @@ -631,7 +631,7 @@ void render_palm_trees(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { spD4[1] = var_s1->pos[1]; spD4[2] = var_s1->pos[2]; - if (is_within_render_distance(camera->pos, spD4, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], var_f22) < + if (distance_if_visible(camera->pos, spD4, camera->rot[1], 0.0f, gCameraZoom[camera - camera1], var_f22) < 0.0f) { var_s1++; continue; @@ -640,7 +640,7 @@ void render_palm_trees(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { test &= 0xF; test = (s16) test; if (test == 6) { - mtxf_pos_rotation_xyz(sp90, spD4, sp88); + mtxf_rotate_zxy_translate(sp90, spD4, sp88); if (!(gMatrixObjectCount < MTX_OBJECT_POOL_SIZE)) { break; } @@ -692,7 +692,7 @@ void render_actor_shell(Camera* camera, Mat4 matrix, struct ShellActor* shell) { uintptr_t phi_t3; f32 temp_f0 = - is_within_render_distance(camera->pos, shell->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 490000.0f); + distance_if_visible(camera->pos, shell->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 490000.0f); s32 maxObjectsReached; if (temp_f0 < 0.0f) { actor_not_rendered(camera, (struct Actor*) shell); @@ -755,8 +755,8 @@ UNUSED void func_8029ABD4(f32* pos, s16 state) { } void func_8029AC18(Camera* camera, Mat4 arg1, struct Actor* arg2) { - if (is_within_render_distance(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], - 4000000.0f) < 0) { + if (distance_if_visible(camera->pos, arg2->pos, camera->rot[1], 0, gCameraZoom[camera - camera1], 4000000.0f) < + 0) { return; } diff --git a/src/racing/actors_extended.c b/src/racing/actors_extended.c index 29419c63c..a8f8c716f 100644 --- a/src/racing/actors_extended.c +++ b/src/racing/actors_extended.c @@ -193,7 +193,7 @@ void func_802B0788(s16 rawStickY, struct BananaBunchParent* banana_bunch, Player var_f12 = (player->speed * 0.75f) + 4.5f + var_f0; } vec3f_set(velocity, 0.0f, var_f0, var_f12); - func_802B64C4(velocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(velocity, player->rotation[1] + player->unk_0C0); banana->velocity[0] = velocity[0]; banana->velocity[1] = velocity[1]; banana->velocity[2] = velocity[2]; @@ -431,7 +431,7 @@ void update_actor_triple_shell(TripleShellParent* parent, s16 shellType) { someVelocity[0] = 0; someVelocity[1] = 0; someVelocity[2] = 8; - func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(someVelocity, player->rotation[1] + player->unk_0C0); shell->velocity[0] = someVelocity[0]; shell->velocity[1] = someVelocity[1]; shell->velocity[2] = someVelocity[2]; @@ -457,7 +457,7 @@ void update_actor_triple_shell(TripleShellParent* parent, s16 shellType) { someVelocity[0] = 0; someVelocity[1] = 0; someVelocity[2] = 8; - func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(someVelocity, player->rotation[1] + player->unk_0C0); shell->velocity[0] = someVelocity[0]; shell->velocity[1] = someVelocity[1]; shell->velocity[2] = someVelocity[2]; @@ -483,7 +483,7 @@ void update_actor_triple_shell(TripleShellParent* parent, s16 shellType) { someVelocity[0] = 0; someVelocity[1] = 0; someVelocity[2] = 8; - func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0); + vec3f_rotate_y(someVelocity, player->rotation[1] + player->unk_0C0); shell->velocity[0] = someVelocity[0]; shell->velocity[1] = someVelocity[1]; shell->velocity[2] = someVelocity[2]; @@ -561,7 +561,7 @@ s32 init_triple_shell(TripleShellParent* parent, Player* player, s16 shellType, startingPos[0] = 0.0f; startingPos[1] = -player->boundingBoxSize; startingPos[2] = player->boundingBoxSize - 4.0f; - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); startingPos[0] += player->pos[0]; startingPos[1] += player->pos[1]; startingPos[2] += player->pos[2]; @@ -610,7 +610,7 @@ s32 use_green_shell_item(Player* player) { startingPos[2] = player->boundingBoxSize - 4.0f; // rotate to match player orientation - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); // move to player position startingPos[0] += player->pos[0]; @@ -650,7 +650,7 @@ s32 use_red_shell_item(Player* player) { startingPos[2] = player->boundingBoxSize - 4.0f; // rotate to match player orientation - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); // move to player position startingPos[0] += player->pos[0]; @@ -699,7 +699,7 @@ void func_802B2914(struct BananaBunchParent* banana_bunch, Player* player, s16 b startingPos[0] = 0.0f; startingPos[1] = -player->boundingBoxSize; startingPos[2] = -(player->boundingBoxSize + 4.0f); - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); startingPos[0] += player->pos[0]; startingPos[1] += player->pos[1]; startingPos[2] += player->pos[2]; @@ -779,7 +779,7 @@ s32 use_fake_itembox_item(Player* player) { startingPos[2] = -(player->boundingBoxSize + 4.0f); // rotate to match player orientation - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); // move to player position startingPos[0] += player->pos[0]; @@ -827,7 +827,7 @@ s32 use_banana_item(Player* player) { startingPos[2] = -(player->boundingBoxSize + 4.0f); // apply the player's orientation to the banana - mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); + mtxf_transform_vec3f_mat3(startingPos, player->orientationMatrix); // add the player's position to the banana's position startingPos[0] += player->pos[0]; diff --git a/src/racing/math_util.c b/src/racing/math_util.c index cc3799832..f677863d5 100644 --- a/src/racing/math_util.c +++ b/src/racing/math_util.c @@ -11,10 +11,10 @@ #pragma intrinsic(sqrtf, fabs) -s32 D_802B91C0[2] = { 13, 13 }; +UNUSED s32 D_802B91C0[2] = { 13, 13 }; Vec3f D_802B91C8 = { 0.0f, 0.0f, 0.0f }; -// This functions looks similar to a segment of code from func_802A4A0C in skybox_and_splitscreen.c +// This functions looks similar to a segment of code from render_skybox in skybox_and_splitscreen.c UNUSED s32 func_802B4F60(UNUSED s32 arg0, Vec3f arg1, UNUSED s32 arg2, UNUSED f32 arg3, UNUSED f32 arg4) { Mat4 sp30; f32 sp2C; @@ -28,7 +28,7 @@ UNUSED s32 func_802B4F60(UNUSED s32 arg0, Vec3f arg1, UNUSED s32 arg2, UNUSED f3 sp2C = ((sp30[0][3] * sp28) + (sp30[1][3] * sp2C) + (sp30[2][3] * sp1C[2])) + sp30[3][3]; // double wut? if (sp28 && sp28) {}; - mtxf_translate_vec3f_mat4(sp1C, sp30); + mtxf_transform_vec3f_mat4(sp1C, sp30); if (0.0f >= sp2C) { return 0; } else { @@ -44,12 +44,12 @@ UNUSED void func_802B4FF0() { * object already render Note that gMatrixObjectCount gets reset at the beginning of the game loop. So no cleanup needs * to be performed. */ -s32 render_set_position(Mat4 arg0, s32 arg1) { +s32 render_set_position(Mat4 mtx, s32 mode) { if (gMatrixObjectCount >= MTX_OBJECT_POOL_SIZE) { return 0; } - mtxf_to_mtx(&gGfxPool->mtxObject[gMatrixObjectCount], arg0); - switch (arg1) { /* irregular */ + mtxf_to_mtx(&gGfxPool->mtxObject[gMatrixObjectCount], mtx); + switch (mode) { /* irregular */ case 0: gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxObject[gMatrixObjectCount++]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); @@ -70,18 +70,41 @@ s32 render_set_position(Mat4 arg0, s32 arg1) { return 1; } -f32 func_802B51E8(Vec3f arg0, Vec3f arg1) { - f32 sub_y; - f32 sub_z; - f32 sub_x; +/* + * @brief Finds the squared distance between two points, but contains a bug when handling the z-axis + * @param from A point in 3D space + * @param to A point in 3D space + * @return Roughly the squared distance between from and to. (x**2 + y**2 + 2*z) instead of (x**2 + y**2 + z**2) + */ +f32 dist_squared_bugged(Vec3f from, Vec3f to) { + f32 deltaY; + f32 deltaZ; + f32 deltaX; - sub_x = arg1[0] - arg0[0]; - sub_y = arg1[1] - arg0[1]; - sub_z = arg1[2] - arg0[2]; - return (sub_x * sub_x) + (sub_y * sub_y) + sub_z + sub_z; + deltaX = to[0] - from[0]; + deltaY = to[1] - from[1]; + deltaZ = to[2] - from[2]; + // If the last plus was a multiplication symbol, we'd have a correct dist_squared formula + return (deltaX * deltaX) + (deltaY * deltaY) + deltaZ + deltaZ; } -s32 get_angle_between_points(Vec3f arg0, Vec3f arg1) { +/* + * @brief Finds the angle within the XZ-plane between two points (while ignoring any difference in Y) + * @param pointFrom A point in 3D space + * @param pointTo A point in 3D space + * @return Angle (N64-units) in XZ-plane between pointFrom and pointTo + */ +s32 get_xz_angle_between_points(Vec3f pointFrom, Vec3f pointTo) { + f32 deltaX; + f32 deltaZ; + deltaX = pointTo[0] - pointFrom[0]; + deltaZ = pointTo[2] - pointFrom[2]; + + return atan2s(deltaX, deltaZ); +} + +// copy of get_xz_angle_between_points +UNUSED u32 func_802B5258(Vec3f arg0, Vec3s arg1) { f32 temp_v1; f32 temp_v2; temp_v1 = arg1[0] - arg0[0]; @@ -90,26 +113,30 @@ s32 get_angle_between_points(Vec3f arg0, Vec3f arg1) { return atan2s(temp_v1, temp_v2); } -// get_angle_between_points -u32 func_802B5258(Vec3f arg0, Vec3s arg1) { - f32 temp_v1; - f32 temp_v2; - temp_v1 = arg1[0] - arg0[0]; - temp_v2 = arg1[2] - arg0[2]; - - return atan2s(temp_v1, temp_v2); +/* + * @brief sets a vector to the given coordinates + * @param dest The vector to be overriden + * @param coordX The X coordinate of the desired vector + * @param coordY The Y coordinate of the desired vector + * @param coordZ The Z coordinate of the desired vector + */ +void vec3f_set(Vec3f dest, f32 coordX, f32 coordY, f32 coordZ) { + dest[0] = coordX; + dest[1] = coordY; + dest[2] = coordZ; } -void vec3f_set(Vec3f arg0, f32 arg1, f32 arg2, f32 arg3) { - arg0[0] = arg1; - arg0[1] = arg2; - arg0[2] = arg3; -} - -void vec3s_set(Vec3s arg0, s16 arg1, s16 arg2, s16 arg3) { - arg0[0] = arg1; - arg0[1] = arg2; - arg0[2] = arg3; +/* + * @brief sets a vector to the given coordinates + * @param dest The vector to be overriden + * @param coordX The X coordinate of the desired vector + * @param coordY The Y coordinate of the desired vector + * @param coordZ The Z coordinate of the desired vector + */ +void vec3s_set(Vec3s dest, s16 coordX, s16 coordY, s16 coordZ) { + dest[0] = coordX; + dest[1] = coordY; + dest[2] = coordZ; } // These functions have bogus return values. @@ -124,6 +151,12 @@ void vec3s_set(Vec3s arg0, s16 arg1, s16 arg2, s16 arg3) { #endif #endif +/* + * @brief Copies the coordinates of a vector to another vector + * @param dest The vector to be overriden + * @param src The vector to be copied + * @return local address of destination vector + */ void* vec3f_copy_return(Vec3f dest, Vec3f src) { dest[0] = src[0]; dest[1] = src[1]; @@ -132,6 +165,11 @@ void* vec3f_copy_return(Vec3f dest, Vec3f src) { return &dest; } +/* + * @brief copies the coordinates of a vector to another vector + * @param dest The vector to be overriden + * @param src The vector to be copied + */ void vec3s_copy(Vec3s dest, Vec3s src) { dest[0] = src[0]; dest[1] = src[1]; @@ -145,62 +183,78 @@ UNUSED void* vec3f_set_return(Vec3f dest, f32 x, f32 y, f32 z) { return &dest; } -// Copy mat1 to mat2 -void mtxf_copy(Mat4 mat1, Mat4 mat2) { +/* + * @brief copies the values of a matrix to another matrix + * @param src The matrix to be copied + * @param dest The matrix to be overriden + */ +void mtxf_copy(Mat4 src, Mat4 dest) { s32 row; s32 column; for (row = 0; row < 4; row++) { for (column = 0; column < 4; column++) { - mat2[row][column] = mat1[row][column]; + dest[row][column] = src[row][column]; } } } -// mtxf_copy +/* + * @brief copies the first n values of a matrix to another matrix + * @param dest The matrix to be overriden + * @param src The matrix to be copied + * @param n The number of values to be copied + */ void mtxf_copy_n_element(s32* dest, s32* src, s32 n) { while (n-- > 0) { *dest++ = *src++; } } -// Transform a matrix to a matrix identity +/* + * @brief Transform a matrix to an identity matrix + * @param Matrix The matrix to be changed to an identity matrix + */ void mtxf_identity(Mat4 mtx) { - register s32 i; - register s32 k; + register s32 row; + register s32 col; - for (i = 0; i < 4; i++) { - for (k = 0; k < 4; k++) { - mtx[i][k] = (i == k) ? 1.0f : 0.0f; + for (row = 0; row < 4; row++) { + for (col = 0; col < 4; col++) { + mtx[row][col] = (row == col) ? 1.0f : 0.0f; } } } -// Add a translation vector to a matrix, mat is the matrix to add, dest is the destination matrix, pos is the -// translation vector -void add_translate_mat4_vec3f(Mat4 mat, Mat4 dest, Vec3f pos) { - dest[3][0] = mat[3][0] + pos[0]; - dest[3][1] = mat[3][1] + pos[1]; - dest[3][2] = mat[3][2] + pos[2]; - dest[3][3] = mat[3][3]; - dest[0][0] = mat[0][0]; - dest[0][1] = mat[0][1]; - dest[0][2] = mat[0][2]; - dest[0][3] = mat[0][3]; - dest[1][0] = mat[1][0]; - dest[1][1] = mat[1][1]; - dest[1][2] = mat[1][2]; - dest[1][3] = mat[1][3]; - dest[2][0] = mat[2][0]; - dest[2][1] = mat[2][1]; - dest[2][2] = mat[2][2]; - dest[2][3] = mat[2][3]; +/* + * @brief Add a translation vector to a matrix + * @param scr The matrix to be copied + * @param dest The matrix to be overriden with the result + * @param translate The translation vector to be added + */ +void add_translate_mat4_vec3f(Mat4 src, Mat4 dest, Vec3f translate) { + dest[3][0] = src[3][0] + translate[0]; + dest[3][1] = src[3][1] + translate[1]; + dest[3][2] = src[3][2] + translate[2]; + dest[3][3] = src[3][3]; + dest[0][0] = src[0][0]; + dest[0][1] = src[0][1]; + dest[0][2] = src[0][2]; + dest[0][3] = src[0][3]; + dest[1][0] = src[1][0]; + dest[1][1] = src[1][1]; + dest[1][2] = src[1][2]; + dest[1][3] = src[1][3]; + dest[2][0] = src[2][0]; + dest[2][1] = src[2][1]; + dest[2][2] = src[2][2]; + dest[2][3] = src[2][3]; /* - * mat(0,0) mat(0,1) mat(0,2) mat(0,3) - * mat(1,0) mat(1,1) mat(1,2) mat(1,3) - * mat(2,0) mat(2,1) mat(2,2) mat(2,3) - * mat(3,0)+pos(0) mat(3,1)+pos(1) mat(3,2)+pos(2) mat(3,3) + * src(0,0) src(0,1) src(0,2) src(0,3) + * src(1,0) src(1,1) src(1,2) src(1,3) + * src(2,0) src(2,1) src(2,2) src(2,3) + * src(3,0)+translate(0) src(3,1)+translate(1) src(3,2)+translate(2) src(3,3) */ } @@ -211,42 +265,50 @@ UNUSED void add_translate_mat4_vec3f_lite(Mat4 mat, Mat4 dest, Vec3f pos) { dest[3][2] = mat[3][2] + pos[2]; } -// create a translation matrix -void mtxf_translate(Mat4 dest, Vec3f b) { +/* + * @brief Creates a translation matrix + * @param dest The matrix to be overriden with the translation matrix + * @param translate The translation vector to be added + */ +void mtxf_translate(Mat4 dest, Vec3f translate) { mtxf_identity(dest); - dest[3][0] = b[0]; - dest[3][1] = b[1]; - dest[3][2] = b[2]; + dest[3][0] = translate[0]; + dest[3][1] = translate[1]; + dest[3][2] = translate[2]; + /* 1 0 0 0 + * 0 1 0 0 + * 0 0 1 0 + * translate[0] translate[1] translate[2] 1 + */ } /* - * @brief Creates a projection matrix based on specified frustrum (i.e. where the camera can see) - * @param projMat A dummy variable that will be overwritten with the projection matrix - * @param arg1 Unknown dummy variable (will be overwritten) - * @param vertFov vertical field of view (in degrees) - * @param aspectRatio Width / Height of player screen - * @param near near clipping distance - * @param far far clipping distance + * @brief Creates a projection matrix based on specified frustrum (i.e. where the camera can see) + * @param projMtx A dummy variable that will be overwritten with the projection matrix + * @param arg1 Unknown dummy variable (will be overwritten) + * @param vertFov vertical field of view (in degrees) + * @param aspectRatio Width / Height of player screen + * @param near near clipping distance + * @param far far clipping distance * @param homogeneousScale Scaling factor for homogeneous coordinates. Always 1.0 in game * Note the use of `2` which generates diff asm than just using floats (2.0f). */ -void get_projection_matrix(Mat4 projMat, u16* arg1, f32 vertFov, f32 aspectRatio, f32 near, f32 far, - f32 homogeneousScale) { - f32 half_cot; - s32 row_idx, col_idx; - mtxf_identity(projMat); +void mtxf_projection(Mat4 projMtx, u16* arg1, f32 vertFov, f32 aspectRatio, f32 near, f32 far, f32 homogeneousScale) { + f32 halfCot; + s32 rowIdx, colIdx; + mtxf_identity(projMtx); vertFov *= 0.017453292222222222; // convert from degrees to radians - half_cot = cosf(vertFov / 2) / sinf(vertFov / 2); - projMat[0][0] = half_cot / aspectRatio; - projMat[1][1] = half_cot; + halfCot = cosf(vertFov / 2) / sinf(vertFov / 2); + projMtx[0][0] = halfCot / aspectRatio; + projMtx[1][1] = halfCot; // Literature usually prefers the clearer equivalent -(near + far) / (far - near) - projMat[2][2] = (near + far) / (near - far); - projMat[2][3] = -1.0f; - projMat[3][2] = (2 * near * far) / (near - far); - projMat[3][3] = 0.0f; + projMtx[2][2] = (near + far) / (near - far); + projMtx[2][3] = -1.0f; + projMtx[3][2] = (2 * near * far) / (near - far); + projMtx[3][3] = 0.0f; - for (row_idx = 0; row_idx < 4; row_idx++) { - for (col_idx = 0; col_idx < 4; col_idx++) { - projMat[row_idx][col_idx] *= homogeneousScale; + for (rowIdx = 0; rowIdx < 4; rowIdx++) { + for (colIdx = 0; colIdx < 4; colIdx++) { + projMtx[rowIdx][colIdx] *= homogeneousScale; } } @@ -264,65 +326,78 @@ void get_projection_matrix(Mat4 projMat, u16* arg1, f32 vertFov, f32 aspectRatio } // Appears to only be for the skybox. mtxf_lookat from sm64 with some modifications. -void func_802B5794(Mat4 mtx, Vec3f from, Vec3f to) { +/** + * @brief Create a lookat matrix (convert to coordinates relative to camera) + * @param mtx Dummy matrix overwritten with lookat matrix + * @param from Where the camera is looking from + * @param to Where the camera is looking to + */ +void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to) { // register from sm64 but not required for matching. register f32 invLength; - f32 xColY; - f32 yColY; - f32 zColY; - f32 xColZ; - f32 yColZ; - f32 zColZ; - f32 xColX; - f32 yColX; - f32 zColX; - xColY = 0.0f; - yColY = 1.0f; - zColY = 0.0f; + // forward: direction camera lens is facing + // up: direction toward top of frame + // right: direction toward right of frame + f32 upX; + f32 upY; + f32 upZ; + f32 forwardX; + f32 forwardY; + f32 forwardZ; + f32 rightX; + f32 rightY; + f32 rightZ; - xColZ = to[0] - from[0]; - yColZ = to[1] - from[1]; - zColZ = to[2] - from[2]; + upX = 0.0f; + upY = 1.0f; + upZ = 0.0f; - invLength = -1.0 / sqrtf(xColZ * xColZ + yColZ * yColZ + zColZ * zColZ); - xColZ *= invLength; - yColZ *= invLength; - zColZ *= invLength; + forwardX = to[0] - from[0]; + forwardY = to[1] - from[1]; + forwardZ = to[2] - from[2]; - xColX = yColY * zColZ - zColY * yColZ; - yColX = zColY * xColZ - xColY * zColZ; - zColX = xColY * yColZ - yColY * xColZ; + // normalize forward vector + invLength = -1.0 / sqrtf(forwardX * forwardX + forwardY * forwardY + forwardZ * forwardZ); + forwardX *= invLength; + forwardY *= invLength; + forwardZ *= invLength; - invLength = 1.0 / sqrtf(xColX * xColX + yColX * yColX + zColX * zColX); + // Cross product (creates vector perpendicular to forward and up) + rightX = upY * forwardZ - upZ * forwardY; + rightY = upZ * forwardX - upX * forwardZ; + rightZ = upX * forwardY - upY * forwardX; - xColX *= invLength; - yColX *= invLength; - zColX *= invLength; + invLength = 1.0 / sqrtf(rightX * rightX + rightY * rightY + rightZ * rightZ); - xColY = yColZ * zColX - zColZ * yColX; - yColY = zColZ * xColX - xColZ * zColX; - zColY = xColZ * yColX - yColZ * xColX; + rightX *= invLength; + rightY *= invLength; + rightZ *= invLength; - invLength = 1.0 / sqrtf(xColY * xColY + yColY * yColY + zColY * zColY); - xColY *= invLength; - yColY *= invLength; - zColY *= invLength; + // Cross product + upX = forwardY * rightZ - forwardZ * rightY; + upY = forwardZ * rightX - forwardX * rightZ; + upZ = forwardX * rightY - forwardY * rightX; - mtx[0][0] = xColX; - mtx[1][0] = yColX; - mtx[2][0] = zColX; - mtx[3][0] = -(from[0] * xColX + from[1] * yColX + from[2] * zColX); + invLength = 1.0 / sqrtf(upX * upX + upY * upY + upZ * upZ); + upX *= invLength; + upY *= invLength; + upZ *= invLength; - mtx[0][1] = xColY; - mtx[1][1] = yColY; - mtx[2][1] = zColY; - mtx[3][1] = -(from[0] * xColY + from[1] * yColY + from[2] * zColY); + mtx[0][0] = rightX; + mtx[1][0] = rightY; + mtx[2][0] = rightZ; + mtx[3][0] = -(from[0] * rightX + from[1] * rightY + from[2] * rightZ); - mtx[0][2] = xColZ; - mtx[1][2] = yColZ; - mtx[2][2] = zColZ; - mtx[3][2] = -(from[0] * xColZ + from[1] * yColZ + from[2] * zColZ); + mtx[0][1] = upX; + mtx[1][1] = upY; + mtx[2][1] = upZ; + mtx[3][1] = -(from[0] * upX + from[1] * upY + from[2] * upZ); + + mtx[0][2] = forwardX; + mtx[1][2] = forwardY; + mtx[2][2] = forwardZ; + mtx[3][2] = -(from[0] * forwardX + from[1] * forwardY + from[2] * forwardZ); mtx[0][3] = 0.0f; mtx[1][3] = 0.0f; @@ -330,64 +405,76 @@ void func_802B5794(Mat4 mtx, Vec3f from, Vec3f to) { mtx[3][3] = 1.0f; } -// create a rotation matrix around the x axis -void mtxf_rotate_x(Mat4 mat, s16 angle) { - f32 sin_theta = sins(angle); - f32 cos_theta = coss(angle); +/* + * @brief Create a rotation matrix for rotating about the X axis + * @param mtx Dummy matrix overwritten with x-axis rotation matrix + * @param angle Angle to rotate by (in N64 units) + */ +void mtxf_rotate_x(Mat4 mtx, s16 angle) { + f32 sinAngle = sins(angle); + f32 cosAngle = coss(angle); - mtxf_identity(mat); - mat[1][1] = cos_theta; - mat[1][2] = sin_theta; - mat[2][1] = -sin_theta; - mat[2][2] = cos_theta; + mtxf_identity(mtx); + mtx[1][1] = cosAngle; + mtx[1][2] = sinAngle; + mtx[2][1] = -sinAngle; + mtx[2][2] = cosAngle; /* - * 1, 0, 0, 0, - * 0, cos_theta, sin_theta, 0, - * 0, -sin_theta, cos_theta, 0, - * 0, 0, 0, 1 + * 1, 0, 0, 0, + * 0, cosAngle, sinAngle, 0, + * 0, -sinAngle, cosAngle, 0, + * 0, 0, 0, 1 */ } -// create a rotation matrix around the y axis -void mtxf_rotate_y(Mat4 mat, s16 angle) { - f32 sin_theta = sins(angle); - f32 cos_theta = coss(angle); +/* + * @brief Create a rotation matrix for rotating about the Y axis + * @param mtx Dummy matrix overwritten with Y axis rotation matrix + * @param angle Angle to rotate by (in N64 units) + */ +void mtxf_rotate_y(Mat4 mtx, s16 angle) { + f32 sinAngle = sins(angle); + f32 cosAngle = coss(angle); - mtxf_identity(mat); - mat[0][0] = cos_theta; - mat[0][2] = -sin_theta; - mat[2][0] = sin_theta; - mat[2][2] = cos_theta; + mtxf_identity(mtx); + mtx[0][0] = cosAngle; + mtx[0][2] = -sinAngle; + mtx[2][0] = sinAngle; + mtx[2][2] = cosAngle; /* - * cos_theta, 0, -sin_theta, 0, - * 0, 1, 0, 0, - * sin_theta, 0, cos_theta, 0, - * 0, 0, 0, 1 + * cosAngle, 0, -sinAngle, 0, + * 0, 1, 0, 0, + * sinAngle, 0, cosAngle, 0, + * 0, 0, 0, 1 */ } -// create a rotation matrix around the z axis -void mtxf_s16_rotate_z(Mat4 mat, s16 angle) { - f32 sin_theta = sins(angle); - f32 cos_theta = coss(angle); +/* + * @brief Create a rotation matrix for rotating about the Z axis + * @param mtx Dummy matrix overwritten with Z axis rotation matrix + * @param angle Angle to rotate by (in N64 units) + */ +void mtxf_s16_rotate_z(Mat4 mtx, s16 angle) { + f32 sinAngle = sins(angle); + f32 cosAngle = coss(angle); - mtxf_identity(mat); - mat[0][0] = cos_theta; - mat[0][1] = sin_theta; - mat[1][0] = -sin_theta; - mat[1][1] = cos_theta; + mtxf_identity(mtx); + mtx[0][0] = cosAngle; + mtx[0][1] = sinAngle; + mtx[1][0] = -sinAngle; + mtx[1][1] = cosAngle; /* - * cos_theta, sin_theta, 0, 0, - * -sin_theta, cos_theta, 0, 0, - * 0, 0, 1, 0, - * 0, 0, 0, 1 + * cosAngle, sinAngle, 0, 0, + * -sinAngle, cosAngle, 0, 0, + * 0, 0, 1, 0, + * 0, 0, 0, 1 */ } -void func_802B5B14(Vec3f b, Vec3s rotate) { +UNUSED void func_802B5B14(Vec3f b, Vec3s rotate) { Mat4 mtx; Vec3f copy; @@ -420,104 +507,124 @@ void func_802B5B14(Vec3f b, Vec3s rotate) { b[2] = copy[0] * mtx[2][0] + copy[1] * mtx[2][1] + copy[1] * mtx[2][2]; } -void func_802B5CAC(s16 arg0, s16 arg1, Vec3f arg2) { - f32 sp2C = sins(arg1); - f32 sp28 = coss(arg1); - f32 sp24 = sins(arg0); - f32 temp_f10 = coss(arg0); +// rotates (0, 0, -1) about the x and y axis, in that order +void vec_unit_z_rotX_rotY(s16 rotY, s16 rotX, Vec3f arg2) { + f32 sinX = sins(rotX); + f32 cosX = coss(rotX); + f32 sinY = sins(rotY); + f32 cosY = coss(rotY); - arg2[0] = sp28 * sp24; - arg2[1] = sp2C; - arg2[2] = -(sp28 * temp_f10); + arg2[0] = cosX * sinY; + arg2[1] = sinX; + arg2[2] = -(cosX * cosY); + // (0, 0, -1) -> (0, sinX, -cosX) -> (cosX * sinY, sinX, -(cosX * cosY)) } -void func_802B5D30(s16 arg0, s16 arg1, s32 arg2) { +UNUSED void func_802B5D30(s16 arg0, s16 arg1, s32 arg2) { set_course_lighting((Lights1*) 0x9000000, arg0, arg1, arg2); } -/** +/* * @brief Set the course lighting object - * Uses a directional light + * Uses a directional light, rotates by Y, then X * - * @param addr - * @param arg1 - * @param arg2 - * @param arg3 + * @param lightAddr + * @param rotateAngleY + * @param rotateAngleX + * @param lightCount Always 1 in practice */ -void set_course_lighting(Lights1* addr, s16 arg1, s16 arg2, s32 arg3) { - u32 segment = SEGMENT_NUMBER2(addr); - u32 offset = SEGMENT_OFFSET(addr); +void set_course_lighting(Lights1* lightAddr, s16 rotateAngleY, s16 rotateAngleX, s32 lightCount) { + u32 segment = SEGMENT_NUMBER2(lightAddr); + u32 offset = SEGMENT_OFFSET(lightAddr); UNUSED s32 pad; - f32 sp48; - f32 sp44; - f32 sp40; + f32 sinAngleX; + f32 cosAngleX; + f32 sinAngleY; UNUSED s32 pad2[2]; - f32 temp_f10; - s32 var_v0; - s8 sp2C[3]; - Lights1* var_s0; + f32 cosAngleY; + s32 lightIdx; + s8 lightAngle[3]; + Lights1* lights; - var_s0 = (Lights1*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); - sp48 = sins(arg2); - sp44 = coss(arg2); - sp40 = sins(arg1); - temp_f10 = coss(arg1); - sp2C[0] = sp44 * sp40 * 120.0f; - sp2C[1] = 120.0f * sp48; - sp2C[2] = sp44 * temp_f10 * -120.0f; - for (var_v0 = 0; var_v0 < arg3; var_v0++, var_s0++) { - var_s0->l[0].l.dir[0] = sp2C[0]; - var_s0->l[0].l.dir[1] = sp2C[1]; - var_s0->l[0].l.dir[2] = sp2C[2]; + lights = (Lights1*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + sinAngleX = sins(rotateAngleX); + cosAngleX = coss(rotateAngleX); + sinAngleY = sins(rotateAngleY); + cosAngleY = coss(rotateAngleY); + // take (0, 0, 1), rotate by Y, then X + lightAngle[0] = cosAngleX * sinAngleY * 120.0f; + lightAngle[1] = 120.0f * sinAngleX; + lightAngle[2] = cosAngleX * cosAngleY * -120.0f; + for (lightIdx = 0; lightIdx < lightCount; lightIdx++, lights++) { + lights->l[0].l.dir[0] = lightAngle[0]; + lights->l[0].l.dir[1] = lightAngle[1]; + lights->l[0].l.dir[2] = lightAngle[2]; } } -// multiply a matrix with a number -void mtxf_scale(Mat4 mat, f32 coef) { - mat[0][0] *= coef; - mat[1][0] *= coef; - mat[2][0] *= coef; - mat[0][1] *= coef; - mat[1][1] *= coef; - mat[2][1] *= coef; - mat[0][2] *= coef; - mat[1][2] *= coef; - mat[2][2] *= coef; +/* + * @brief Scale a matrix by a given coefficient + * @param mtx Matrix to scale + * @param coef Coefficient to use when scaling + */ +void mtxf_scale(Mat4 mtx, f32 coef) { + mtx[0][0] *= coef; + mtx[1][0] *= coef; + mtx[2][0] *= coef; + mtx[0][1] *= coef; + mtx[1][1] *= coef; + mtx[2][1] *= coef; + mtx[0][2] *= coef; + mtx[1][2] *= coef; + mtx[2][2] *= coef; } -// look like create a translation and rotation matrix with arg1 position and arg2 rotation -void mtxf_pos_rotation_xyz(Mat4 out, Vec3f pos, Vec3s orientation) { - f32 sine1; - f32 cosine1; - f32 sine2; - f32 cosine2; - f32 sine3; - f32 cosine3; +/* + * @brief Matrix for rotating about Z, X, Y axes (in order) then translating + * @param dest Matrix to output + * @param translate Vector to use for translation + * @param orientation Vector of 3 rotation angles (Rz, Rx, Ry) + */ +void mtxf_rotate_zxy_translate(Mat4 dest, Vec3f translate, Vec3s orientation) { + f32 sinX; + f32 cosX; + f32 sinY; + f32 cosY; + f32 sinZ; + f32 cosZ; - sine1 = sins(orientation[0]); - cosine1 = coss(orientation[0]); - sine2 = sins(orientation[1]); - cosine2 = coss(orientation[1]); - sine3 = sins(orientation[2]); - cosine3 = coss(orientation[2]); - out[0][0] = (cosine2 * cosine3) + ((sine1 * sine2) * sine3); - out[1][0] = (-cosine2 * sine3) + ((sine1 * sine2) * cosine3); - out[2][0] = cosine1 * sine2; - out[3][0] = pos[0]; - out[0][1] = cosine1 * sine3; - out[1][1] = cosine1 * cosine3; - out[2][1] = -sine1; - out[3][1] = pos[1]; - out[0][2] = (-sine2 * cosine3) + ((sine1 * cosine2) * sine3); - out[1][2] = (sine2 * sine3) + ((sine1 * cosine2) * cosine3); - out[2][2] = cosine1 * cosine2; - out[3][2] = pos[2]; - out[0][3] = 0.0f; - out[1][3] = 0.0f; - out[2][3] = 0.0f; - out[3][3] = 1.0f; + sinX = sins(orientation[0]); + cosX = coss(orientation[0]); + sinY = sins(orientation[1]); + cosY = coss(orientation[1]); + sinZ = sins(orientation[2]); + cosZ = coss(orientation[2]); + dest[0][0] = (cosY * cosZ) + ((sinX * sinY) * sinZ); + dest[1][0] = (-cosY * sinZ) + ((sinX * sinY) * cosZ); + dest[2][0] = cosX * sinY; + dest[3][0] = translate[0]; + dest[0][1] = cosX * sinZ; + dest[1][1] = cosX * cosZ; + dest[2][1] = -sinX; + dest[3][1] = translate[1]; + dest[0][2] = (-sinY * cosZ) + ((sinX * cosY) * sinZ); + dest[1][2] = (sinY * sinZ) + ((sinX * cosY) * cosZ); + dest[2][2] = cosX * cosY; + dest[3][2] = translate[2]; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][3] = 1.0f; } - +// Product of Z, X and Y rotation matrices and a translation matrix +/* | Cz Sz 0 0|| 1 0 0 0|| Cy 0 -Sy 0|| 1 0 0 0| + |-Sz Cz 0 0|| 0 Cx Sx 0|| 0 1 0 0|| 0 1 0 0| + | 0 0 1 0|| 0 -Sx Cx 0|| Sy 0 Cy 0|| 0 0 1 0| + | 0 0 0 1|| 0 0 0 1|| 0 0 0 1|| V0 V1 V2 1|*/ +/* | CyCz + SxSySz CxSz -SyCz + SxCySz 0| + =|-CySz + SxSyCz CxCz SySz + SxCyCz 0| + | CxSy -Sx CxCy 0| + | V0 V1 V2 1|*/ UNUSED void func_802B60B4(Mat4 arg0, Vec3s arg1, Vec3s arg2) { f32 sine1; f32 cosine1; @@ -591,114 +698,147 @@ UNUSED void func_802B6374(Vec3f arg0) { arg0[2] /= temp_f0; } -// translate the vector with a matrix -void mtxf_translate_vec3f_mat3(Vec3f pos, Mat3 mat) { - f32 new_x; - f32 new_y; - f32 new_z; +/* + * @brief Given matrix M and vector v, calculates Mv + * @param vec Vector to transform + * @param mtx Matrix to use in transformation + */ +void mtxf_transform_vec3f_mat3(Vec3f vec, Mat3 mtx) { + f32 newX; + f32 newY; + f32 newZ; - new_x = (mat[0][0] * pos[0]) + (mat[0][1] * pos[1]) + (mat[0][2] * pos[2]); - new_y = (mat[1][0] * pos[0]) + (mat[1][1] * pos[1]) + (mat[1][2] * pos[2]); - new_z = (mat[2][0] * pos[0]) + (mat[2][1] * pos[1]) + (mat[2][2] * pos[2]); + newX = (mtx[0][0] * vec[0]) + (mtx[0][1] * vec[1]) + (mtx[0][2] * vec[2]); + newY = (mtx[1][0] * vec[0]) + (mtx[1][1] * vec[1]) + (mtx[1][2] * vec[2]); + newZ = (mtx[2][0] * vec[0]) + (mtx[2][1] * vec[1]) + (mtx[2][2] * vec[2]); - pos[0] = new_x; - pos[1] = new_y; - pos[2] = new_z; + vec[0] = newX; + vec[1] = newY; + vec[2] = newZ; } -// translate the vector with a matrix (with a matrix 4x4) -void mtxf_translate_vec3f_mat4(Vec3f pos, Mat4 mat) { - f32 new_x; - f32 new_y; - f32 new_z; +/* + * @brief Given matrix M and vector v, calculates Mv + * @param vec Vector to transform + * @param mtx Matrix to use in transformation + */ +void mtxf_transform_vec3f_mat4(Vec3f vec, Mat4 mat) { + f32 newX; + f32 newY; + f32 newZ; - new_x = (mat[0][0] * pos[0]) + (mat[0][1] * pos[1]) + (mat[0][2] * pos[2]); - new_y = (mat[1][0] * pos[0]) + (mat[1][1] * pos[1]) + (mat[1][2] * pos[2]); - new_z = (mat[2][0] * pos[0]) + (mat[2][1] * pos[1]) + (mat[2][2] * pos[2]); + newX = (mat[0][0] * vec[0]) + (mat[0][1] * vec[1]) + (mat[0][2] * vec[2]); + newY = (mat[1][0] * vec[0]) + (mat[1][1] * vec[1]) + (mat[1][2] * vec[2]); + newZ = (mat[2][0] * vec[0]) + (mat[2][1] * vec[1]) + (mat[2][2] * vec[2]); - pos[0] = new_x; - pos[1] = new_y; - pos[2] = new_z; + vec[0] = newX; + vec[1] = newY; + vec[2] = newZ; } UNUSED void func_802B64B0(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED s32 arg2, UNUSED s32 arg3) { } -void func_802B64C4(Vec3f arg0, s16 arg1) { - f32 sp2C = sins(arg1); - f32 temp_f0 = coss(arg1); +/* + * @brief rotates a given vector about the Y axis by amount specified + * @param vec Vector to rotate + * @param angle + */ +void vec3f_rotate_y(Vec3f vec, s16 rotAngleY) { + f32 sinAngleY = sins(rotAngleY); + f32 cosAngleY = coss(rotAngleY); - f32 temp1 = arg0[0]; - f32 temp2 = arg0[1]; - f32 temp3 = arg0[2]; + f32 vecX = vec[0]; + f32 vecY = vec[1]; + f32 vecZ = vec[2]; - arg0[0] = temp_f0 * temp1 - (sp2C * temp3); - arg0[1] = temp2; - arg0[2] = sp2C * temp1 + (temp_f0 * temp3); + vec[0] = cosAngleY * vecX - (sinAngleY * vecZ); + vec[1] = vecY; + vec[2] = sinAngleY * vecX + (cosAngleY * vecZ); } +// Standard Y-axis rotation matrix multiplication +/* |Cy 0 -Sy||Vx| + * | 0 1 0||Vy| = |CyVx - SyVz, Vy, SyVx + CyVz| + * |Sy 0 Cy||Vz| + */ -void calculate_orientation_matrix(Mat3 dest, f32 arg1, f32 arg2, f32 arg3, s16 rotationAngle) { - Mat3 mtx_rot_y; - Mat3 matrix; - s32 i, j; +/* If cosAxisY is 1, this is just rotating around the Y axis, like in mtxf_rotate_y. Otherwise, + it intends to rotate about any axis by composing with a rotation matrix for an XZ axis rotation. + However, if Y is not 1 or -1, angle calculations break. It looks like cosAxisY might always + be 1, but that is not completely confirmed. + */ +void calculate_orientation_matrix(Mat3 dest, f32 axisZ, f32 cosAxisY, f32 axisX, s16 rotationAngle) { + Mat3 mtxRotY; + Mat3 mtxRotXZ; + s32 row, col; f32 a; - f32 b; - f32 c; - f32 d; + f32 axisNormedX; + UNUSED f32 c; + f32 axisNormedZ; UNUSED s32 pad[3]; f32 sinValue; - f32 cossValue; + f32 cosValue; sinValue = sins(rotationAngle); - cossValue = coss(rotationAngle); - mtx_rot_y[0][0] = cossValue; - mtx_rot_y[2][1] = 0; - mtx_rot_y[1][2] = 0; + cosValue = coss(rotationAngle); + mtxRotY[0][0] = cosValue; + mtxRotY[2][1] = 0; + mtxRotY[1][2] = 0; - mtx_rot_y[1][1] = 1; - mtx_rot_y[2][0] = sinValue; - mtx_rot_y[0][2] = -sinValue; + mtxRotY[1][1] = 1; + mtxRotY[2][0] = sinValue; + mtxRotY[0][2] = -sinValue; - mtx_rot_y[2][2] = cossValue; - mtx_rot_y[1][0] = 0; - mtx_rot_y[0][1] = 0; + mtxRotY[2][2] = cosValue; + mtxRotY[1][0] = 0; + mtxRotY[0][1] = 0; - if (arg2 == 1) { // set matrix to identity + /* Standard rotation matrix + [cos, 0, -sin] + [ 0, 1, 0] + [sin, 0, cos] + */ - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - matrix[i][j] = (i == j) ? 1.0f : 0.0f; + if (cosAxisY == 1) { // set matrix to identity + + for (row = 0; row < 3; row++) { + for (col = 0; col < 3; col++) { + mtxRotXZ[row][col] = (row == col) ? 1.0f : 0.0f; } } - } else if (arg2 == -1) { // set matrix to identity with the second column negative + } else if (cosAxisY == -1) { // set matrix to identity with the second column negative - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - matrix[i][j] = (i == j) ? 1.0f : 0.0f; + for (row = 0; row < 3; row++) { + for (col = 0; col < 3; col++) { + mtxRotXZ[row][col] = (row == col) ? 1.0f : 0.0f; } } - matrix[1][1] = -1; + mtxRotXZ[1][1] = -1; } else { - a = (f32) - (360.0 - ((f64) (calculate_vector_angle_xy(arg2) * 180.0f) / M_PI)); - b = -arg3 / sqrtf((arg1 * arg1) + (arg3 * arg3)); - c = 0; - d = arg1 / sqrtf((arg1 * arg1) + (arg3 * arg3)); - calculate_rotation_matrix(matrix, a, b, c, d); + /* This looks like it is meant to convert from radians to degrees, but acos1f returns N64-units, not radians + suggesting this is never used because it would give wildly incorrect values. Not sure this ever actually gets + called because cosAxisY is usually 1*/ + a = (f32) - (360.0 - ((f64) (acos1f(cosAxisY) * 180.0f) / M_PI)); + axisNormedX = -axisX / sqrtf((axisZ * axisZ) + (axisX * axisX)); + axisNormedZ = axisZ / sqrtf((axisZ * axisZ) + (axisX * axisX)); + calculate_rotation_matrix(mtxRotXZ, a, axisNormedX, 0, + axisNormedZ); // rotates around something in the x-z plane } - dest[0][0] = (mtx_rot_y[0][0] * matrix[0][0]) + (mtx_rot_y[0][1] * matrix[1][0]) + (mtx_rot_y[0][2] * matrix[2][0]); - dest[1][0] = (mtx_rot_y[1][0] * matrix[0][0]) + (mtx_rot_y[1][1] * matrix[1][0]) + (mtx_rot_y[1][2] * matrix[2][0]); - dest[2][0] = (mtx_rot_y[2][0] * matrix[0][0]) + (mtx_rot_y[2][1] * matrix[1][0]) + (mtx_rot_y[2][2] * matrix[2][0]); + // mtxRotY * matrixRotXZ + dest[0][0] = (mtxRotY[0][0] * mtxRotXZ[0][0]) + (mtxRotY[0][1] * mtxRotXZ[1][0]) + (mtxRotY[0][2] * mtxRotXZ[2][0]); + dest[1][0] = (mtxRotY[1][0] * mtxRotXZ[0][0]) + (mtxRotY[1][1] * mtxRotXZ[1][0]) + (mtxRotY[1][2] * mtxRotXZ[2][0]); + dest[2][0] = (mtxRotY[2][0] * mtxRotXZ[0][0]) + (mtxRotY[2][1] * mtxRotXZ[1][0]) + (mtxRotY[2][2] * mtxRotXZ[2][0]); - dest[0][1] = (mtx_rot_y[0][0] * matrix[0][1]) + (mtx_rot_y[0][1] * matrix[1][1]) + (mtx_rot_y[0][2] * matrix[2][1]); - dest[1][1] = (mtx_rot_y[1][0] * matrix[0][1]) + (mtx_rot_y[1][1] * matrix[1][1]) + (mtx_rot_y[1][2] * matrix[2][1]); - dest[2][1] = (mtx_rot_y[2][0] * matrix[0][1]) + (mtx_rot_y[2][1] * matrix[1][1]) + (mtx_rot_y[2][2] * matrix[2][1]); + dest[0][1] = (mtxRotY[0][0] * mtxRotXZ[0][1]) + (mtxRotY[0][1] * mtxRotXZ[1][1]) + (mtxRotY[0][2] * mtxRotXZ[2][1]); + dest[1][1] = (mtxRotY[1][0] * mtxRotXZ[0][1]) + (mtxRotY[1][1] * mtxRotXZ[1][1]) + (mtxRotY[1][2] * mtxRotXZ[2][1]); + dest[2][1] = (mtxRotY[2][0] * mtxRotXZ[0][1]) + (mtxRotY[2][1] * mtxRotXZ[1][1]) + (mtxRotY[2][2] * mtxRotXZ[2][1]); - dest[0][2] = (mtx_rot_y[0][0] * matrix[0][2]) + (mtx_rot_y[0][1] * matrix[1][2]) + (mtx_rot_y[0][2] * matrix[2][2]); - dest[1][2] = (mtx_rot_y[1][0] * matrix[0][2]) + (mtx_rot_y[1][1] * matrix[1][2]) + (mtx_rot_y[1][2] * matrix[2][2]); - dest[2][2] = (mtx_rot_y[2][0] * matrix[0][2]) + (mtx_rot_y[2][1] * matrix[1][2]) + (mtx_rot_y[2][2] * matrix[2][2]); + dest[0][2] = (mtxRotY[0][0] * mtxRotXZ[0][2]) + (mtxRotY[0][1] * mtxRotXZ[1][2]) + (mtxRotY[0][2] * mtxRotXZ[2][2]); + dest[1][2] = (mtxRotY[1][0] * mtxRotXZ[0][2]) + (mtxRotY[1][1] * mtxRotXZ[1][2]) + (mtxRotY[1][2] * mtxRotXZ[2][2]); + dest[2][2] = (mtxRotY[2][0] * mtxRotXZ[0][2]) + (mtxRotY[2][1] * mtxRotXZ[1][2]) + (mtxRotY[2][2] * mtxRotXZ[2][2]); } // include in calculate_orientation_matrix @@ -724,7 +864,7 @@ UNUSED void func_802B68F8(Mat3 matrix, f32 arg1, f32 arg2, f32 arg3) { } matrix[1][1] = -1.0f; } else { - a = (f32) - (360.0 - ((f64) (calculate_vector_angle_xy(arg2) * 180.0f) / M_PI)); + a = (f32) - (360.0 - ((f64) (acos1f(arg2) * 180.0f) / M_PI)); b = -arg3 / sqrtf((arg1 * arg1) + (arg3 * arg3)); c = 0; d = arg1 / sqrtf((arg1 * arg1) + (arg3 * arg3)); @@ -732,41 +872,50 @@ UNUSED void func_802B68F8(Mat3 matrix, f32 arg1, f32 arg2, f32 arg3) { } } -void calculate_rotation_matrix(Mat3 destMatrix, s16 rotationAngle, f32 rotationX, f32 rotationY, f32 rotationZ) { +/* + * @brief Rotates a given vector about a given axis by amount specified + * @param destMatrix Overriden with the resulting matrix + * @param rotationAngle Angle to rotate (in N64 units) + * @param axisX The X component of the axis to rotate around + * @param axisY The Y component of the axis to rotate around + * @param axisZ The Z component of the axis to rotate around + */ +// Standard algorithm, but unintuitive. "Rotation matrix from axis and angle" brings up info online +void calculate_rotation_matrix(Mat3 destMatrix, s16 rotationAngle, f32 axisX, f32 axisY, f32 axisZ) { f32 sinValue; - f32 cossValue; - f32 temp_f12; - f32 temp_f10; - f32 temp_f2; + f32 cosValue; f32 temp; + f32 valueZX; + f32 valueYZ; + f32 valueXY; UNUSED s32 pad[2]; sinValue = sins((u16) rotationAngle); - cossValue = coss((u16) rotationAngle); + cosValue = coss((u16) rotationAngle); - temp_f12 = 1.0f - cossValue; + temp = 1.0f - cosValue; - temp_f10 = (rotationZ * rotationX) * temp_f12; - temp_f2 = (rotationY * rotationZ) * temp_f12; - temp = ((rotationX * rotationY) * temp_f12); + valueZX = (axisZ * axisX) * temp; + valueYZ = (axisY * axisZ) * temp; + valueXY = (axisX * axisY) * temp; - temp_f12 = rotationX * rotationX; - destMatrix[0][0] = ((1.0f - temp_f12) * cossValue) + temp_f12; - destMatrix[2][1] = temp_f2 - (rotationX * sinValue); - destMatrix[1][2] = temp_f2 + (rotationX * sinValue); + temp = axisX * axisX; + destMatrix[0][0] = ((1.0f - temp) * cosValue) + temp; + destMatrix[2][1] = valueYZ - (axisX * sinValue); + destMatrix[1][2] = valueYZ + (axisX * sinValue); - temp_f12 = rotationY * rotationY; - destMatrix[1][1] = (((1.0f - temp_f12) * cossValue) + temp_f12); - destMatrix[2][0] = temp_f10 + (rotationY * sinValue); - destMatrix[0][2] = temp_f10 - (rotationY * sinValue); + temp = axisY * axisY; + destMatrix[1][1] = (((1.0f - temp) * cosValue) + temp); + destMatrix[2][0] = valueZX + (axisY * sinValue); + destMatrix[0][2] = valueZX - (axisY * sinValue); - temp_f12 = rotationZ * rotationZ; - destMatrix[2][2] = (((1.0f - temp_f12) * cossValue) + temp_f12); - destMatrix[1][0] = temp - (rotationZ * sinValue); - destMatrix[0][1] = temp + (rotationZ * sinValue); + temp = axisZ * axisZ; + destMatrix[2][2] = (((1.0f - temp) * cosValue) + temp); + destMatrix[1][0] = valueXY - (axisZ * sinValue); + destMatrix[0][1] = valueXY + (axisZ * sinValue); } -void func_802B6BC0(Mat4 arg0, s16 arg1, f32 arg2, f32 arg3, f32 arg4) { +UNUSED void func_802B6BC0(Mat4 arg0, s16 arg1, f32 arg2, f32 arg3, f32 arg4) { f32 sine; f32 cosine; f32 temp_f0; @@ -804,7 +953,7 @@ void func_802B6BC0(Mat4 arg0, s16 arg1, f32 arg2, f32 arg3, f32 arg4) { } // look like create a translation and rotation matrix with arg1 position and arg2 rotation -void func_802B6D58(Mat4 arg0, Vec3f arg1, Vec3f arg2) { +UNUSED void func_802B6D58(Mat4 arg0, Vec3f arg1, Vec3f arg2) { f32 sine1; f32 cosine1; f32 sine2; @@ -836,40 +985,46 @@ void func_802B6D58(Mat4 arg0, Vec3f arg1, Vec3f arg2) { arg0[3][3] = 1.0f; } -void mtxf_multiplication(Mat4 dest, Mat4 mat1, Mat4 mat2) { +/** + * @brief Multiply two 4x4 matrices + * @param dest Result of multiplication is saved here + * @param mtxLeft Left matrix in product + * @param mtxRight Right matrix to product + */ +void mtxf_multiplication(Mat4 dest, Mat4 mtxLeft, Mat4 mtxRight) { Mat4 product; - product[0][0] = - (mat1[0][0] * mat2[0][0]) + (mat1[0][1] * mat2[1][0]) + (mat1[0][2] * mat2[2][0]) + (mat1[0][3] * mat2[3][0]); - product[0][1] = - (mat1[0][0] * mat2[0][1]) + (mat1[0][1] * mat2[1][1]) + (mat1[0][2] * mat2[2][1]) + (mat1[0][3] * mat2[3][1]); - product[0][2] = - (mat1[0][0] * mat2[0][2]) + (mat1[0][1] * mat2[1][2]) + (mat1[0][2] * mat2[2][2]) + (mat1[0][3] * mat2[3][2]); - product[0][3] = - (mat1[0][0] * mat2[0][3]) + (mat1[0][1] * mat2[1][3]) + (mat1[0][2] * mat2[2][3]) + (mat1[0][3] * mat2[3][3]); - product[1][0] = - (mat1[1][0] * mat2[0][0]) + (mat1[1][1] * mat2[1][0]) + (mat1[1][2] * mat2[2][0]) + (mat1[1][3] * mat2[3][0]); - product[1][1] = - (mat1[1][0] * mat2[0][1]) + (mat1[1][1] * mat2[1][1]) + (mat1[1][2] * mat2[2][1]) + (mat1[1][3] * mat2[3][1]); - product[1][2] = - (mat1[1][0] * mat2[0][2]) + (mat1[1][1] * mat2[1][2]) + (mat1[1][2] * mat2[2][2]) + (mat1[1][3] * mat2[3][2]); - product[1][3] = - (mat1[1][0] * mat2[0][3]) + (mat1[1][1] * mat2[1][3]) + (mat1[1][2] * mat2[2][3]) + (mat1[1][3] * mat2[3][3]); - product[2][0] = - (mat1[2][0] * mat2[0][0]) + (mat1[2][1] * mat2[1][0]) + (mat1[2][2] * mat2[2][0]) + (mat1[2][3] * mat2[3][0]); - product[2][1] = - (mat1[2][0] * mat2[0][1]) + (mat1[2][1] * mat2[1][1]) + (mat1[2][2] * mat2[2][1]) + (mat1[2][3] * mat2[3][1]); - product[2][2] = - (mat1[2][0] * mat2[0][2]) + (mat1[2][1] * mat2[1][2]) + (mat1[2][2] * mat2[2][2]) + (mat1[2][3] * mat2[3][2]); - product[2][3] = - (mat1[2][0] * mat2[0][3]) + (mat1[2][1] * mat2[1][3]) + (mat1[2][2] * mat2[2][3]) + (mat1[2][3] * mat2[3][3]); - product[3][0] = - (mat1[3][0] * mat2[0][0]) + (mat1[3][1] * mat2[1][0]) + (mat1[3][2] * mat2[2][0]) + (mat1[3][3] * mat2[3][0]); - product[3][1] = - (mat1[3][0] * mat2[0][1]) + (mat1[3][1] * mat2[1][1]) + (mat1[3][2] * mat2[2][1]) + (mat1[3][3] * mat2[3][1]); - product[3][2] = - (mat1[3][0] * mat2[0][2]) + (mat1[3][1] * mat2[1][2]) + (mat1[3][2] * mat2[2][2]) + (mat1[3][3] * mat2[3][2]); - product[3][3] = - (mat1[3][0] * mat2[0][3]) + (mat1[3][1] * mat2[1][3]) + (mat1[3][2] * mat2[2][3]) + (mat1[3][3] * mat2[3][3]); + product[0][0] = (mtxLeft[0][0] * mtxRight[0][0]) + (mtxLeft[0][1] * mtxRight[1][0]) + + (mtxLeft[0][2] * mtxRight[2][0]) + (mtxLeft[0][3] * mtxRight[3][0]); + product[0][1] = (mtxLeft[0][0] * mtxRight[0][1]) + (mtxLeft[0][1] * mtxRight[1][1]) + + (mtxLeft[0][2] * mtxRight[2][1]) + (mtxLeft[0][3] * mtxRight[3][1]); + product[0][2] = (mtxLeft[0][0] * mtxRight[0][2]) + (mtxLeft[0][1] * mtxRight[1][2]) + + (mtxLeft[0][2] * mtxRight[2][2]) + (mtxLeft[0][3] * mtxRight[3][2]); + product[0][3] = (mtxLeft[0][0] * mtxRight[0][3]) + (mtxLeft[0][1] * mtxRight[1][3]) + + (mtxLeft[0][2] * mtxRight[2][3]) + (mtxLeft[0][3] * mtxRight[3][3]); + product[1][0] = (mtxLeft[1][0] * mtxRight[0][0]) + (mtxLeft[1][1] * mtxRight[1][0]) + + (mtxLeft[1][2] * mtxRight[2][0]) + (mtxLeft[1][3] * mtxRight[3][0]); + product[1][1] = (mtxLeft[1][0] * mtxRight[0][1]) + (mtxLeft[1][1] * mtxRight[1][1]) + + (mtxLeft[1][2] * mtxRight[2][1]) + (mtxLeft[1][3] * mtxRight[3][1]); + product[1][2] = (mtxLeft[1][0] * mtxRight[0][2]) + (mtxLeft[1][1] * mtxRight[1][2]) + + (mtxLeft[1][2] * mtxRight[2][2]) + (mtxLeft[1][3] * mtxRight[3][2]); + product[1][3] = (mtxLeft[1][0] * mtxRight[0][3]) + (mtxLeft[1][1] * mtxRight[1][3]) + + (mtxLeft[1][2] * mtxRight[2][3]) + (mtxLeft[1][3] * mtxRight[3][3]); + product[2][0] = (mtxLeft[2][0] * mtxRight[0][0]) + (mtxLeft[2][1] * mtxRight[1][0]) + + (mtxLeft[2][2] * mtxRight[2][0]) + (mtxLeft[2][3] * mtxRight[3][0]); + product[2][1] = (mtxLeft[2][0] * mtxRight[0][1]) + (mtxLeft[2][1] * mtxRight[1][1]) + + (mtxLeft[2][2] * mtxRight[2][1]) + (mtxLeft[2][3] * mtxRight[3][1]); + product[2][2] = (mtxLeft[2][0] * mtxRight[0][2]) + (mtxLeft[2][1] * mtxRight[1][2]) + + (mtxLeft[2][2] * mtxRight[2][2]) + (mtxLeft[2][3] * mtxRight[3][2]); + product[2][3] = (mtxLeft[2][0] * mtxRight[0][3]) + (mtxLeft[2][1] * mtxRight[1][3]) + + (mtxLeft[2][2] * mtxRight[2][3]) + (mtxLeft[2][3] * mtxRight[3][3]); + product[3][0] = (mtxLeft[3][0] * mtxRight[0][0]) + (mtxLeft[3][1] * mtxRight[1][0]) + + (mtxLeft[3][2] * mtxRight[2][0]) + (mtxLeft[3][3] * mtxRight[3][0]); + product[3][1] = (mtxLeft[3][0] * mtxRight[0][1]) + (mtxLeft[3][1] * mtxRight[1][1]) + + (mtxLeft[3][2] * mtxRight[2][1]) + (mtxLeft[3][3] * mtxRight[3][1]); + product[3][2] = (mtxLeft[3][0] * mtxRight[0][2]) + (mtxLeft[3][1] * mtxRight[1][2]) + + (mtxLeft[3][2] * mtxRight[2][2]) + (mtxLeft[3][3] * mtxRight[3][2]); + product[3][3] = (mtxLeft[3][0] * mtxRight[0][3]) + (mtxLeft[3][1] * mtxRight[1][3]) + + (mtxLeft[3][2] * mtxRight[2][3]) + (mtxLeft[3][3] * mtxRight[3][3]); mtxf_copy_n_element((s32*) dest, (s32*) product, 16); } @@ -902,17 +1057,23 @@ void mtxf_to_mtx(Mtx* dest, Mat4 src) { #endif } -/** - * Comment from sm64 unverified. mk64 verison is modified - * +/* * Helper function for atan2s. Does a look up of the arctangent of y/x assuming * the resulting angle is in range [0, 0x2000] (1/8 of a circle). + * Note that this is only called by atan2s, guaranteeing that y <= x + * If y > x, it will cause out of bounds issues + * + * @brief Finds the arctan angle (in N64 units) given x, y coordinates + * @param y y coordinate + * @param x x coordinate + * @return arctan(y/x) (in N64 units) */ - u16 atan2_lookup(f32 y, f32 x) { u16 ret; if (x == 0) { + /* In a vacuum this would be incorrect. But, it works with how atan2s + is implemented, which is the only place this function is called*/ ret = gArctanTable[0]; } else { if (1000000.0f < y / x) { @@ -928,50 +1089,56 @@ u16 atan2_lookup(f32 y, f32 x) { return ret; } -/** +/* * Compute the angle from (0, 0) to (x, y) as a u16. Given that terrain is in * the xz-plane, this is commonly called with (z, x) to get a yaw angle. * sm64 but x, y swapped and returns u16. + + * @brief Finds the arctan angle (in N64 units) given x, y coordinates + * @param y y coordinate + * @param x x coordinate + * @return arctan(y/x) (in N64 units) */ -u16 atan2s(f32 x, f32 y) { +u16 atan2s(f32 y, f32 x) { u16 ret; - if (x >= 0) { - if (y >= 0) { - if (y >= x) { - ret = atan2_lookup(x, y); + if (y >= 0) { + if (x >= 0) { + if (x >= y) { + ret = atan2_lookup(y, x); } else { - ret = 0x4000 - atan2_lookup(y, x); + ret = 0x4000 - atan2_lookup(x, y); } } else { - y = -y; - if (y < x) { - ret = 0x4000 + atan2_lookup(y, x); + x = -x; + if (x < y) { + ret = 0x4000 + atan2_lookup(x, y); } else { - ret = 0x8000 - atan2_lookup(x, y); + ret = 0x8000 - atan2_lookup(y, x); } } } else { - x = -x; - if (y < 0) { - y = -y; - if (y >= x) { - ret = 0x8000 + atan2_lookup(x, y); + y = -y; + if (x < 0) { + x = -x; + if (x >= y) { + ret = 0x8000 + atan2_lookup(y, x); } else { - ret = 0xC000 - atan2_lookup(y, x); + ret = 0xC000 - atan2_lookup(x, y); } } else { - if (y < x) { - ret = 0xC000 + atan2_lookup(y, x); + if (x < y) { + ret = 0xC000 + atan2_lookup(x, y); } else { - ret = -atan2_lookup(x, y); + ret = -atan2_lookup(y, x); } } } return ret; } -f32 atan2f(f32 arg0, f32 arg1) { - return atan2s(arg0, arg1); +// @brief see atan2s +f32 atan2f(f32 y, f32 x) { + return atan2s(y, x); } #ifndef NON_MATCHING // The decomp does not support fabs @@ -1024,21 +1191,47 @@ UNUSED u16 func_802B7B50(f32 arg0, f32 arg1) { UNUSED void func_802B7C18(f32 arg0) { atan2f(arg0, 1.0f); } - -s16 func_802B7C40(f32 arg0) { - return atan2s(arg0, 1.0f); +/* + * @brief Finds the arctan angle (in N64 units) given the tangent + * @param tan Tangent of an angle + * @return arctan(tan) (in N64 units) + */ +s16 atan1s(f32 tan) { + return atan2s(tan, 1.0f); } UNUSED void func_802B7C6C(f32 arg0) { atan2f(arg0, sqrtf(1.0 - (arg0 * arg0))); } -s16 func_802B7CA8(f32 arg0) { - return atan2s(arg0, sqrtf(1.0 - (arg0 * arg0))); +/* + * @brief Finds the arcsin (in N64 units) of a value (assuming positive cosine) + * @param value Value to find the arcsin of + * @return arcsin(value) + */ +s16 asin1s(f32 value) { + return atan2s(value, sqrtf(1.0 - (value * value))); + /* if value = sin(Angle), we have + = asin(sin(Angle) / sqrt(1 - sin**2(Angle))) + = atan(sin(Angle) / sqrt(cos**2(Angle))) + = atan(sin(Angle) / cos(Angle)) + = atan(tan(Angle)) + = Angle */ } -f32 calculate_vector_angle_xy(f32 vectorX) { - return atan2f(sqrtf(1.0 - (vectorX * vectorX)), vectorX); +/* + * @brief Finds the arccos angle (in N64 units) of a value (assuming positive sine) + * @param value Value to find the arccos of + * @return arccos(value) + */ +f32 acos1f(f32 value) { + return atan2f(sqrtf(1.0 - (value * value)), value); + /* if value = cos(Angle), we have + = atan(sqrt(1 - cos**2(Angle)) / cos(Angle)) + = atan(sqrt(sin**2(Angle)) / cos(Angle)) + = atan(sin(Angle) / cos(Angle)) + = atan(tan(Angle)) + = Angle */ } UNUSED s16 func_802B7D28(f32 arg0) { @@ -1077,120 +1270,156 @@ u16 random_int(u16 arg0) { return arg0 * (((f32) random_u16()) / 65535.0); } -s16 func_802B7F34(f32 arg0, f32 arg1, f32 arg2, f32 arg3) { - return atan2s(arg2 - arg0, arg3 - arg1); +/* + * @brief Find the angle (in N64 units) between two points given their coords + * @param fromY The y coordinate of the point the angle is measured from + * @param fromX The x coordinate of the point the angle is measured from + * @param toY The y coordinate of the point the angle is measured to + * @param toX The x coordinate of the point the angle is measured to + * @return The angle (in N64 units) of the line from the from-point, to the to-point + */ +s16 get_angle_between_coords(f32 fromY, f32 fromX, f32 toY, f32 toX) { + return atan2s(toY - fromY, toX - fromX); } -void func_802B7F7C(Vec3f arg0, Vec3f arg1, Vec3s dest) { - f32 x1 = arg0[0]; - f32 y1 = arg0[1]; - f32 z1 = arg0[2]; +/* + * @brief Find the planar angles (in N64 units) between two points given their positions + * @param from The coordinates of the point the angle is measured from + * @param to The coordinate of the point the angle is measured to + * @param rotAngles Overwritten with the angles between the two points in the coordinate planes (yz, xz, xy) + */ +void planar_angles(Vec3f from, Vec3f to, Vec3s rotAngles) { + f32 fromX = from[0]; + f32 fromY = from[1]; + f32 fromZ = from[2]; - f32 x2 = arg1[0]; - f32 y2 = arg1[1]; - f32 z2 = arg1[2]; + f32 toX = to[0]; + f32 toY = to[1]; + f32 toZ = to[2]; - dest[1] = func_802B7F34(z1, x1, z2, x2); - dest[0] = func_802B7F34(y1, z1, y2, z2); - dest[2] = func_802B7F34(x1, y1, x2, y2); + rotAngles[1] = get_angle_between_coords(fromZ, fromX, toZ, toX); + rotAngles[0] = get_angle_between_coords(fromY, fromZ, toY, toZ); + rotAngles[2] = get_angle_between_coords(fromX, fromY, toX, toY); } -f32 sins(u16 arg0) { - return gSineTable[arg0 >> 4]; +/* + * @brief Get the sine of an angle + * @param angle Angle (in N64 units) + * @return sin(angle) + */ +f32 sins(u16 angle) { + return gSineTable[angle >> 4]; } -f32 coss(u16 arg0) { - return gCosineTable[arg0 >> 4]; +/* + * @brief Get the cosine of an angle + * @param angle angle (in N64 units) + * @return sin(angle) + */ +f32 coss(u16 angle) { + return gCosineTable[angle >> 4]; } -s32 is_visible_between_angle(u16 arg0, u16 arg1, u16 arg2) { - if (arg1 < arg0) { - if (arg1 >= arg2) { +/* + * @brief Checks if angle is between 2 specified angles + * @param angleCCW The counter-clockwise angle + * @param angleCW The clockwise angle + * @param angleToCheck The angle to check is between the other angles + * @return 1 if angleToCheck is between the other angles, 0 otherwise + */ +s32 is_between_angle(u16 angleCCW, u16 angleCW, u16 angleToCheck) { + if (angleCW < angleCCW) { + if (angleCW >= angleToCheck) { return 0; } - if (arg2 >= arg0) { + if (angleToCheck >= angleCCW) { return 0; } } else { - if ((arg1 >= arg2) && (arg2 >= arg0)) { + // angle straddles 0 angle + if ((angleCW >= angleToCheck) && (angleToCheck >= angleCCW)) { return 0; } } return 1; } -/** - * Determines whether an object is within the render distance of a camera. +/* + * @brief Finds the xz-distance squared between a point and the camera, if the point is visible (or near visible) to + * the camera * - * @param cameraPos The position of the camera in 3D space. - * @param objectPos The position of the object in 3D space. - * @param orientationY The orientation angle of the object around the Y-axis. - * @param minDistance The minimum distance at which the object is considered within render distance. - * @param fov The field of view (FOV) of the camera. - * @param maxDistance The maximum render distance. - * @return The distance between the camera and the object if it's within render distance, - * or -1.0f if it exceeds the render distance. + * @param cameraPos The position of the camera in 3D space. + * @param objectPos The position of the object in 3D space. + * @param orientationY The orientation angle of the object around the Y-axis. + * @param preloadDistanceSquared Consider an object within this distance of viweable area as renderable + * @param fovDegrees The field of view (FOV) of the camera (degrees). + * @param maxDistanceSquared The maximum render distance. + * @return The xz-distance squared between the camera and the object if it's within render distance + of the camera's vision, or -1.0f if it exceeds the render distance. */ -f32 is_within_render_distance(Vec3f cameraPos, Vec3f objectPos, u16 orientationY, f32 minDistance, f32 fov, - f32 maxDistance) { +f32 distance_if_visible(Vec3f cameraPos, Vec3f objectPos, u16 orientationY, f32 preloadDistanceSquared, + f32 fovDegrees, f32 maxDistanceSquared) { u16 angleObject; UNUSED u16 pad; - u16 temp_v0; - f32 distanceX; - f32 distance; - f32 distanceY; - s32 plus_fov_angle; - s32 minus_fov_angle; - u16 temp; + u16 preloadAngle; + f32 distanceXSquared; + f32 distanceSquared; + f32 distanceZSquared; + s32 plusFovAngle; + s32 minusFovAngle; + u16 adjustedAngle; UNUSED s32 pad2[3]; - u16 extended_fov = ((u16) fov * 0xB6); + u16 fovUnits = ((u16) fovDegrees * 182); // degrees to angle units (182 * 360 ~= 2**16) - distanceX = objectPos[0] - cameraPos[0]; - distanceX = distanceX * distanceX; - if (maxDistance < distanceX) { + distanceXSquared = objectPos[0] - cameraPos[0]; + distanceXSquared = distanceXSquared * distanceXSquared; + if (maxDistanceSquared < distanceXSquared) { return -1.0f; } - distanceY = objectPos[2] - cameraPos[2]; - distanceY = distanceY * distanceY; - if (maxDistance < distanceY) { + distanceZSquared = objectPos[2] - cameraPos[2]; + distanceZSquared = distanceZSquared * distanceZSquared; + if (maxDistanceSquared < distanceZSquared) { return -1.0f; } - distance = distanceX + distanceY; - if (distance < minDistance) { - return distance; + distanceSquared = distanceXSquared + distanceZSquared; + if (distanceSquared < preloadDistanceSquared) { + return distanceSquared; } - if (distance > maxDistance) { + if (distanceSquared > maxDistanceSquared) { return -1.0f; } - angleObject = get_angle_between_points(cameraPos, objectPos); - minus_fov_angle = (orientationY - extended_fov); - plus_fov_angle = (orientationY + extended_fov); + angleObject = get_xz_angle_between_points(cameraPos, objectPos); + minusFovAngle = (orientationY - fovUnits); + plusFovAngle = (orientationY + fovUnits); - if (minDistance == 0.0f) { - if (is_visible_between_angle((orientationY + extended_fov), (orientationY - extended_fov), angleObject) == 1) { - return distance; + if (preloadDistanceSquared == 0.0f) { + if (is_between_angle((orientationY + fovUnits), (orientationY - fovUnits), angleObject) == 1) { + return distanceSquared; } return -1.0f; } - if (is_visible_between_angle((u16) plus_fov_angle, (u16) minus_fov_angle, angleObject) == 1) { - return distance; - } - temp_v0 = func_802B7CA8(minDistance / distance); - temp = angleObject + temp_v0; - - if (is_visible_between_angle(plus_fov_angle, minus_fov_angle, temp) == 1) { - return distance; + if (is_between_angle((u16) plusFovAngle, (u16) minusFovAngle, angleObject) == 1) { + return distanceSquared; } - temp = angleObject - temp_v0; - if (is_visible_between_angle(plus_fov_angle, minus_fov_angle, temp) == 1) { - return distance; + /* This is bugged. This gives asin((sin(theta)**2) instead of asin(sin(theta)) = theta. + Probably unnoticed because it only deals with objects not on screen*/ + preloadAngle = asin1s(preloadDistanceSquared / distanceSquared); + adjustedAngle = angleObject + preloadAngle; + + if (is_between_angle(plusFovAngle, minusFovAngle, adjustedAngle) == 1) { + return distanceSquared; + } + + adjustedAngle = angleObject - preloadAngle; + if (is_between_angle(plusFovAngle, minusFovAngle, adjustedAngle) == 1) { + return distanceSquared; } return -1.0f; } @@ -1225,7 +1454,7 @@ UNUSED void func_802B8414(uintptr_t addr, Mat4 arg1, s16 arg2, s16 arg3, s32 arg } } -void func_802B8614(Player* arg0) { +UNUSED void func_802B8614(Player* arg0) { UNUSED f64 pad[4]; f64 corner1PosX = arg0->tyres[FRONT_RIGHT].pos[0]; f64 corner1PosY = arg0->tyres[FRONT_RIGHT].baseHeight; diff --git a/src/racing/math_util.h b/src/racing/math_util.h index 0ec5445a0..6ba4d0aa3 100644 --- a/src/racing/math_util.h +++ b/src/racing/math_util.h @@ -14,13 +14,12 @@ // Here to appease the pragma gods double fabs(double x); -void func_802B5794(Mat4, Vec3f, Vec3f); -s32 func_802B4F60(s32, Vec3f, s32, f32, f32); +void func_802B5794(Mat4, Vec3f, Vec3f); // Unused +s32 func_802B4F60(s32, Vec3f, s32, f32, f32); // Unused s32 render_set_position(Mat4, s32); -f32 func_802B51E8(Vec3f, Vec3f); -s32 get_angle_between_points(Vec3f, Vec3f); -u32 func_802B5258(Vec3f, Vec3s); -void func_802B5794(Mat4, Vec3f, Vec3f); +f32 dist_squared_bugged(Vec3f, Vec3f); +s32 get_xz_angle_between_points(Vec3f, Vec3f); +u32 func_802B5258(Vec3f, Vec3s); // Unused void vec3f_set(Vec3f, f32, f32, f32); void vec3s_set(Vec3s, s16, s16, s16); void* vec3f_copy_return(Vec3f, Vec3f); @@ -32,42 +31,42 @@ void mtxf_identity(Mat4); void add_translate_mat4_vec3f(Mat4, Mat4, Vec3f); void add_translate_mat4_vec3f_lite(Mat4, Mat4, Vec3f); void mtxf_translate(Mat4, Vec3f); -void get_projection_matrix(Mat4, u16*, f32, f32, f32, f32, f32); -void func_802B5794(Mat4, Vec3f, Vec3f); +void mtxf_projection(Mat4, u16*, f32, f32, f32, f32, f32); +void mtxf_lookat(Mat4, Vec3f, Vec3f); void mtxf_rotate_x(Mat4, s16); void mtxf_rotate_y(Mat4, s16); void mtxf_s16_rotate_z(Mat4, s16); -void func_802B5B14(Vec3f b, Vec3s rotate); // unused -void func_802B5CAC(s16, s16, Vec3f); -void func_802B5D30(s16, s16, s32); +void func_802B5B14(Vec3f b, Vec3s rotate); // Unused +void func_802B5CAC(s16, s16, Vec3f); // Unused +void func_802B5D30(s16, s16, s32); // Unused void set_course_lighting(Lights1*, s16, s16, s32); void mtxf_scale(Mat4, f32); -void mtxf_pos_rotation_xyz(Mat4, Vec3f, Vec3s); -void mtxf_translate_vec3f_mat3(Vec3f, Mat3); -void mtxf_translate_vec3f_mat4(Vec3f, Mat4); -void func_802B64C4(Vec3f, s16); +void mtxf_rotate_zxy_translate(Mat4, Vec3f, Vec3s); +void mtxf_transform_vec3f_mat3(Vec3f, Mat3); +void mtxf_transform_vec3f_mat4(Vec3f, Mat4); +void vec3f_rotate_y(Vec3f, s16); void calculate_orientation_matrix(Mat3, f32, f32, f32, s16); void calculate_rotation_matrix(Mat3, s16, f32, f32, f32); -void func_802B6BC0(Mat4, s16, f32, f32, f32); -void func_802B6D58(Mat4, Vec3f, Vec3f); +void func_802B6BC0(Mat4, s16, f32, f32, f32); // Unused +void func_802B6D58(Mat4, Vec3f, Vec3f); // Unused void mtxf_multiplication(Mat4, Mat4, Mat4); void mtxf_to_mtx(Mtx*, Mat4); u16 atan2_lookup(f32, f32); u16 atan2s(f32, f32); f32 atan2f(f32, f32); -s16 func_802B7C40(f32); -s16 func_802B7CA8(f32); -f32 calculate_vector_angle_xy(f32); +s16 atan1s(f32); +s16 asin1s(f32); +f32 acos1f(f32); u16 random_u16(void); u16 random_int(u16); -s16 func_802B7F34(f32, f32, f32, f32); -void func_802B7F7C(Vec3f, Vec3f, Vec3s); +s16 angle_from_coords(f32, f32, f32, f32); +void planar_angles(Vec3f, Vec3f, Vec3s); f32 sins(u16); f32 coss(u16); -s32 is_visible_between_angle(u16, u16, u16); -f32 is_within_render_distance(Vec3f, Vec3f, u16, f32, f32, f32); +s32 is_between_angle(u16, u16, u16); +f32 distance_if_visible(Vec3f, Vec3f, u16, f32, f32, f32); -extern s32 D_802B91C0[]; +extern s32 D_802B91C0[]; // Unused extern Vec3f D_802B91C8; #endif // MATH_UTIL_H diff --git a/src/racing/render_courses.c b/src/racing/render_courses.c index 4cb202acb..e1556abea 100644 --- a/src/racing/render_courses.c +++ b/src/racing/render_courses.c @@ -1509,7 +1509,8 @@ void course_generate_collision_mesh(void) { nullify_displaylist((uintptr_t) 0x070003C8); } parse_course_displaylists((uintptr_t) &d_course_choco_mountain_addr); - func_802B5CAC(0x238E, 0x31C7, D_8015F590); + // D_8015F590 is only used here, so this seems meaningless + vec_unit_z_rotX_rotY(0x238E, 0x31C7, D_8015F590); func_80295C6C(); D_8015F8E4 = -80.0f; break; diff --git a/src/racing/skybox_and_splitscreen.c b/src/racing/skybox_and_splitscreen.c index 81c034037..78f95fe7c 100644 --- a/src/racing/skybox_and_splitscreen.c +++ b/src/racing/skybox_and_splitscreen.c @@ -23,7 +23,7 @@ Vp D_802B8880[] = { { { { 640, 480, 511, 0 }, { 640, 480, 511, 0 } } }, }; -Vtx D_802B8890[] = { +static Vtx sSkyboxP1[] = { { { { SCREEN_WIDTH, SCREEN_HEIGHT, -1 }, 0, { 0, 0 }, { 0xC8, 0xC8, 0xFF, 0xFF } } }, { { { SCREEN_WIDTH, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, @@ -34,7 +34,7 @@ Vtx D_802B8890[] = { { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x00, 0xDC, 0x00, 0xFF } } }, }; -Vtx D_802B8910[] = { +static Vtx sSkyboxP2[] = { { { { SCREEN_WIDTH, SCREEN_HEIGHT, -1 }, 0, { 0, 0 }, { 0xC8, 0xC8, 0xFF, 0xFF } } }, { { { SCREEN_WIDTH, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, @@ -45,7 +45,7 @@ Vtx D_802B8910[] = { { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x00, 0xDC, 0x00, 0xFF } } }, }; -Vtx D_802B8990[] = { +static Vtx sSkyboxP3[] = { { { { SCREEN_WIDTH, SCREEN_HEIGHT, -1 }, 0, { 0, 0 }, { 0xC8, 0xC8, 0xFF, 0xFF } } }, { { { SCREEN_WIDTH, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, @@ -56,7 +56,7 @@ Vtx D_802B8990[] = { { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x00, 0xDC, 0x00, 0xFF } } }, }; -Vtx D_802B8A10[] = { +static Vtx sSkyboxP4[] = { { { { SCREEN_WIDTH, SCREEN_HEIGHT, -1 }, 0, { 0, 0 }, { 0xC8, 0xC8, 0xFF, 0xFF } } }, { { { SCREEN_WIDTH, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, { { { 0, 120, -1 }, 0, { 0, 0 }, { 0x1E, 0x1E, 0xFF, 0xFF } } }, @@ -443,6 +443,7 @@ void course_set_skybox_colours(Vtx* skybox) { #endif } +// Almost identical to end of render_skybox void func_802A487C(Vtx* arg0, UNUSED struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, UNUSED s32 arg3, UNUSED f32* arg4) { @@ -461,46 +462,62 @@ void func_802A487C(Vtx* arg0, UNUSED struct UnkStruct_800DC5EC* arg1, UNUSED s32 } } -void func_802A4A0C(Vtx* vtx, struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, UNUSED s32 arg3, UNUSED f32* arg4) { +/** + * @brief Sets skybox horizon. Some coordinate transformations which can affect game physics and display of player + * sprite + * @param skybox player skybox + * @param arg1 something camera related + * @param arg2 unused + * @param arg3 unused + * @parma arg4 unused + */ +void render_skybox(Vtx* skybox, struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, UNUSED s32 arg3, UNUSED f32* arg4) { Camera* camera = arg1->camera; - s16 temp_t5; - f32 temp_f0; + s16 horizonRow; + f32 homogFactor; UNUSED s32 pad[2]; UNUSED u16 pad2; u16 sp128; - Mat4 matrix1; - Mat4 matrix2; - Mat4 matrix3; - Vec3f sp5C; - f32 sp58; + Mat4 projMtx; + Mat4 lookAtMtx; + Mat4 lookAndProjMtx; + Vec3f horizonPoint; + f32 homogScale; - course_set_skybox_colours(vtx); - sp5C[0] = 0.0f; - sp5C[1] = 0.0f; - sp5C[2] = 30000.0f; - get_projection_matrix(matrix1, &sp128, camera->unk_B4, gScreenAspect, gCourseNearPersp, gCourseFarPersp, 1.0f); - func_802B5794(matrix2, camera->pos, camera->lookAt); - mtxf_multiplication(matrix3, matrix1, matrix2); + course_set_skybox_colours(skybox); - sp58 = ((matrix3[0][3] * sp5C[0]) + (matrix3[1][3] * sp5C[1]) + (matrix3[2][3] * sp5C[2])) + matrix3[3][3]; + // horizonPoint is an apparently arbitrary point on the horizon (technically, where y = 0). Used for skybox horizon + horizonPoint[0] = 0.0f; + horizonPoint[1] = 0.0f; + horizonPoint[2] = 30000.0f; + mtxf_projection(projMtx, &sp128, camera->unk_B4, gScreenAspect, gCourseNearPersp, gCourseFarPersp, 1.0f); + mtxf_lookat(lookAtMtx, camera->pos, camera->lookAt); + mtxf_multiplication(lookAndProjMtx, projMtx, lookAtMtx); - mtxf_translate_vec3f_mat4(sp5C, matrix3); + /* math would have been simpler if horizonPoint had an additional homogenous coordinate set to 1. Recreated here in + extra steps */ + homogScale = ((lookAndProjMtx[0][3] * horizonPoint[0]) + (lookAndProjMtx[1][3] * horizonPoint[1]) + + (lookAndProjMtx[2][3] * horizonPoint[2])) + + lookAndProjMtx[3][3]; + mtxf_transform_vec3f_mat4(horizonPoint, lookAndProjMtx); - temp_f0 = (1.0 / sp58); + homogFactor = (1.0 / homogScale); - sp5C[0] *= temp_f0; - sp5C[1] *= temp_f0; + horizonPoint[0] *= homogFactor; + horizonPoint[1] *= homogFactor; - sp5C[0] *= 160.0f; - sp5C[1] *= 120.0f; + horizonPoint[0] *= 160.0f; // SCREEN_WIDTH / 2 + horizonPoint[1] *= 120.0f; // SCREEN_HEIGHT / 2 - temp_t5 = 120 - (s16) sp5C[1]; - arg1->cameraHeight = temp_t5; - vtx[1].v.ob[1] = temp_t5; - vtx[2].v.ob[1] = temp_t5; - vtx[4].v.ob[1] = temp_t5; - vtx[7].v.ob[1] = temp_t5; + horizonRow = 120 - (s16) horizonPoint[1]; + arg1->cameraHeight = horizonRow; + skybox[1].v.ob[1] = horizonRow; + skybox[2].v.ob[1] = horizonRow; + skybox[4].v.ob[1] = horizonRow; + skybox[7].v.ob[1] = horizonRow; + + // this section reders the skybox. Unclear if it does anything else init_rdp(); gDPSetRenderMode(gDisplayListHead++, G_RM_OPA_SURF, G_RM_OPA_SURF2); gSPClearGeometryMode(gDisplayListHead++, G_ZBUFFER | G_LIGHTING); @@ -509,10 +526,10 @@ void func_802A4A0C(Vtx* vtx, struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, U gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxScreen), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_0D008E98), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPVertex(gDisplayListHead++, &vtx[0], 4, 0); + gSPVertex(gDisplayListHead++, &skybox[0], 4, 0); gSP2Triangles(gDisplayListHead++, 0, 3, 1, 0, 1, 3, 2, 0); if (gCurrentCourseId == COURSE_RAINBOW_ROAD) { - gSPVertex(gDisplayListHead++, &vtx[4], 4, 0); + gSPVertex(gDisplayListHead++, &skybox[4], 4, 0); gSP2Triangles(gDisplayListHead++, 0, 3, 1, 0, 1, 3, 2, 0); } } @@ -604,7 +621,7 @@ void func_802A4EF4(void) { break; } } - +// player 2 vertical void func_802A5004(void) { init_rdp(); @@ -616,13 +633,13 @@ void func_802A5004(void) { func_802A39E0(D_800DC5F0); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + render_skybox((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80057FC4(2); - func_802A487C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + func_802A487C((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80093A30(2); } } - +// player 1 vertical void func_802A50EC(void) { init_rdp(); @@ -633,13 +650,13 @@ void func_802A50EC(void) { func_802A39E0(D_800DC5EC); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8890, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); + render_skybox((Vtx*) sSkyboxP1, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); func_80057FC4(1); - func_802A487C((Vtx*) D_802B8890, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); + func_802A487C((Vtx*) sSkyboxP1, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); func_80093A30(1); } } - +// player 1 horizontal void func_802A51D4(void) { init_rdp(); @@ -650,13 +667,13 @@ void func_802A51D4(void) { gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CLIPPING); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8890, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); + render_skybox((Vtx*) sSkyboxP1, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); func_80057FC4(3); - func_802A487C((Vtx*) D_802B8890, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); + func_802A487C((Vtx*) sSkyboxP1, D_800DC5EC, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[0]); func_80093A30(3); } } - +// player 2 horizontal void func_802A52BC(void) { init_rdp(); @@ -667,13 +684,13 @@ void func_802A52BC(void) { gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CLIPPING); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + render_skybox((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80057FC4(4); - func_802A487C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + func_802A487C((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80093A30(4); } } - +// player 1 solo void func_802A53A4(void) { move_segment_table_to_dmem(); @@ -686,15 +703,15 @@ void func_802A53A4(void) { init_z_buffer(); select_framebuffer(); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8890, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); + render_skybox((Vtx*) sSkyboxP1, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); if (gGamestate != CREDITS_SEQUENCE) { func_80057FC4(0); } - func_802A487C((Vtx*) D_802B8890, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); + func_802A487C((Vtx*) sSkyboxP1, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); func_80093A30(0); } } - +// player 1 3p 4p void func_802A54A8(void) { init_rdp(); @@ -705,13 +722,13 @@ void func_802A54A8(void) { gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CLIPPING); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8890, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); + render_skybox((Vtx*) sSkyboxP1, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); func_80057FC4(8); - func_802A487C((Vtx*) D_802B8890, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); + func_802A487C((Vtx*) sSkyboxP1, D_800DC5EC, 0x140, 0xF0, &gCameraZoom[0]); func_80093A30(8); } } - +// player 2 3p 4p void func_802A5590(void) { init_rdp(); @@ -722,13 +739,13 @@ void func_802A5590(void) { gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CLIPPING); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + render_skybox((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80057FC4(9); - func_802A487C((Vtx*) D_802B8910, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); + func_802A487C((Vtx*) sSkyboxP2, D_800DC5F0, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[1]); func_80093A30(9); } } - +// player 3 3p4p void func_802A5678(void) { init_rdp(); @@ -739,13 +756,14 @@ void func_802A5678(void) { gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CLIPPING); if (D_800DC5B4 != 0) { - func_802A4A0C((Vtx*) D_802B8990, D_800DC5F4, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[2]); + render_skybox((Vtx*) sSkyboxP3, D_800DC5F4, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[2]); func_80057FC4(10); - func_802A487C((Vtx*) D_802B8990, D_800DC5F4, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[2]); + func_802A487C((Vtx*) sSkyboxP3, D_800DC5F4, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[2]); func_80093A30(10); } } +// player 4 3p 4p void func_802A5760(void) { init_rdp(); @@ -774,9 +792,9 @@ void func_802A5760(void) { func_802A39E0(D_800DC5F8); if (D_800DC5B4 != 0) { - func_802A4A0C(D_802B8A10, D_800DC5F8, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[3]); + render_skybox(sSkyboxP4, D_800DC5F8, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[3]); func_80057FC4(11); - func_802A487C(D_802B8A10, D_800DC5F8, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[3]); + func_802A487C(sSkyboxP4, D_800DC5F8, SCREEN_WIDTH, SCREEN_HEIGHT, &gCameraZoom[3]); func_80093A30(11); } } diff --git a/src/racing/skybox_and_splitscreen.h b/src/racing/skybox_and_splitscreen.h index fee41aa4b..bc9f19639 100644 --- a/src/racing/skybox_and_splitscreen.h +++ b/src/racing/skybox_and_splitscreen.h @@ -8,7 +8,7 @@ /* Function Prototypes */ -void func_802A4A0C(Vtx*, struct UnkStruct_800DC5EC*, s32, s32, f32*); +void render_skybox(Vtx*, struct UnkStruct_800DC5EC*, s32, s32, f32*); void func_802A3730(struct UnkStruct_800DC5EC*); void func_802A38AC(void); diff --git a/src/render_player.c b/src/render_player.c index 652fdbbf7..a90ed7f45 100644 --- a/src/render_player.c +++ b/src/render_player.c @@ -483,7 +483,7 @@ void render_players_on_screen_one(void) { s32 junk[] = { 0, 0, 0 }; -Vtx* D_800DDBB4[] = { D_800E49C0, D_800E4AC0, D_800E4BC0, D_800E4CC0, D_800E4DC0, D_800E4EC0, D_800E4FD0, D_800E50D0 }; +Vtx* gPlayerVtx[] = { gPlayerOneVtx, gPlayerTwoVtx, gPlayerThreeVtx, gPlayerFourVtx, gPlayerFiveVtx, gPlayerSixVtx, gPlayerSevenVtx, gPlayerEightVtx }; f32 gCharacterSize[] = { MARIO_SIZE, LUIGI_SIZE, YOSHI_SIZE, TOAD_SIZE, DK_SIZE, WARIO_SIZE, PEACH_SIZE, BOWSER_SIZE }; @@ -1010,24 +1010,25 @@ void func_80022BC4(Player* player, UNUSED s8 playerIndex) { player->unk_DB4.unk2 = temp_v0; } -void func_80022CA8(Player* player, s8 playerId, UNUSED s8 screenId, s8 arg3) { +// look like related to flatten animation +void func_80022CA8(Player* player, s8 playerId, UNUSED s8 screenId, s8 flipOffset) { s16 temp_v0 = player->unk_DA4; - D_800DDBB4[playerId][arg3 + 0x0].v.ob[1] = 18 - (temp_v0 * 2.3); - D_800DDBB4[playerId][arg3 + 0x1].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x2].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x3].v.ob[1] = 18 - (temp_v0 * 2.3); - D_800DDBB4[playerId][arg3 + 0x4].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x7].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x0].v.ob[1] = 18 - (temp_v0 * 2.3); + gPlayerVtx[playerId][flipOffset + 0x1].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x2].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x3].v.ob[1] = 18 - (temp_v0 * 2.3); + gPlayerVtx[playerId][flipOffset + 0x4].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x7].v.ob[1] = 9 - temp_v0; } /** * Seems to stretch/warp a specific players texture for a * short period of time. Perhaps does not do anything **/ -void func_80022D60(UNUSED Player* player, s8 playerId, UNUSED s8 screenId, s8 arg3) { - D_800DDBB4[playerId][arg3].v.ob[1] = 21; - D_800DDBB4[playerId][arg3 + 0x3].v.ob[1] = 21; +void func_80022D60(UNUSED Player* player, s8 playerId, UNUSED s8 screenId, s8 flipOffset) { + gPlayerVtx[playerId][flipOffset].v.ob[1] = 21; + gPlayerVtx[playerId][flipOffset + 0x3].v.ob[1] = 21; } void func_80022DB4(Player* player, UNUSED s8 playerIndex) { @@ -1054,15 +1055,15 @@ void func_80022DB4(Player* player, UNUSED s8 playerIndex) { player->unk_DB4.unk18 = temp_v0; } -void func_80022E84(Player* player, s8 playerId, UNUSED s8 screenId, s8 arg3) { +void func_80022E84(Player* player, s8 playerId, UNUSED s8 screenId, s8 flipOffset) { s16 temp_v0 = player->unk_DB4.unk1E; - D_800DDBB4[playerId][arg3 + 0x0].v.ob[1] = 18 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x1].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x2].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x3].v.ob[1] = 18 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x4].v.ob[1] = 9 - temp_v0; - D_800DDBB4[playerId][arg3 + 0x7].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x0].v.ob[1] = 18 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x1].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x2].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x3].v.ob[1] = 18 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x4].v.ob[1] = 9 - temp_v0; + gPlayerVtx[playerId][flipOffset + 0x7].v.ob[1] = 9 - temp_v0; } /** @@ -1411,7 +1412,7 @@ void render_player_shadow_credits(Player* player, s8 playerId, s8 arg2) { gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF); } -void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { +void render_kart(Player* player, s8 playerId, s8 arg2, s8 flipOffset) { UNUSED s32 pad; Mat4 sp1A4; UNUSED s32 pad2[17]; @@ -1528,19 +1529,19 @@ void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gDPLoadTextureBlock(gDisplayListHead++, sKartLowerTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3 + 4], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset + 4], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF); gDPSetAlphaCompare(gDisplayListHead++, G_AC_NONE); } -void render_ghost(Player* player, s8 playerId, s8 screenId, s8 arg3) { +void render_ghost(Player* player, s8 playerId, s8 screenId, s8 flipOffset) { UNUSED s32 pad; Mat4 sp12C; UNUSED s32 pad2[17]; @@ -1605,19 +1606,19 @@ void render_ghost(Player* player, s8 playerId, s8 screenId, s8 arg3) { gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gDPLoadTextureBlock(gDisplayListHead++, sKartLowerTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3 + 4], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset + 4], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF); gDPSetAlphaCompare(gDisplayListHead++, G_AC_NONE); } -void func_80025DE8(Player* player, s8 playerId, s8 screenId, s8 arg3) { +void func_80025DE8(Player* player, s8 playerId, s8 screenId, s8 flipOffset) { Mat4 spA8; Vec3f sp9C; Vec3s sp94; @@ -1649,19 +1650,19 @@ void func_80025DE8(Player* player, s8 playerId, s8 screenId, s8 arg3) { gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gDPLoadTextureBlock(gDisplayListHead++, sKartLowerTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3 + 4], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset + 4], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF); gMatrixEffectCount += 1; } -void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 arg3) { +void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 flipOffset) { Mat4 spA8; Vec3f sp9C; Vec3s sp94; @@ -1673,9 +1674,9 @@ void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 a sp9C[1] = player->unk_074 + (4.0f * player->size); sp9C[2] = player->pos[2]; if (!(player->unk_002 & (4 << (screenId * 4)))) { - arg3 = 8; + flipOffset = 8; } else { - arg3 = 0; + flipOffset = 0; } mtxf_translate_rotate(spA8, sp9C, sp94); @@ -1693,12 +1694,12 @@ void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 a gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gDPLoadTextureBlock(gDisplayListHead++, sKartLowerTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3 + 4], 4, 0); + gSPVertex(gDisplayListHead++, &gPlayerVtx[playerId][flipOffset + 4], 4, 0); gSPDisplayList(gDisplayListHead++, common_square_plain_render); gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF); gMatrixEffectCount += 1; @@ -1707,16 +1708,16 @@ void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 a void render_player(Player* player, s8 playerId, s8 screenId) { UNUSED s32 pad[2]; s32 temp_t1; - s32 var_v1; + s32 flipOffset; OSMesg* sp34; update_wheel_palette(player, playerId, screenId, D_801651D0[screenId][playerId]); if (!(player->unk_002 & (4 << (screenId * 4)))) { - var_v1 = 0; + flipOffset = 0; } else { - var_v1 = 8; + flipOffset = 8; } - func_80023BF0(player, playerId, screenId, var_v1); + func_80023BF0(player, playerId, screenId, flipOffset); temp_t1 = 8 << (screenId * 4); if ((temp_t1 == (player->unk_002 & temp_t1)) && (player->collision.surfaceDistance[2] <= 50.0f) && (player->surfaceType != ICE)) { @@ -1729,17 +1730,17 @@ void render_player(Player* player, s8 playerId, s8 screenId) { } } if ((player->type & PLAYER_INVISIBLE_OR_BOMB) != PLAYER_INVISIBLE_OR_BOMB) { - render_kart(player, playerId, screenId, var_v1); + render_kart(player, playerId, screenId, flipOffset); } else { - render_ghost(player, playerId, screenId, var_v1); + render_ghost(player, playerId, screenId, flipOffset); } osRecvMesg(&gDmaMesgQueue, (OSMesg*) &sp34, OS_MESG_BLOCK); if ((temp_t1 == (player->unk_002 & temp_t1)) && (player->surfaceType == ICE) && ((player->unk_0CA & 1) != 1) && (player->collision.surfaceDistance[2] <= 30.0f)) { - render_player_ice_reflection(player, playerId, screenId, var_v1); + render_player_ice_reflection(player, playerId, screenId, flipOffset); } if (player->boostPower >= 2.0f) { - func_80025DE8(player, playerId, screenId, var_v1); + func_80025DE8(player, playerId, screenId, flipOffset); } } diff --git a/src/render_player.h b/src/render_player.h index ca8346b62..6a635af05 100644 --- a/src/render_player.h +++ b/src/render_player.h @@ -92,7 +92,7 @@ extern Gfx D_0D008D58[]; extern s32 gPlayersToRenderCount; extern void* D_800DDB5C[]; -extern Vtx* D_800DDBB4[]; +extern Vtx* gPlayerVtx[]; extern f32 gCharacterSize[]; extern s32 D_800DDE74[]; extern Vtx D_800E51D0[]; @@ -102,14 +102,14 @@ extern f64 D_800ED688; extern f32 D_800ED6A8; // There are actually found in data_0DD0A0_2_0.s -extern Vtx D_800E49C0[]; -extern Vtx D_800E4AC0[]; -extern Vtx D_800E4BC0[]; -extern Vtx D_800E4CC0[]; -extern Vtx D_800E4DC0[]; -extern Vtx D_800E4EC0[]; -extern Vtx D_800E4FD0[]; -extern Vtx D_800E50D0[]; +extern Vtx gPlayerOneVtx[]; +extern Vtx gPlayerTwoVtx[]; +extern Vtx gPlayerThreeVtx[]; +extern Vtx gPlayerFourVtx[]; +extern Vtx gPlayerFiveVtx[]; +extern Vtx gPlayerSixVtx[]; +extern Vtx gPlayerSevenVtx[]; +extern Vtx gPlayerEightVtx[]; extern u8** gKartMarioWheels0[]; extern u8** gKartMarioWheels1[]; diff --git a/src/update_objects.c b/src/update_objects.c index a8cbbe651..7533ae63a 100644 --- a/src/update_objects.c +++ b/src/update_objects.c @@ -6588,7 +6588,7 @@ void func_8008275C(s32 objectIndex) { gObjectList[objectIndex].offset[2] *= 2.0; object_calculate_new_pos_offset(objectIndex); gObjectList[objectIndex].direction_angle[1] = - get_angle_between_points(gObjectList[objectIndex].unk_01C, gObjectList[objectIndex].pos); + get_xz_angle_between_points(gObjectList[objectIndex].unk_01C, gObjectList[objectIndex].pos); break; } func_800873F4(objectIndex); @@ -7691,7 +7691,7 @@ void update_chain_chomps(void) { func_800859C8(objectIndex, var_s4); vec3f_copy(object->unk_01C, object->offset); func_8000D940(object->offset, &object->unk_084[8], object->unk_034, object->surfaceHeight, 0); - object->direction_angle[1] = get_angle_between_points(object->unk_01C, object->offset); + object->direction_angle[1] = get_xz_angle_between_points(object->unk_01C, object->offset); object_calculate_new_pos_offset(objectIndex); func_80089CBC(objectIndex, 30.0f); }