use DEGREES macro in math/physics/action code

This commit is contained in:
Altimor 2023-10-10 13:32:36 -04:00
parent 9921382a68
commit 43ac09f6b7
13 changed files with 143 additions and 140 deletions

View file

@ -426,12 +426,12 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
f32 avgY;
f32 minY = -radius * 3;
point0[0] = pos[0] + radius * sins(yaw + 0x2AAA);
point0[2] = pos[2] + radius * coss(yaw + 0x2AAA);
point1[0] = pos[0] + radius * sins(yaw + 0x8000);
point1[2] = pos[2] + radius * coss(yaw + 0x8000);
point2[0] = pos[0] + radius * sins(yaw + 0xD555);
point2[2] = pos[2] + radius * coss(yaw + 0xD555);
point0[0] = pos[0] + radius * sins(yaw + DEGREES(60));
point0[2] = pos[2] + radius * coss(yaw + DEGREES(60));
point1[0] = pos[0] + radius * sins(yaw + DEGREES(180));
point1[2] = pos[2] + radius * coss(yaw + DEGREES(180));
point2[0] = pos[0] + radius * sins(yaw + DEGREES(300));
point2[2] = pos[2] + radius * coss(yaw + DEGREES(300));
point0[1] = find_floor(point0[0], pos[1] + 150, point0[2], &sp74);
point1[1] = find_floor(point1[0], pos[1] + 150, point1[2], &sp74);
@ -718,14 +718,14 @@ s16 atan2s(f32 y, f32 x) {
if (y >= x) {
ret = atan2_lookup(x, y);
} else {
ret = 0x4000 - atan2_lookup(y, x);
ret = DEGREES(90) - atan2_lookup(y, x);
}
} else {
y = -y;
if (y < x) {
ret = 0x4000 + atan2_lookup(y, x);
ret = DEGREES(90) + atan2_lookup(y, x);
} else {
ret = 0x8000 - atan2_lookup(x, y);
ret = DEGREES(180) - atan2_lookup(x, y);
}
}
} else {
@ -733,13 +733,13 @@ s16 atan2s(f32 y, f32 x) {
if (y < 0) {
y = -y;
if (y >= x) {
ret = 0x8000 + atan2_lookup(x, y);
ret = DEGREES(180) + atan2_lookup(x, y);
} else {
ret = 0xC000 - atan2_lookup(y, x);
ret = DEGREES(270) - atan2_lookup(y, x);
}
} else {
if (y < x) {
ret = 0xC000 + atan2_lookup(y, x);
ret = DEGREES(270) + atan2_lookup(y, x);
} else {
ret = -atan2_lookup(x, y);
}

View file

@ -5,6 +5,13 @@
#include "types.h"
/**
* 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.
* Shouldn't be used for angular velocities which are often small arbitrary s16 values.
*/
#define DEGREES(x) (int)((x) * 0x10000 / 360)
/*
* The sine and cosine tables overlap, but "#define gCosineTable (gSineTable +
* 0x400)" doesn't give expected codegen; gSineTable and gCosineTable need to

View file

@ -808,7 +808,7 @@ s16 look_down_slopes(s16 camYaw) {
struct Surface *floor;
f32 floorDY;
// Default pitch
s16 pitch = 0x05B0;
s16 pitch = DEGREES(8);
// x and z offsets towards the camera
f32 xOff = sMarioCamState->pos[0] + sins(camYaw) * 40.f;
f32 zOff = sMarioCamState->pos[2] + coss(camYaw) * 40.f;
@ -818,7 +818,7 @@ s16 look_down_slopes(s16 camYaw) {
if (floor != NULL) {
if (floor->type != SURFACE_WALL_MISC && floorDY > 0) {
if (floor->normal.z == 0.f && floorDY < 100.f) {
pitch = 0x05B0;
pitch = DEGREES(8);
} else {
// Add the slope's angle of declination to the pitch
pitch += atan2s(40.f, floorDY);
@ -2045,7 +2045,7 @@ void mode_water_surface_camera(struct Camera *c) {
*/
s32 update_mario_camera(UNUSED struct Camera *c, Vec3f focus, Vec3f pos) {
s16 yaw = sMarioCamState->faceAngle[1] + sModeOffsetYaw + DEGREES(180);
focus_on_mario(focus, pos, 125.f, 125.f, gCameraZoomDist, 0x05B0, yaw);
focus_on_mario(focus, pos, 125.f, 125.f, gCameraZoomDist, DEGREES(8), yaw);
return sMarioCamState->faceAngle[1];
}
@ -4751,7 +4751,7 @@ s32 offset_yaw_outward_radial(struct Camera *c, s16 areaYaw) {
areaCenter[2] = c->areaCenZ;
distFromAreaCenter = calc_abs_dist(areaCenter, sMarioCamState->pos);
if (800.f > distFromAreaCenter) {
yawGoal = 0x3800;
yawGoal = DEGREES(78.75);
}
break;
case AREA_SSL_PYRAMID:
@ -4778,7 +4778,7 @@ s32 offset_yaw_outward_radial(struct Camera *c, s16 areaYaw) {
}
// When the final yaw is out of [-60,60] degrees, approach yawGoal faster than dYaw will ever be,
// making the camera lock in one direction until yawGoal drops below 60 (or Mario presses a C button)
if (yaw < -DEGREES(60)) {
if (yaw < DEGREES(-60)) {
//! Maybe they meant to reverse yawGoal's sign?
camera_approach_s16_symmetric_bool(&yaw, -yawGoal, 0x200);
}

View file

@ -19,12 +19,6 @@
#define ABS(x) ((x) > 0.f ? (x) : -(x))
#define ABS2(x) ((x) >= 0.f ? (x) : -(x))
/**
* Converts an angle in degrees to sm64's s16 angle units. For example, DEGREES(90) == 0x4000
* This should be used mainly to make camera code clearer at first glance.
*/
#define DEGREES(x) ((x) * 0x10000 / 360)
#define LEVEL_AREA_INDEX(levelNum, areaNum) (((levelNum) << 4) + (areaNum))
/**

View file

@ -559,12 +559,12 @@ s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw) {
// This is never used in practice, as turnYaw is
// always passed as zero.
if (turnYaw && m->forwardVel < 0.0f) {
faceAngleYaw += 0x8000;
faceAngleYaw += DEGREES(180);
}
faceAngleYaw = m->floorAngle - faceAngleYaw;
return (-0x4000 < faceAngleYaw) && (faceAngleYaw < 0x4000);
return (DEGREES(-90) < faceAngleYaw) && (faceAngleYaw < DEGREES(90));
}
/**
@ -744,7 +744,7 @@ void set_steep_jump_action(struct MarioState *m) {
if (m->forwardVel > 0.0f) {
//! ((s16)0x8000) has undefined behavior. Therefore, this downcast has
// undefined behavior if m->floorAngle >= 0.
s16 angleTemp = m->floorAngle + 0x8000;
s16 angleTemp = m->floorAngle + DEGREES(180);
s16 faceAngleTemp = m->faceAngle[1] - angleTemp;
f32 y = sins(faceAngleTemp) * m->forwardVel;
@ -843,7 +843,7 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
case ACT_STEEP_JUMP:
m->marioObj->header.gfx.animInfo.animID = -1;
set_mario_y_vel_based_on_fspeed(m, 42.0f, 0.25f);
m->faceAngle[0] = -0x2000;
m->faceAngle[0] = DEGREES(-45);
break;
case ACT_LAVA_BOOST:

View file

@ -242,8 +242,8 @@ void update_air_without_turn(struct MarioState *m) {
m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);
m->slideVelX += sidewaysSpeed * sins(m->faceAngle[1] + 0x4000);
m->slideVelZ += sidewaysSpeed * coss(m->faceAngle[1] + 0x4000);
m->slideVelX += sidewaysSpeed * sins(m->faceAngle[1] + DEGREES(90));
m->slideVelZ += sidewaysSpeed * coss(m->faceAngle[1] + DEGREES(90));
m->vel[0] = m->slideVelX;
m->vel[2] = m->slideVelZ;
@ -262,7 +262,7 @@ void update_lava_boost_or_twirling(struct MarioState *m) {
m->faceAngle[1] += sins(intendedDYaw) * intendedMag * 1024.0f;
if (m->forwardVel < 0.0f) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
m->forwardVel *= -1.0f;
}
@ -336,7 +336,7 @@ void update_flying(struct MarioState *m) {
update_flying_pitch(m);
update_flying_yaw(m);
m->forwardVel -= 2.0f * ((f32) m->faceAngle[0] / 0x4000) + 0.1f;
m->forwardVel -= 2.0f * ((f32) m->faceAngle[0] / DEGREES(90)) + 0.1f;
m->forwardVel -= 0.5f * (1.0f - coss(m->angleVel[1]));
if (m->forwardVel < 0.0f) {
@ -353,11 +353,11 @@ void update_flying(struct MarioState *m) {
m->faceAngle[0] += m->angleVel[0];
if (m->faceAngle[0] > 0x2AAA) {
m->faceAngle[0] = 0x2AAA;
if (m->faceAngle[0] > DEGREES(60)) {
m->faceAngle[0] = DEGREES(60);
}
if (m->faceAngle[0] < -0x2AAA) {
m->faceAngle[0] = -0x2AAA;
if (m->faceAngle[0] < DEGREES(-60)) {
m->faceAngle[0] = DEGREES(-60);
}
m->vel[0] = m->forwardVel * coss(m->faceAngle[0]) * sins(m->faceAngle[1]);
@ -393,7 +393,7 @@ u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation,
queue_rumble_data(5, 40);
#endif
mario_bonk_reflection(m, FALSE);
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
if (m->wall != NULL) {
set_mario_action(m, ACT_AIR_HIT_WALL, 0);
@ -605,7 +605,7 @@ s32 act_side_flip(struct MarioState *m) {
if (common_air_action_step(m, ACT_SIDE_FLIP_LAND, MARIO_ANIM_SLIDEFLIP, AIR_STEP_CHECK_LEDGE_GRAB)
!= AIR_STEP_GRABBED_LEDGE) {
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
}
// This must be one line to match on -O2
@ -742,17 +742,17 @@ s32 act_dive(struct MarioState *m) {
switch (perform_air_step(m, 0)) {
case AIR_STEP_NONE:
if (m->vel[1] < 0.0f && m->faceAngle[0] > -0x2AAA) {
if (m->vel[1] < 0.0f && m->faceAngle[0] > DEGREES(-60)) {
m->faceAngle[0] -= 0x200;
if (m->faceAngle[0] < -0x2AAA) {
m->faceAngle[0] = -0x2AAA;
if (m->faceAngle[0] < DEGREES(-60)) {
m->faceAngle[0] = DEGREES(-60);
}
}
m->marioObj->header.gfx.angle[0] = -m->faceAngle[0];
break;
case AIR_STEP_LANDED:
if (should_get_stuck_in_ground(m) && m->faceAngle[0] == -0x2AAA) {
if (should_get_stuck_in_ground(m) && m->faceAngle[0] == DEGREES(-60)) {
#if ENABLE_RUMBLE
queue_rumble_data(5, 80);
#endif
@ -1146,7 +1146,7 @@ u32 common_air_knockback_step(struct MarioState *m, u32 landAction, u32 hardFall
s32 check_wall_kick(struct MarioState *m) {
if ((m->input & INPUT_A_PRESSED) && m->wallKickTimer != 0 && m->prevAction == ACT_AIR_HIT_WALL) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
@ -1233,11 +1233,11 @@ s32 act_thrown_forward(struct MarioState *m) {
if (common_air_knockback_step(m, landAction, ACT_HARD_FORWARD_GROUND_KB, 0x002D, m->forwardVel)
== AIR_STEP_NONE) {
pitch = atan2s(m->forwardVel, -m->vel[1]);
if (pitch > 0x1800) {
pitch = 0x1800;
if (pitch > DEGREES(33.75)) {
pitch = DEGREES(33.75);
}
m->marioObj->header.gfx.angle[0] = pitch + 0x1800;
m->marioObj->header.gfx.angle[0] = pitch + DEGREES(33.75);
}
m->forwardVel *= 0.98f;
@ -1314,7 +1314,7 @@ s32 act_air_hit_wall(struct MarioState *m) {
if (++(m->actionTimer) <= 2) {
if (m->input & INPUT_A_PRESSED) {
m->vel[1] = 52.0f;
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
} else if (m->forwardVel >= 38.0f) {
@ -1593,8 +1593,8 @@ s32 act_slide_kick(struct MarioState *m) {
case AIR_STEP_NONE:
if (m->actionState == 0) {
m->marioObj->header.gfx.angle[0] = atan2s(m->forwardVel, -m->vel[1]);
if (m->marioObj->header.gfx.angle[0] > 0x1800) {
m->marioObj->header.gfx.angle[0] = 0x1800;
if (m->marioObj->header.gfx.angle[0] > DEGREES(33.75)) {
m->marioObj->header.gfx.angle[0] = DEGREES(33.75);
}
}
break;
@ -1813,8 +1813,8 @@ s32 act_flying(struct MarioState *m) {
}
m->faceAngle[0] -= 0x200;
if (m->faceAngle[0] < -0x2AAA) {
m->faceAngle[0] = -0x2AAA;
if (m->faceAngle[0] < DEGREES(-60)) {
m->faceAngle[0] = DEGREES(-60);
}
m->marioObj->header.gfx.angle[0] = -m->faceAngle[0];
@ -1827,7 +1827,7 @@ s32 act_flying(struct MarioState *m) {
break;
}
if (m->faceAngle[0] > 0x800 && m->forwardVel >= 48.0f) {
if (m->faceAngle[0] > DEGREES(11.25) && m->forwardVel >= 48.0f) {
m->particleFlags |= PARTICLE_DUST;
}
@ -1863,7 +1863,7 @@ s32 act_riding_hoot(struct MarioState *m) {
m->pos[1] = m->usedObj->oPosY - 92.5f;
m->pos[2] = m->usedObj->oPosZ;
m->faceAngle[1] = 0x4000 - m->usedObj->oMoveAngleYaw;
m->faceAngle[1] = DEGREES(90) - m->usedObj->oMoveAngleYaw;
if (m->actionState == 0) {
set_mario_animation(m, MARIO_ANIM_HANG_ON_CEILING);
@ -1875,7 +1875,7 @@ s32 act_riding_hoot(struct MarioState *m) {
vec3f_set(m->vel, 0.0f, 0.0f, 0.0f);
vec3f_set(m->marioObj->header.gfx.pos, m->pos[0], m->pos[1], m->pos[2]);
vec3s_set(m->marioObj->header.gfx.angle, 0, 0x4000 - m->faceAngle[1], 0);
vec3s_set(m->marioObj->header.gfx.angle, 0, DEGREES(90) - m->faceAngle[1], 0);
return FALSE;
}

View file

@ -116,7 +116,7 @@ s32 act_holding_pole(struct MarioState *m) {
#ifdef VERSION_JP
if (m->input & INPUT_A_PRESSED) {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
@ -134,7 +134,7 @@ s32 act_holding_pole(struct MarioState *m) {
if (m->input & INPUT_A_PRESSED) {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
#endif
@ -200,7 +200,7 @@ s32 act_climbing_pole(struct MarioState *m) {
if (m->input & INPUT_A_PRESSED) {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
@ -573,7 +573,7 @@ s32 act_ledge_grab(struct MarioState *m) {
&& !(m->input & INPUT_A_DOWN)
#endif
) {
if (intendedDYaw >= -0x4000 && intendedDYaw <= 0x4000) {
if (intendedDYaw >= DEGREES(-90) && intendedDYaw <= DEGREES(90)) {
if (hasSpaceForMario) {
return set_mario_action(m, ACT_LEDGE_CLIMB_SLOW_1, 0);
}
@ -582,7 +582,7 @@ s32 act_ledge_grab(struct MarioState *m) {
}
}
heightAboveFloor = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 30.0f);
heightAboveFloor = m->pos[1] - find_floor_height_relative_polar(m, DEGREES(-180), 30.0f);
if (hasSpaceForMario && heightAboveFloor < 100.0f) {
return set_mario_action(m, ACT_LEDGE_CLIMB_FAST, 0);
}
@ -711,18 +711,18 @@ s32 act_in_cannon(struct MarioState *m) {
m->faceAngle[0] -= (s16)(m->controller->stickY * 10.0f);
marioObj->oMarioCannonInputYaw -= (s16)(m->controller->stickX * 10.0f);
if (m->faceAngle[0] > 0x38E3) {
m->faceAngle[0] = 0x38E3;
if (m->faceAngle[0] > DEGREES(80)) {
m->faceAngle[0] = DEGREES(80);
}
if (m->faceAngle[0] < 0) {
m->faceAngle[0] = 0;
}
if (marioObj->oMarioCannonInputYaw > 0x4000) {
marioObj->oMarioCannonInputYaw = 0x4000;
if (marioObj->oMarioCannonInputYaw > DEGREES(90)) {
marioObj->oMarioCannonInputYaw = DEGREES(90);
}
if (marioObj->oMarioCannonInputYaw < -0x4000) {
marioObj->oMarioCannonInputYaw = -0x4000;
if (marioObj->oMarioCannonInputYaw < DEGREES(-90)) {
marioObj->oMarioCannonInputYaw = DEGREES(-90);
}
m->faceAngle[1] = marioObj->oMarioCannonObjectYaw + marioObj->oMarioCannonInputYaw;

View file

@ -261,7 +261,7 @@ void handle_save_menu(struct MarioState *m) {
// not quitting
if (gSaveOptSelectIndex != MENU_OPT_SAVE_AND_QUIT) {
disable_time_stop();
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
// figure out what dialog to show, if we should
dialogID = get_star_collection_dialog(m);
if (dialogID) {
@ -779,7 +779,7 @@ s32 act_unlocking_key_door(struct MarioState *m) {
m->pos[2] = m->usedObj->oPosZ + sins(m->faceAngle[1]) * 75.0f;
if (m->actionArg & 2) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
}
if (m->actionTimer == 0) {
@ -819,7 +819,7 @@ s32 act_unlocking_star_door(struct MarioState *m) {
case 0:
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
if (m->actionArg & 2) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
}
m->marioObj->oMarioReadingSignDPosX = m->pos[0];
m->marioObj->oMarioReadingSignDPosZ = m->pos[2];
@ -898,7 +898,7 @@ s32 act_entering_star_door(struct MarioState *m) {
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
if (m->actionArg & 2) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
}
m->pos[0] += 12.0f * sins(m->faceAngle[1]);
@ -939,7 +939,7 @@ s32 act_going_through_door(struct MarioState *m) {
}
} else if (is_anim_at_end(m)) {
if (m->actionArg & 2) {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
}
set_mario_action(m, ACT_IDLE, 0);
}
@ -1054,7 +1054,7 @@ s32 act_exit_airborne(struct MarioState *m) {
m->healCounter = 31;
}
// rotate him to face away from the entrance
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
m->particleFlags |= PARTICLE_SPARKLES;
return FALSE;
}
@ -1065,7 +1065,7 @@ s32 act_falling_exit_airborne(struct MarioState *m) {
m->healCounter = 31;
}
// rotate Mario to face away from the entrance
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
m->particleFlags |= PARTICLE_SPARKLES;
return FALSE;
}
@ -1149,7 +1149,7 @@ s32 act_exit_land_save_dialog(struct MarioState *m) {
break;
}
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
return FALSE;
}
@ -1227,7 +1227,7 @@ s32 act_special_exit_airborne(struct MarioState *m) {
m->particleFlags |= PARTICLE_SPARKLES;
// rotate Mario to face away from the entrance
marioObj->header.gfx.angle[1] += 0x8000;
marioObj->header.gfx.angle[1] += DEGREES(180);
// show Mario
marioObj->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
@ -1813,7 +1813,7 @@ static void jumbo_star_cutscene_falling(struct MarioState *m) {
m->input |= INPUT_A_DOWN;
m->flags |= (MARIO_WING_CAP | MARIO_CAP_ON_HEAD);
m->faceAngle[1] = -0x8000;
m->faceAngle[1] = DEGREES(-180);
m->pos[0] = 0.0f;
m->pos[2] = 0.0f;
@ -2663,7 +2663,7 @@ static s32 act_end_waving_cutscene(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_CREDITS_WAVING);
stop_and_set_height_to_floor(m);
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
m->marioObj->header.gfx.pos[0] -= 60.0f;
m->marioBodyState->handState = MARIO_HAND_RIGHT_OPEN;

View file

@ -119,12 +119,12 @@ void check_ledge_climb_down(struct MarioState *m) {
wallAngle = atan2s(wall->normal.z, wall->normal.x);
wallDYaw = wallAngle - m->faceAngle[1];
if (wallDYaw > -0x4000 && wallDYaw < 0x4000) {
if (wallDYaw > DEGREES(-90) && wallDYaw < DEGREES(90)) {
m->pos[0] = wallCols.x - 20.0f * wall->normal.x;
m->pos[2] = wallCols.z - 20.0f * wall->normal.z;
m->faceAngle[0] = 0;
m->faceAngle[1] = wallAngle + 0x8000;
m->faceAngle[1] = wallAngle + DEGREES(180);
set_mario_action(m, ACT_LEDGE_CLIMB_DOWN, 0);
set_mario_animation(m, MARIO_ANIM_CLIMB_DOWN_LEDGE);
@ -176,22 +176,22 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
facingDYaw = m->faceAngle[1] - m->slideYaw;
newFacingDYaw = facingDYaw;
//! -0x4000 not handled - can slide down a slope while facing perpendicular to it
if (newFacingDYaw > 0 && newFacingDYaw <= 0x4000) {
//! -0x4000 / -90 degrees not handled - can slide down a slope while facing perpendicular to it
if (newFacingDYaw > 0 && newFacingDYaw <= DEGREES(90)) {
if ((newFacingDYaw -= 0x200) < 0) {
newFacingDYaw = 0;
}
} else if (newFacingDYaw > -0x4000 && newFacingDYaw < 0) {
} else if (newFacingDYaw > DEGREES(-90) && newFacingDYaw < 0) {
if ((newFacingDYaw += 0x200) > 0) {
newFacingDYaw = 0;
}
} else if (newFacingDYaw > 0x4000 && newFacingDYaw < 0x8000) {
if ((newFacingDYaw += 0x200) > 0x8000) {
newFacingDYaw = 0x8000;
} else if (newFacingDYaw > DEGREES(90) && newFacingDYaw < DEGREES(180)) {
if ((newFacingDYaw += 0x200) > DEGREES(180)) {
newFacingDYaw = DEGREES(180);
}
} else if (newFacingDYaw > -0x8000 && newFacingDYaw < -0x4000) {
if ((newFacingDYaw -= 0x200) < -0x8000) {
newFacingDYaw = -0x8000;
} else if (newFacingDYaw > DEGREES(-180) && newFacingDYaw < DEGREES(-90)) {
if ((newFacingDYaw -= 0x200) < DEGREES(-180)) {
newFacingDYaw = DEGREES(-180);
}
}
@ -211,7 +211,7 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
m->slideVelZ = m->slideVelZ * 100.0f / m->forwardVel;
}
if (newFacingDYaw < -0x4000 || newFacingDYaw > 0x4000) {
if (newFacingDYaw < DEGREES(-90) || newFacingDYaw > DEGREES(90)) {
m->forwardVel *= -1.0f;
}
}
@ -311,7 +311,7 @@ void apply_slope_accel(struct MarioState *m) {
break;
}
if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
if (floorDYaw > DEGREES(-90) && floorDYaw < DEGREES(90)) {
m->forwardVel += slopeAccel * steepness;
} else {
m->forwardVel -= slopeAccel * steepness;
@ -479,7 +479,7 @@ s32 should_begin_sliding(struct MarioState *m) {
s32 analog_stick_held_back(struct MarioState *m) {
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
return intendedDYaw < -0x471C || intendedDYaw > 0x471C;
return intendedDYaw < DEGREES(-100) || intendedDYaw > DEGREES(100);
}
s32 check_ground_dive_or_punch(struct MarioState *m) {
@ -685,7 +685,7 @@ void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
dWallAngle = wallAngle - m->faceAngle[1];
}
if (m->wall == NULL || dWallAngle <= -0x71C8 || dWallAngle >= 0x71C8) {
if (m->wall == NULL || dWallAngle < DEGREES(-160) || dWallAngle > DEGREES(160)) {
m->flags |= MARIO_UNKNOWN_31;
set_mario_animation(m, MARIO_ANIM_PUSHING);
play_step_sound(m, 6, 18);
@ -702,9 +702,9 @@ void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
}
m->actionState = 1;
m->actionArg = wallAngle + 0x8000;
m->marioObj->header.gfx.angle[1] = wallAngle + 0x8000;
m->marioObj->header.gfx.angle[2] = find_floor_slope(m, 0x4000);
m->actionArg = wallAngle + DEGREES(180);
m->marioObj->header.gfx.angle[1] = wallAngle + DEGREES(180);
m->marioObj->header.gfx.angle[2] = find_floor_slope(m, DEGREES(90));
}
}
@ -720,15 +720,15 @@ void tilt_body_walking(struct MarioState *m, s16 startYaw) {
s16 val02 = -(s16)(dYaw * m->forwardVel / 12.0f);
s16 val00 = (s16)(m->forwardVel * 170.0f);
if (val02 > 0x1555) {
val02 = 0x1555;
if (val02 > DEGREES(30)) {
val02 = DEGREES(30);
}
if (val02 < -0x1555) {
val02 = -0x1555;
if (val02 < DEGREES(-30)) {
val02 = DEGREES(-30);
}
if (val00 > 0x1555) {
val00 = 0x1555;
if (val00 > DEGREES(30)) {
val00 = DEGREES(30);
}
if (val00 < 0) {
val00 = 0;
@ -752,15 +752,15 @@ void tilt_body_ground_shell(struct MarioState *m, s16 startYaw) {
s16 val04 = -(s16)(dYaw * m->forwardVel / 12.0f);
s16 val02 = (s16)(m->forwardVel * 170.0f);
if (val04 > 0x1800) {
val04 = 0x1800;
if (val04 > DEGREES(33.75)) {
val04 = DEGREES(33.75);
}
if (val04 < -0x1800) {
val04 = -0x1800;
if (val04 < DEGREES(-33.75)) {
val04 = DEGREES(-33.75);
}
if (val02 > 0x1000) {
val02 = 0x1000;
if (val02 > DEGREES(22.5)) {
val02 = DEGREES(22.5);
}
if (val02 < 0) {
val02 = 0;
@ -1030,7 +1030,7 @@ s32 act_finish_turning_around(struct MarioState *m) {
set_mario_action(m, ACT_WALKING, 0);
}
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
return FALSE;
}
@ -1400,7 +1400,7 @@ void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32
slideSpeed = 4.0f;
}
m->slideYaw = wallAngle - (s16)(m->slideYaw - wallAngle) + 0x8000;
m->slideYaw = wallAngle - (s16)(m->slideYaw - wallAngle) + DEGREES(180);
m->vel[0] = m->slideVelX = slideSpeed * sins(m->slideYaw);
m->vel[2] = m->slideVelZ = slideSpeed * coss(m->slideYaw);
@ -1813,7 +1813,7 @@ s32 act_side_flip_land(struct MarioState *m) {
}
if (common_landing_action(m, MARIO_ANIM_SLIDEFLIP_LAND, ACT_FREEFALL) != GROUND_STEP_HIT_WALL) {
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
}
return FALSE;
}

View file

@ -153,7 +153,7 @@ s32 act_idle(struct MarioState *m) {
// and that he's gone through 10 cycles before sleeping.
// actionTimer is used to track how many cycles have passed.
if (++m->actionState == 3) {
f32 deltaYOfFloorBehindMario = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f);
f32 deltaYOfFloorBehindMario = m->pos[1] - find_floor_height_relative_polar(m, DEGREES(-180), 60.0f);
if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || m->floor->flags & SURFACE_FLAG_DYNAMIC) {
m->actionState = 0;
} else {
@ -265,7 +265,7 @@ s32 act_sleeping(struct MarioState *m) {
return set_mario_action(m, ACT_WAKING_UP, m->actionState);
}
if (m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f) > 24.0f) {
if (m->pos[1] - find_floor_height_relative_polar(m, DEGREES(-180), 60.0f) > 24.0f) {
return set_mario_action(m, ACT_WAKING_UP, m->actionState);
}
@ -888,7 +888,7 @@ s32 act_side_flip_land_stop(struct MarioState *m) {
}
landing_step(m, MARIO_ANIM_SLIDEFLIP_LAND, ACT_IDLE);
m->marioObj->header.gfx.angle[1] += 0x8000;
m->marioObj->header.gfx.angle[1] += DEGREES(180);
return FALSE;
}
@ -1070,7 +1070,7 @@ s32 act_first_person(struct MarioState *m) {
&& save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 10) {
s16 sp1A = m->statusForCamera->headRotation[0];
s16 sp18 = ((m->statusForCamera->headRotation[1] * 4) / 3) + m->faceAngle[1];
if (sp1A == -0x1800 && (sp18 < -0x6FFF || sp18 >= 0x7000)) {
if (sp1A == DEGREES(-33.75) && (sp18 <= DEGREES(-157.5) || sp18 >= DEGREES(157.5))) {
level_trigger_warp(m, WARP_OP_UNKNOWN_01);
}
}

View file

@ -143,7 +143,7 @@ static void apply_water_current(struct MarioState *m, Vec3f step) {
s16 pitchToWhirlpool = atan2s(lateralDist, dy);
s16 yawToWhirlpool = atan2s(dz, dx);
yawToWhirlpool -= (s16)(0x2000 * 1000.0f / (distance + 1000.0f));
yawToWhirlpool -= (s16)(DEGREES(45) * 1000.0f / (distance + 1000.0f));
if (whirlpool->strength >= 0) {
if (gCurrLevelNum == LEVEL_DDD && gCurrAreaIndex == 2) {
@ -341,7 +341,7 @@ static s32 act_water_idle(struct MarioState *m) {
return set_mario_action(m, ACT_BREASTSTROKE, 0);
}
if (m->faceAngle[0] < -0x1000) {
if (m->faceAngle[0] < DEGREES(-22.5)) {
val = 0x30000;
}
@ -446,29 +446,31 @@ static void common_swimming_step(struct MarioState *m, s16 swimStrength) {
switch (perform_water_step(m)) {
case WATER_STEP_HIT_FLOOR:
floorPitch = -find_floor_slope(m, -0x8000);
floorPitch = -find_floor_slope(m, DEGREES(-180));
if (m->faceAngle[0] < floorPitch) {
m->faceAngle[0] = floorPitch;
}
break;
case WATER_STEP_HIT_CEILING:
if (m->faceAngle[0] > -0x3000) {
if (m->faceAngle[0] > DEGREES(-67.5)) {
m->faceAngle[0] -= 0x100;
}
break;
case WATER_STEP_HIT_WALL:
if (m->controller->stickY == 0.0f) {
// These angles were likely specified as arbitrary s16 values,
// but are converted to degrees for consistency.
if (m->faceAngle[0] > 0.0f) {
m->faceAngle[0] += 0x200;
if (m->faceAngle[0] > 0x3F00) {
m->faceAngle[0] = 0x3F00;
if (m->faceAngle[0] > DEGREES(88.59375)) {
m->faceAngle[0] = DEGREES(88.59375);
}
} else {
m->faceAngle[0] -= 0x200;
if (m->faceAngle[0] < -0x3F00) {
m->faceAngle[0] = -0x3F00;
if (m->faceAngle[0] < DEGREES(-88.59375)) {
m->faceAngle[0] = DEGREES(-88.59375);
}
}
}
@ -780,7 +782,7 @@ static s32 check_water_grab(struct MarioState *m) {
f32 dz = object->oPosZ - m->pos[2];
s16 dAngleToObject = atan2s(dz, dx) - m->faceAngle[1];
if (dAngleToObject >= -0x2AAA && dAngleToObject <= 0x2AAA) {
if (dAngleToObject >= DEGREES(-60) && dAngleToObject <= DEGREES(60)) {
m->usedObj = object;
mario_grab_used_object(m);
m->marioBodyState->grabPos = GRAB_POS_LIGHT_OBJ;
@ -1059,13 +1061,13 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
if (distance <= 28.0f) {
newDistance = 16.0f;
angleChange = 0x1800;
angleChange = DEGREES(33.75);
} else if (distance < 256.0f) {
newDistance = distance - (12.0f - distance / 32.0f);
angleChange = (s16)(0x1C00 - distance * 20.0f);
angleChange = (s16)(DEGREES(39.375) - distance * 20.0f);
} else {
newDistance = distance - 4.0f;
angleChange = 0x800;
angleChange = DEGREES(11.25);
}
m->vel[1] = -640.0f / (newDistance + 16.0f);
@ -1085,7 +1087,7 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
m->pos[2] = whirlpool->oPosZ - dx * sinAngleChange + dz * cosAngleChange;
m->pos[1] = whirlpool->oPosY + marioObj->oMarioWhirlpoolPosY;
m->faceAngle[1] = atan2s(dz, dx) + 0x8000;
m->faceAngle[1] = atan2s(dz, dx) + DEGREES(180);
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);

View file

@ -220,9 +220,9 @@ static void star_door_unlock_spawn_particles(s16 angleOffset) {
struct Object *sparkleParticle = spawn_object(gCurrentObject, 0, bhvSparkleSpawn);
sparkleParticle->oPosX +=
100.0f * sins((gCurrentObject->oUnlockDoorStarTimer * 0x2800) + angleOffset);
100.0f * sins((gCurrentObject->oUnlockDoorStarTimer * DEGREES(56.25)) + angleOffset);
sparkleParticle->oPosZ +=
100.0f * coss((gCurrentObject->oUnlockDoorStarTimer * 0x2800) + angleOffset);
100.0f * coss((gCurrentObject->oUnlockDoorStarTimer * DEGREES(56.25)) + angleOffset);
// Particles are spawned lower each frame
sparkleParticle->oPosY -= gCurrentObject->oUnlockDoorStarTimer * 10.0f;
}
@ -231,9 +231,9 @@ void bhv_unlock_door_star_init(void) {
gCurrentObject->oUnlockDoorStarState = UNLOCK_DOOR_STAR_RISING;
gCurrentObject->oUnlockDoorStarTimer = 0;
gCurrentObject->oUnlockDoorStarYawVel = 0x1000;
gCurrentObject->oPosX += 30.0f * sins(gMarioState->faceAngle[1] - 0x4000);
gCurrentObject->oPosX += 30.0f * sins(gMarioState->faceAngle[1] - DEGREES(90));
gCurrentObject->oPosY += 160.0f;
gCurrentObject->oPosZ += 30.0f * coss(gMarioState->faceAngle[1] - 0x4000);
gCurrentObject->oPosZ += 30.0f * coss(gMarioState->faceAngle[1] - DEGREES(90));
gCurrentObject->oMoveAngleYaw = 0x7800;
obj_scale(gCurrentObject, 0.5f);
}
@ -273,8 +273,8 @@ void bhv_unlock_door_star_loop(void) {
break;
case UNLOCK_DOOR_STAR_SPAWNING_PARTICLES:
// Spawn two particles, opposite sides of the star.
star_door_unlock_spawn_particles(0);
star_door_unlock_spawn_particles(0x8000);
star_door_unlock_spawn_particles(DEGREES(0));
star_door_unlock_spawn_particles(DEGREES(180));
if (gCurrentObject->oUnlockDoorStarTimer++ == 20) {
gCurrentObject->oUnlockDoorStarTimer = 0;
gCurrentObject->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_DONE

View file

@ -75,7 +75,7 @@ BAD_RETURN(s32) init_bully_collision_data(struct BullyCollisionData *data, f32 p
f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius) {
if (forwardVel < 0.0f) {
forwardVel *= -1.0f;
yaw += 0x8000;
yaw += DEGREES(180);
}
data->radius = radius;
@ -100,7 +100,7 @@ void mario_bonk_reflection(struct MarioState *m, u32 negateSpeed) {
if (negateSpeed) {
mario_set_forward_vel(m, -m->forwardVel);
} else {
m->faceAngle[1] += 0x8000;
m->faceAngle[1] += DEGREES(180);
}
}
@ -158,12 +158,12 @@ u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg) {
s16 floorDYaw = m->floorAngle - m->faceAngle[1];
if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
if (floorDYaw > DEGREES(-90) && floorDYaw < DEGREES(90)) {
m->forwardVel = 16.0f;
m->faceAngle[1] = m->floorAngle;
} else {
m->forwardVel = -16.0f;
m->faceAngle[1] = m->floorAngle + 0x8000;
m->faceAngle[1] = m->floorAngle + DEGREES(180);
}
return set_mario_action(m, action, actionArg);
@ -199,7 +199,7 @@ u32 mario_update_windy_ground(struct MarioState *m) {
pushSpeed = m->forwardVel > 0.0f ? -m->forwardVel * 0.5f : -8.0f;
if (pushDYaw > -0x4000 && pushDYaw < 0x4000) {
if (pushDYaw > DEGREES(-90) && pushDYaw < DEGREES(90)) {
pushSpeed *= -1.0f;
}
@ -306,10 +306,10 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
if (upperWall != NULL) {
s16 wallDYaw = atan2s(upperWall->normal.z, upperWall->normal.x) - m->faceAngle[1];
if (wallDYaw >= 0x2AAA && wallDYaw <= 0x5555) {
if (wallDYaw >= DEGREES(60) && wallDYaw <= DEGREES(120)) {
return GROUND_STEP_NONE;
}
if (wallDYaw <= -0x2AAA && wallDYaw >= -0x5555) {
if (wallDYaw <= DEGREES(-60) && wallDYaw >= DEGREES(-120)) {
return GROUND_STEP_NONE;
}
@ -381,7 +381,7 @@ u32 check_ledge_grab(struct MarioState *m, struct Surface *wall, Vec3f intendedP
m->floorAngle = atan2s(ledgeFloor->normal.z, ledgeFloor->normal.x);
m->faceAngle[0] = 0;
m->faceAngle[1] = atan2s(wall->normal.z, wall->normal.x) + 0x8000;
m->faceAngle[1] = atan2s(wall->normal.z, wall->normal.x) + DEGREES(180);
return TRUE;
}
@ -491,7 +491,7 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
return AIR_STEP_HIT_LAVA_WALL;
}
if (wallDYaw < -0x6000 || wallDYaw > 0x6000) {
if (wallDYaw < DEGREES(-135) || wallDYaw > DEGREES(135)) {
m->flags |= MARIO_UNKNOWN_30;
return AIR_STEP_HIT_WALL;
}