Files
mk64/src/code_8003DC40.c
T
Jed Grabman a5526cc5bf Document effects and define magic values (#733)
* Document projection matrix function

Document function for computing a projection matrix. Used for camera and graphics.

* Fix loop index bug

Fix straightforward loop index bug introduced in last commit

* Style guide updates

Changes to match style recommendations
* Update function variables to camelCase
* Use dOxygen tags
* Use block comment

* Document math functions

* Give all functions in src\racing\math_util.c descriptive names

* Improve documentation for math_util

Improves a number of functions by giving descriptive argument names and comments

* Additional merge

* Fix style issues

update variables / parameters to use camelCase instead of snakeCase

* doxygen and other documentation

* Add doxygen documentation
* Rename mat -> mtx for consistency among matrices
* Theta -> Angle for angles
* Give some arguments more descriptive names

* Partial documentation for calculate_orientation_matrix

Documentation for when cosAxisY is 1 and observations that things break when if it does not equal 1.

* Rename functions

Renamed multiple functions for accuracy or clarity

* doxygen whitespace alignment

Improve readability of doxygen info by aligning text

* Make format check

Formatting updates suggested by make format

* Make skyboxes static

* Change function name

angle_from_coords -> get_angle_between_coords

* Math values renamed

Functions:
render_distance_squared -> distance_if_visible
mtxf_rotation_zxy_translate -> mtxf_rotate_zxy_translate

Arguments:
vecTrans -> translate

* Document many effects

Define effects for
* Braking
* Drifting
* Spinning out (driving and bananas)
* Mini turbos
* Losing at GP
* Tumbling on terrain
* CPU rubberbanding

And substitute some pre-existing defined effect names in place of bit flags

* Replace effect magic numbers with defined values

* Separate effect bit-flags into components

* Document more effects

* Rename some effects

* Replace effect bit_flags with defined values

* Formatting fixes

---------

Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
2025-07-17 20:53:11 -06:00

384 lines
16 KiB
C

#include <ultra64.h>
#include <macros.h>
#include <mk64.h>
#include <course.h>
#include "math_util.h"
#include <common_structs.h>
#include "player_controller.h"
#include "effects.h"
#include "code_8003DC40.h"
#include "defines.h"
void func_8003DC40(Player* player) {
player->unk_DAC = 1.0f;
}
UNUSED void func_8003DC50(Player* player, Vec3f arg1) {
s32 thing1 = 0;
s32 thing2 = 0;
// Praise Fake Match!!
if (player) {};
if (player->unk_230 <= player->unk_23C) {
if (player->collision.unk48[1] >= 0.1736) {
arg1[0] = (player->unk_206 / 182) * 0x78;
arg1[2] = -(player->slopeAccel / 182) * 0x78;
} else {
arg1[0] = thing1;
arg1[2] = thing2;
}
} else if (player->collision.unk48[1] >= 0.1736) {
arg1[0] = (player->unk_206 / 182) * 0x78;
arg1[2] = -(player->slopeAccel / 182) * 0x78;
} else {
arg1[0] = thing1;
arg1[2] = thing2;
}
arg1[1] = 0.0f;
mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix);
}
UNUSED void func_8003DE4C(Player* player, Vec3f arg1) {
s32 thing1 = 0;
s32 thing2 = 0;
// Praise Fake Match!!
if (player) {};
if (player->unk_230 <= player->unk_23C) {
if (player->collision.unk54[1] >= 0.1736) {
arg1[0] = (player->unk_206 / 182) * 0x78;
arg1[2] = -(player->slopeAccel / 182) * 0x78;
} else {
arg1[0] = thing1;
arg1[2] = thing2;
}
} else if (player->collision.unk54[1] >= 0.1736) {
arg1[0] = (player->unk_206 / 182) * 0x78;
arg1[2] = -(player->slopeAccel / 182) * 0x78;
} else {
arg1[0] = thing1;
arg1[2] = thing2;
}
arg1[1] = 0.0f;
mtxf_transform_vec3f_mat3(arg1, player->orientationMatrix);
}
// Stick to ground?
void func_8003E048(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 1, 2);
if (player->collision.orientationVector[1] <= 0.8829f) {
arg3[0] = ((player->unk_206 / 182) * 0xB4);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
player_decelerate_alternative(player, 4.0f);
player->unk_DAC = 0.5f;
if ((player->effects & MUSHROOM_EFFECT) != 0) {
remove_mushroom_effect(player);
player->currentSpeed /= 2;
player->unk_08C /= 2;
}
} else if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
arg3[0] = ((player->unk_206 / 182) * 0x32);
arg3[2] = (-(player->slopeAccel / 182) * 0x3C);
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
arg3[1] = 0.0f;
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) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.2;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 0.5f, 2);
if ((player->collision.orientationVector[1] <= 0.7318f) || (player->surfaceType == CLIFF)) {
arg3[0] = ((player->unk_206 / 182) * 0xB4);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
if (((player->speed / 18.0f) * 216.0f) >= 8.0f) {
player_decelerate_alternative(player, 5.0f);
}
player->unk_DAC = 0.5f;
if ((player->effects & MUSHROOM_EFFECT) != 0) {
remove_mushroom_effect(player);
player->currentSpeed /= 2;
player->unk_08C /= 2;
}
} else if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
arg3[0] = ((player->unk_206 / 182) * 0x32);
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
arg3[1] = 0.0f;
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) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 0.5f, 2);
if (player->collision.orientationVector[1] <= 0.8829f) {
arg3[0] = ((player->unk_206 / 182) * 0xB4);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
player_decelerate_alternative(player, 4.0f);
func_8003DC40(player);
} else if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
arg3[0] = ((player->unk_206 / 182) * 0x32);
arg3[2] = (-(player->slopeAccel / 182) * 0x3C);
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
arg3[1] = 0.0f;
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) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 1.2f, 2);
if (player->collision.orientationVector[1] <= 0.8357f) {
arg3[0] = ((player->unk_206 / 182) * 0x78);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
player_decelerate_alternative(player, 4.0f);
func_8003DC40(player);
} else {
if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
if ((player->tyres[BACK_LEFT].surfaceType == ASPHALT) ||
(player->tyres[BACK_RIGHT].surfaceType == ASPHALT) ||
(player->tyres[FRONT_RIGHT].surfaceType == ASPHALT) ||
(player->tyres[FRONT_LEFT].surfaceType == ASPHALT)) {
arg3[0] = ((player->unk_206 / 182) * 5);
} else {
arg3[0] = ((player->unk_206 / 182) * 0x28);
}
arg3[2] = (-(player->slopeAccel / 182) * 0x28);
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
if ((player->effects & TERRAIN_TUMBLE_EFFECT) != 0) {
arg3[0] = ((player->unk_206 / 182) * 0x78);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
}
}
arg3[1] = 0.0f;
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) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 0.5f, 2);
if (player->collision.orientationVector[1] <= 0.8357f) {
arg3[0] = ((player->unk_206 / 182) * 0x78);
arg3[2] = (-(player->slopeAccel / 182) * 0xB4);
player_decelerate_alternative(player, 4.0f);
func_8003DC40(player);
} else if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
arg3[0] = ((player->unk_206 / 182) * 0x32);
arg3[2] = (-(player->slopeAccel / 182) * 0x3C);
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
arg3[1] = 0.0f;
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) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 0.1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 0.5f, 2);
if (player->surfaceType == GRASS) {
player->unk_044 &= ~1;
}
if (player->collision.orientationVector[1] <= 0.8357f) {
arg3[0] = ((player->unk_206 / 182) * 0xC8);
arg3[2] = (-(player->slopeAccel / 182) * 0xC8);
player_decelerate_alternative(player, 4.0f);
player->unk_DAC = 0.5f;
arg3[0] = 0;
} else if ((((player->speed / 18.0f) * 216.0f) > 20.0f) ||
((player->effects & TERRAIN_TUMBLE_EFFECT) == TERRAIN_TUMBLE_EFFECT)) {
arg3[0] = ((player->unk_206 / 182) * 0x78);
arg3[2] = (-(player->slopeAccel / 182) * 0x78);
arg3[0] = 0;
} else {
arg3[0] = 0.0f;
arg3[2] = (-(player->slopeAccel / 182) * 0x32);
}
arg3[1] = 0.0f;
arg3[2] = 0.0f;
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) {
arg1[0] = -player->collision.orientationVector[0];
arg1[1] = -player->collision.orientationVector[1];
arg1[2] = -player->collision.orientationVector[2];
if ((player->collision.orientationVector[1] < 0.0f) && ((player->unk_0CA & 2) == 0)) {
*arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1;
*arg6 += arg1[1] * player->collision.surfaceDistance[2] * 1;
*arg7 += arg1[2] * player->collision.surfaceDistance[2] * 1;
func_8002A5F4(arg1, *arg4, arg2, 1.2f, 0.0f);
player->kartHopJerk = 0.0f;
player->kartHopAcceleration = 0.0f;
player->kartHopVelocity = 0.0f;
return;
} else {
#if !ENABLE_CUSTOM_COURSE_ENGINE
switch (gCurrentCourseId) {
case COURSE_MARIO_RACEWAY:
func_8003E048(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case COURSE_CHOCO_MOUNTAIN:
case COURSE_KOOPA_BEACH:
func_8003E37C(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case COURSE_BOWSER_CASTLE:
func_8003E6EC(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case COURSE_LUIGI_RACEWAY:
func_8003E9EC(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case COURSE_WARIO_STADIUM:
func_8003EE2C(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case COURSE_DK_JUNGLE:
func_8003F138(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
default:
func_8003E048(player, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
}
#else
#endif
if (player->effects & TERRAIN_TUMBLE_EFFECT) {
player->unk_DAC = 0.5f;
}
}
}
void func_8003F734(Player* player, Vec3f arg1, Vec3f arg2, f32* arg3, f32* arg4, f32* arg5, f32* arg6) {
f32 temp_f12;
f32 temp_f14;
f32 temp_f0_2;
arg1[0] = -player->collision.unk48[0];
arg1[1] = -player->collision.unk48[1];
arg1[2] = -player->collision.unk48[2];
if (player->collision.unk48[1] == 0) {
*arg4 += arg1[0] * player->collision.surfaceDistance[0] * 1;
*arg5 += arg1[1] * player->collision.surfaceDistance[0] * 0.1;
*arg6 += arg1[2] * player->collision.surfaceDistance[0] * 1;
if ((player->slopeAccel < 0) && (((player->speed / 18.0f) * 216.0f) < 10.0f)) {
func_8002A5F4(arg1, *arg3, arg2, 2.5f, 0);
} else {
func_8002A5F4(arg1, *arg3, arg2, 0.5f, 0);
}
} else if (player->collision.unk48[1] <= 0.5) {
*arg4 += arg1[0] * player->collision.surfaceDistance[0] * 1;
*arg5 += arg1[1] * player->collision.surfaceDistance[0] * 0.1;
*arg6 += arg1[2] * player->collision.surfaceDistance[0] * 1;
func_8002A5F4(arg1, *arg3, arg2, 1, 0);
if ((!(player->effects & TERRAIN_TUMBLE_EFFECT)) && ((player->effects & MIDAIR_EFFECT) == 0)) {
arg2[1] *= -1e-05;
}
} else {
*arg4 += arg1[0] * player->collision.surfaceDistance[0] * 1;
temp_f0_2 = player->collision.surfaceDistance[0] * arg1[1];
if (temp_f0_2 < 0) {
*arg5 += temp_f0_2 * 0.1;
} else {
*arg5 += temp_f0_2 * 0;
}
*arg6 += arg1[2] * player->collision.surfaceDistance[0] * 1;
func_8002A5F4(arg1, *arg3, arg2, 1.2f, 0);
if ((!(player->effects & TERRAIN_TUMBLE_EFFECT)) && ((player->effects & MIDAIR_EFFECT) == 0)) {
arg2[1] *= -1e-05;
}
}
player->effects &= ~DRIFTING_EFFECT;
temp_f12 = player->collision.surfaceDistance[0] * arg1[0];
temp_f14 = player->collision.surfaceDistance[0] * arg1[2];
if (((temp_f12 >= 0) && (temp_f14 >= 0)) || ((temp_f12 < 0) && (temp_f14 >= 0))) {
temp_f0_2 = player->boundingBoxSize / 2;
player->unk_218 = *arg4 - temp_f12 - temp_f0_2;
player->unk_21C = *arg6 - temp_f14 - temp_f0_2;
}
if (((temp_f12 < 0) && (temp_f14 < 0)) || ((temp_f12 >= 0) && (temp_f14 < 0))) {
temp_f0_2 = player->boundingBoxSize / 2;
player->unk_218 = *arg4 + temp_f12 + temp_f0_2;
player->unk_21C = *arg6 + temp_f14 + temp_f0_2;
}
}
void func_8003FBAC(Player* player, Vec3f arg1, Vec3f arg2, f32* arg3, f32* arg4, f32* arg5, f32* arg6) {
f32 temp_f0_2;
f32 temp_f12;
f32 temp_f14;
arg1[0] = -player->collision.unk54[0];
arg1[1] = -player->collision.unk54[1];
arg1[2] = -player->collision.unk54[2];
if (player->collision.unk54[1] == 0) {
*arg4 += arg1[0] * player->collision.surfaceDistance[1] * 1;
*arg5 += arg1[1] * player->collision.surfaceDistance[1] * 0.1;
*arg6 += arg1[2] * player->collision.surfaceDistance[1] * 1;
if ((player->slopeAccel < 0) && (((player->speed / 18.0f) * 216.0f) < 10.0f)) {
func_8002A5F4(arg1, *arg3, arg2, 1.5f, 0);
} else {
func_8002A5F4(arg1, *arg3, arg2, 0.5f, 0);
}
} else if (player->collision.unk54[1] <= 0.5) {
*arg4 += arg1[0] * player->collision.surfaceDistance[1] * 1;
*arg5 += arg1[1] * player->collision.surfaceDistance[1] * 0.1;
*arg6 += arg1[2] * player->collision.surfaceDistance[1] * 1;
func_8002A5F4(arg1, *arg3, arg2, 1, 0);
if ((!(player->effects & TERRAIN_TUMBLE_EFFECT)) && ((player->effects & MIDAIR_EFFECT) == 0)) {
arg2[1] *= -1e-05;
}
} else {
*arg4 += arg1[0] * player->collision.surfaceDistance[1] * 1;
temp_f0_2 = player->collision.surfaceDistance[1] * arg1[1];
if (temp_f0_2 < 0) {
*arg5 += temp_f0_2 * 0.1;
} else {
*arg5 += temp_f0_2 * 0;
}
*arg6 += arg1[2] * player->collision.surfaceDistance[1] * 1;
func_8002A5F4(arg1, *arg3, arg2, 1.2f, 0);
if ((!(player->effects & TERRAIN_TUMBLE_EFFECT)) && ((player->effects & MIDAIR_EFFECT) == 0)) {
arg2[1] *= -1e-05;
}
}
player->effects &= ~DRIFTING_EFFECT;
temp_f12 = player->collision.surfaceDistance[1] * arg1[0];
temp_f14 = player->collision.surfaceDistance[1] * arg1[2];
if (((temp_f12 >= 0) && (temp_f14 >= 0)) || ((temp_f12 >= 0) && (temp_f14 < 0))) {
temp_f0_2 = player->boundingBoxSize / 2;
player->unk_218 = *arg4 - temp_f12 - temp_f0_2;
player->unk_21C = *arg6 - temp_f14 - temp_f0_2;
}
if (((temp_f12 < 0) && (temp_f14 >= 0)) || ((temp_f12 < 0) && (temp_f14 < 0))) {
temp_f0_2 = player->boundingBoxSize / 2;
player->unk_218 = *arg4 + temp_f12 + temp_f0_2;
player->unk_21C = *arg6 + temp_f14 + temp_f0_2;
}
}