mirror of
https://github.com/izzy2lost/2ship2harkinian-Android.git
synced 2026-06-19 01:20:08 -07:00
Angle Conversions (#1216)
* Angle Conversions * Format * namefixer * Renames in ObjHsStump_Appear * Format * once more * Explicit cast in EnSsh * Update src/overlays/actors/ovl_En_Fishing/z_en_fishing.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
co-authored by
engineer124
parent
a67d086add
commit
823746d495
+21
-6
@@ -114,13 +114,28 @@ typedef struct {
|
||||
|
||||
#define IS_ZERO(f) (fabsf(f) < 0.008f)
|
||||
|
||||
// Casting a float to an integer, when the float value is larger than what the integer type can hold,
|
||||
// leads to undefined behavior. For example (f32)0x8000 doesn't fit in a s16, so it cannot be cast to s16.
|
||||
// This isn't an issue with IDO, but is one with for example GCC.
|
||||
// A partial workaround is to cast to s32 then s16, hoping all binang values used will fit a s32.
|
||||
#define TRUNCF_BINANG(f) (s16)(s32)(f)
|
||||
|
||||
// Angle conversion macros
|
||||
#define DEG_TO_BINANG(degrees) (s16)((degrees) * (0x8000 / 180.0f))
|
||||
#define RADF_TO_BINANG(radf) (s16)((radf) * (0x8000 / M_PI))
|
||||
#define RADF_TO_DEGF(radf) ((radf) * (180.0f / M_PI))
|
||||
#define DEGF_TO_RADF(degf) ((degf) * (M_PI / 180.0f))
|
||||
#define BINANG_TO_RAD(binang) ((f32)binang * (M_PI / 0x8000))
|
||||
#define BINANG_TO_RAD_ALT(binang) (((f32)binang / 0x8000) * M_PI)
|
||||
#define DEG_TO_RAD(degrees) ((degrees) * (M_PI / 180.0f))
|
||||
#define DEG_TO_BINANG(degrees) TRUNCF_BINANG((degrees) * (0x8000 / 180.0f))
|
||||
#define DEG_TO_BINANG_ALT(degrees) TRUNCF_BINANG(((degrees) / 180.0f) * 0x8000)
|
||||
#define DEG_TO_BINANG_ALT2(degrees) TRUNCF_BINANG(((degrees) * 0x10000) / 360.0f)
|
||||
#define DEG_TO_BINANG_ALT3(degrees) ((degrees) * (0x8000 / 180.0f))
|
||||
|
||||
#define RAD_TO_DEG(radians) ((radians) * (180.0f / M_PI))
|
||||
#define RAD_TO_BINANG(radians) TRUNCF_BINANG((radians) * (0x8000 / M_PI))
|
||||
#define RAD_TO_BINANG_ALT(radians) TRUNCF_BINANG(((radians) / M_PI) * 0x8000)
|
||||
#define RAD_TO_BINANG_ALT2(radians) TRUNCF_BINANG(((radians) * 0x8000) / M_PI)
|
||||
|
||||
#define BINANG_TO_DEG(binang) ((f32)(binang) * (180.0f / 0x8000))
|
||||
#define BINANG_TO_RAD(binang) ((f32)(binang) * (M_PI / 0x8000))
|
||||
#define BINANG_TO_RAD_ALT(binang) (((f32)(binang) / 0x8000) * M_PI)
|
||||
#define BINANG_TO_RAD_ALT2(binang) (((f32)(binang) * M_PI) / 0x8000)
|
||||
|
||||
// Angle arithmetic macros
|
||||
#define BINANG_ROT180(angle) ((s16)(angle + 0x8000))
|
||||
|
||||
Reference in New Issue
Block a user