Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DEGREES macro in math/physics/action code #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/engine/math_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -718,28 +718,28 @@ 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 {
x = -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);
}
Expand Down
20 changes: 20 additions & 0 deletions src/engine/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@

#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.
* 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
Expand Down
Loading