use COS constants

This commit is contained in:
Altimor 2023-10-12 20:19:24 -04:00
parent d438af1861
commit ca13b56cbe
8 changed files with 40 additions and 28 deletions

View file

@ -5,6 +5,19 @@
#include "types.h"
#define COS_1 0.99984770f
#define COS_5 0.99619470f
#define COS_10 0.98480770f
#define COS_15 0.96592580f
#define COS_20 0.93969260f
#define COS_25 0.90630780f
#define COS_30 0.86602540f
#define COS_38 0.78801080f
#define COS_60 0.50000000f
#define COS_73 0.29237170f
#define COS_80 0.17364818f
#define COS_90 0.00000000f
/**
* Converts an angle in degrees to sm64's s16 angle units. For example, DEGREES(90) == 0x4000
* This should be used mainly to make math, physics, action, and camera code clearer at first glance.

View file

@ -574,26 +574,25 @@ u32 mario_floor_is_slippery(struct MarioState *m) {
f32 normY;
if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE
&& m->floor->normal.y < 0.9998477f //~cos(1 deg)
) {
&& m->floor->normal.y < COS_1) { // ~cos(1 deg)
return TRUE;
}
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9848077f; //~cos(10 deg)
normY = COS_10; //~cos(10 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9396926f; //~cos(20 deg)
normY = COS_20; //~cos(20 deg)
break;
default:
normY = 0.7880108f; //~cos(38 deg)
normY = COS_38; //~cos(38 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.0f;
normY = COS_90;
break;
}
@ -607,25 +606,25 @@ s32 mario_floor_is_slope(struct MarioState *m) {
f32 normY;
if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE
&& m->floor->normal.y < 0.9998477f) { // ~cos(1 deg)
&& m->floor->normal.y < COS_1) { // ~cos(1 deg)
return TRUE;
}
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9961947f; // ~cos(5 deg)
normY = COS_5; // ~cos(5 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9848077f; // ~cos(10 deg)
normY = COS_10; // ~cos(10 deg)
break;
default:
normY = 0.9659258f; // ~cos(15 deg)
normY = COS_15; // ~cos(15 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.9396926f; // ~cos(20 deg)
normY = COS_20; // ~cos(20 deg)
break;
}
@ -646,19 +645,19 @@ s32 mario_floor_is_steep(struct MarioState *m) {
if (!mario_facing_downhill(m, FALSE)) {
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9659258f; // ~cos(15 deg)
normY = COS_15; // ~cos(15 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9396926f; // ~cos(20 deg)
normY = COS_20; // ~cos(20 deg)
break;
default:
normY = 0.8660254f; // ~cos(30 deg)
normY = COS_30; // ~cos(30 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.8660254f; // ~cos(30 deg)
normY = COS_30; // ~cos(30 deg)
break;
}

View file

@ -120,7 +120,7 @@ s32 should_get_stuck_in_ground(struct MarioState *m) {
if (floor != NULL && (terrainType == TERRAIN_SNOW || terrainType == TERRAIN_SAND)
&& type != SURFACE_BURNING && SURFACE_IS_NOT_HARD(type)) {
if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= 0.8660254f) {
if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= COS_30) {
return TRUE;
}
}
@ -1441,7 +1441,7 @@ s32 act_butt_slide_air(struct MarioState *m) {
switch (perform_air_step(m, 0)) {
case AIR_STEP_LANDED:
if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) {
if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= COS_10) {
m->vel[1] = -m->vel[1] / 2.0f;
m->actionState = 1;
} else {
@ -1480,7 +1480,7 @@ s32 act_hold_butt_slide_air(struct MarioState *m) {
switch (perform_air_step(m, 0)) {
case AIR_STEP_LANDED:
if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) {
if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= COS_10) {
m->vel[1] = -m->vel[1] / 2.0f;
m->actionState = 1;
} else {

View file

@ -549,7 +549,7 @@ s32 act_ledge_grab(struct MarioState *m) {
m->actionTimer++;
}
if (m->floor->normal.y < 0.9063078f) {
if (m->floor->normal.y < COS_25) {
return let_go_of_ledge(m);
}

View file

@ -1545,12 +1545,12 @@ s32 act_squished(struct MarioState *m) {
}
// steep floor
if (m->floor != NULL && m->floor->normal.y < 0.5f) {
if (m->floor != NULL && m->floor->normal.y < COS_60) {
surfAngle = atan2s(m->floor->normal.z, m->floor->normal.x);
underSteepSurf = TRUE;
}
// steep ceiling
if (m->ceil != NULL && -0.5f < m->ceil->normal.y) {
if (m->ceil != NULL && -COS_60 < m->ceil->normal.y) {
surfAngle = atan2s(m->ceil->normal.z, m->ceil->normal.x);
underSteepSurf = TRUE;
}

View file

@ -375,7 +375,7 @@ void update_shell_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= targetSpeed) {
m->forwardVel += 1.1f - m->forwardVel / 58.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg)
m->forwardVel -= 1.0f;
}
@ -451,7 +451,7 @@ void update_walking_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= targetSpeed) {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg)
m->forwardVel -= 1.0f;
}
@ -506,7 +506,7 @@ s32 begin_braking_action(struct MarioState *m) {
return set_mario_action(m, ACT_STANDING_AGAINST_WALL, 0);
}
if (m->forwardVel >= 16.0f && m->floor->normal.y >= 0.17364818f) {
if (m->forwardVel >= 16.0f && m->floor->normal.y >= COS_80) {
return set_mario_action(m, ACT_BRAKING, 0);
}
@ -1760,7 +1760,7 @@ s32 common_landing_cancels(struct MarioState *m, struct LandingAction *landingAc
//! Everything here, including floor steepness, is checked before checking
// if Mario is actually on the floor. This leads to e.g. remote sliding.
if (m->floor->normal.y < 0.2923717f) {
if (m->floor->normal.y < COS_73) {
return mario_push_off_steep_floor(m, landingAction->verySteepAction, 0);
}

View file

@ -19,7 +19,7 @@
s32 check_common_idle_cancels(struct MarioState *m) {
mario_drop_held_object(m);
if (m->floor->normal.y < 0.29237169f) {
if (m->floor->normal.y < COS_73) {
return mario_push_off_steep_floor(m, ACT_FREEFALL, 0);
}
@ -60,7 +60,7 @@ s32 check_common_idle_cancels(struct MarioState *m) {
}
s32 check_common_hold_idle_cancels(struct MarioState *m) {
if (m->floor->normal.y < 0.29237169f) {
if (m->floor->normal.y < COS_73) {
return mario_push_off_steep_floor(m, ACT_HOLD_FREEFALL, 0);
}

View file

@ -1122,7 +1122,7 @@ static void update_metal_water_walking_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= val) {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg)
m->forwardVel -= 1.0f;
}