diff --git a/src/engine/math_util.h b/src/engine/math_util.h index cb37d52d..10602af6 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -32,6 +32,9 @@ extern f32 gCosineTable[]; #define sqr(x) ((x) * (x)) +#define approach_angle(current, target, rate) \ + ((target) - approach_s32((s16)((target) - (current)), 0, (rate), (rate))) + void *vec3f_copy(Vec3f dest, Vec3f src); void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z); void *vec3f_add(Vec3f dest, Vec3f a); diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index f973c665..0fa639b8 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -210,7 +210,7 @@ s32 act_climbing_pole(struct MarioState *m) { marioObj->oMarioPolePos += m->controller->stickY / 8.0f; marioObj->oMarioPoleYawVel = 0; - m->faceAngle[1] = cameraAngle - approach_s32((s16)(cameraAngle - m->faceAngle[1]), 0, 0x400, 0x400); + m->faceAngle[1] = approach_angle(m->faceAngle[1], cameraAngle, 0x400); if (set_pole_position(m, 0.0f) == POLE_NONE) { sp24 = m->controller->stickY / 4.0f * 0x10000; @@ -350,8 +350,7 @@ s32 update_hang_moving(struct MarioState *m) { m->forwardVel = maxSpeed; } - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); + m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800); m->slideYaw = m->faceAngle[1]; m->slideVelX = m->forwardVel * sins(m->faceAngle[1]); diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index fcee2c29..111c764e 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -389,8 +389,7 @@ s32 act_reading_npc_dialog(struct MarioState *m) { if (m->actionState < 8) { // turn to NPC angleToNPC = mario_obj_angle_to_object(m, m->usedObj); - m->faceAngle[1] = - angleToNPC - approach_s32((angleToNPC - m->faceAngle[1]) << 16 >> 16, 0, 2048, 2048); + m->faceAngle[1] = approach_angle(m->faceAngle[1], angleToNPC, 0x800); // turn head to npc m->actionTimer += headTurnAmount; // set animation diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 9da6abb8..e28a440f 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -384,8 +384,7 @@ void update_shell_speed(struct MarioState *m) { m->forwardVel = 64.0f; } - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); + m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800); apply_slope_accel(m); } @@ -459,8 +458,7 @@ void update_walking_speed(struct MarioState *m) { m->forwardVel = 48.0f; } - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); + m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800); apply_slope_accel(m); } @@ -1322,8 +1320,7 @@ s32 act_burning_ground(struct MarioState *m) { m->forwardVel = approach_f32(m->forwardVel, 32.0f, 4.0f, 1.0f); if (m->input & INPUT_NONZERO_ANALOG) { - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x600, 0x600); + m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x600); } apply_slope_accel(m); diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index 4fc919f7..9be6ff15 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -1128,8 +1128,7 @@ static void update_metal_water_walking_speed(struct MarioState *m) { m->forwardVel = 32.0f; } - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); + m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800); m->slideVelX = m->forwardVel * sins(m->faceAngle[1]); m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);