NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_vec.cpp
1#include <game/mLib/m_angle.hpp>
2#include <game/mLib/m_vec.hpp>
3#include <lib/MSL_C/float.h>
4#include <lib/MSL_C/math.h>
6#include <lib/rvl/mtx/vec.h>
7
8// [This is required to ensure correct sdata2 ordering]
9// [It will be deadstripped by the linker later]
10float DUMMY_M_VEC(s16 val) {
11 return nw4r::math::CosS(val);
12}
13
14inline bool isZero(float val) {
15 return (fabsf(val) <= FLT_EPSILON);
16}
17
19 float mag = PSVECMag(*this);
20 if (!isZero(mag)) {
21 operator*=(1.0f/mag);
22 }
23
24 return mag;
25}
26
28 float mag = PSVECMag(*this);
29 if (isZero(mag)) {
30 return false;
31 }
32
33 operator*=(1.0f/mag);
34 return true;
35}
36
37void mVec3_c::rotX(mAng angle) {
38 float cos = angle.cos();
39 float sin = angle.sin();
40 float y = this->y;
41 float z = this->z;
42 this->y = cos * y - sin * z;
43 this->z = sin * y + cos * z;
44}
45
46void mVec3_c::rotY(mAng angle) {
47 float cos = angle.cos();
48 float sin = angle.sin();
49 float x = this->x;
50 float z = this->z;
51 this->x = cos * x + sin * z;
52 this->z = -sin * x + cos * z;
53}
54
55mVec3_c mVec3_c::Zero = mVec3_c(0.0f, 0.0f, 0.0f);
56mVec3_c mVec3_c::Ex = mVec3_c(1.0f, 0.0f, 0.0f);
57mVec3_c mVec3_c::Ey = mVec3_c(0.0f, 1.0f, 0.0f);
58mVec3_c mVec3_c::Ez = mVec3_c(0.0f, 0.0f, 1.0f);
A three-dimensional floating point vector.
Definition m_vec.hpp:100
static mVec3_c Ex
The unit vector for the X axis.
Definition m_vec.hpp:184
static mVec3_c Ey
The unit vector for the Y axis.
Definition m_vec.hpp:185
bool normalizeRS()
Normalizes the vector.
Definition m_vec.cpp:27
float normalize()
Normalizes the vector.
Definition m_vec.cpp:18
mVec3_c & operator*=(f32 f)
Augmented scalar product operator.
Definition m_vec.hpp:143
void rotX(mAng angle)
Rotates the vector on the X axis by the given angle.
Definition m_vec.cpp:37
void rotY(mAng angle)
Rotates the vector on the Y axis by the given angle.
Definition m_vec.cpp:46
static mVec3_c Zero
The null vector.
Definition m_vec.hpp:183
static mVec3_c Ez
The unit vector for the Z axis.
Definition m_vec.hpp:186
f32 PSVECMag(const Vec *v)
Computes the magnitude of a vector.
float fabsf(float x)
Returns the absolute value of x.
Definition math.h:20
#define FLT_EPSILON
Difference between 1 and the smallest 32-bit floating-point value greater than 1.
Definition float.h:12
float CosS(short ang)
Computes the cosine value.
A one-dimensional short angle vector.
Definition m_angle.hpp:8
float cos() const
Computes the cosine of the angle.
Definition m_angle.hpp:53
float sin() const
Computes the sine of the angle.
Definition m_angle.hpp:50