mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-09-07 10:11:43 -04:00
c_xyz OK
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
#ifndef C_XYZ_H
|
||||
#define C_XYZ_H
|
||||
|
||||
#include "dolphin/types.h"
|
||||
#include "global.h"
|
||||
#include "mtx_vec.h"
|
||||
|
||||
struct cXyz : Vec {
|
||||
static const cXyz Zero;
|
||||
static const cXyz BaseX;
|
||||
static const cXyz BaseY;
|
||||
static const cXyz BaseZ;
|
||||
static const cXyz BaseXY;
|
||||
static const cXyz BaseXZ;
|
||||
static const cXyz BaseYZ;
|
||||
static const cXyz BaseXYZ;
|
||||
/* 80009184 */ ~cXyz() {}
|
||||
/* inlined */ cXyz() {}
|
||||
cXyz(f32 x, f32 y, f32 z) {
|
||||
@@ -98,6 +106,16 @@ struct cXyz : Vec {
|
||||
}
|
||||
|
||||
float getSquareMag() const { return PSVECSquareMag(this); }
|
||||
|
||||
static float getNearZeroValue() { return 8e-11f; }
|
||||
|
||||
bool isNearZeroSquare() const { return (this->getSquareMag() < getNearZeroValue()); }
|
||||
f32 abs2() const { return this->getSquareMag(); }
|
||||
f32 abs2XZ() const {
|
||||
cXyz tmp(this->x, 0, this->z);
|
||||
return tmp.abs2();
|
||||
}
|
||||
f32 getMagXZ() const { return cXyz(this->x, 0, this->z).getSquareMag(); }
|
||||
};
|
||||
|
||||
#endif /* C_XYZ_H */
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef _global_h_
|
||||
#define _global_h_
|
||||
|
||||
#include "dolphin/types.h"
|
||||
|
||||
#define ARRAY_SIZE(o) (sizeof((o)) / sizeof(*(o)))
|
||||
|
||||
// Align X to the previous N bytes (N must be power of two)
|
||||
#define ALIGN_PREV(X, N) ((X) & ~((N)-1))
|
||||
// Align X to the next N bytes (N must be power of two)
|
||||
#define ALIGN_NEXT(X, N) ALIGN_PREV(((X) + (N)-1), N)
|
||||
#define IS_ALIGNED(X, N) (((X) & ((N)-1)) == 0)
|
||||
#define IS_NOT_ALIGNED(X, N) (((X) & ((N)-1)) != 0)
|
||||
|
||||
#define JUT_ASSERT(...)
|
||||
#define JUT_EXPECT(...)
|
||||
#define ASSERT(...)
|
||||
#define LOGF(FMT, ...)
|
||||
#define FLAG_ON(V, F) (((V) & (F)) == 0)
|
||||
|
||||
#define FLOAT_LABEL(x) (*(f32*)&x)
|
||||
#define DOUBLE_LABEL(x) (*(f64*)&x)
|
||||
|
||||
#define _SDA_BASE_(dummy) 0
|
||||
#define _SDA2_BASE_(dummy) 0
|
||||
|
||||
struct JUTWarn {
|
||||
JUTWarn& operator<<(const char*) { return *this; }
|
||||
JUTWarn& operator<<(long) { return *this; }
|
||||
};
|
||||
|
||||
// hack to make functions that return comparisons as int match
|
||||
extern int __cntlzw(unsigned int);
|
||||
inline BOOL checkEqual(s32 a, s32 b) {
|
||||
return (u32)__cntlzw(a - b) >> 5;
|
||||
}
|
||||
|
||||
#endif
|
||||
+22
-2
@@ -60,8 +60,28 @@ f64 sqrt(f64);
|
||||
f64 tan(f64);
|
||||
f32 tanf(f32);
|
||||
|
||||
__declspec(section ".sdata") extern f32 __float_nan;
|
||||
__declspec(section ".sdata") extern f32 __float_epsilon;
|
||||
extern f32 __float_nan[4];
|
||||
extern f32 __float_epsilon[4];
|
||||
|
||||
inline f64 sqrt_step(f64 tmpd, f32 mag) {
|
||||
return tmpd * 0.5 * (3.0 - mag * (tmpd * tmpd));
|
||||
}
|
||||
|
||||
inline f32 sqrtf(f32 mag) {
|
||||
if (mag > 0.0f) {
|
||||
f64 tmpd = __frsqrte(mag);
|
||||
tmpd = sqrt_step(tmpd, mag);
|
||||
tmpd = sqrt_step(tmpd, mag);
|
||||
tmpd = sqrt_step(tmpd, mag);
|
||||
return mag * tmpd;
|
||||
} else if (mag < 0.0) {
|
||||
return /* __float_nan */ __float_nan[0];
|
||||
} else if (fpclassify(mag) == 1) {
|
||||
return /* __float_nan */ __float_nan[0];
|
||||
} else {
|
||||
return mag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user