NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
math.hpp
1#pragma once
2
3#include <lib/nw4r/math/vec.hpp>
4#include <lib/MSL_C/math.h>
5
6namespace EGG {
7 /// @note Unfinished
8 template <class T>
9 class Math {
10 public:
11 static T sqrt(T v);
12
13 static T abs(T v) {
14 return v < 0 ? -v : v;
15 }
16
17 static T zero() { return 0; }
18 };
19
20 template <>
21 float Math<float>::abs(float v) {
22 return fabs(v);
23 }
24
25 typedef Math<float> Mathf;
26
27 /// @brief A two-dimensional floating point vector.
28 class Vector2f : public nw4r::math::VEC2 {
29 public:
30 /// @brief Constructs an empty vector.
32
33 ~Vector2f() {}
34
35 /// @brief Constructs a vector from two floating point values.
36 Vector2f(f32 fx, f32 fy) { set(fx, fy); }
37
38 void set(float x, float y) {
39 this->x = x;
40 this->y = y;
41 }
42
43 float normalise();
44
45 /// @brief Gets the length of the vector.
46 float getLength() const { return EGG::Mathf::sqrt(x * x + y * y); }
47 };
48
49 /// @brief A three-dimensional floating point vector.
50 class Vector3f : public nw4r::math::VEC3 {
51 public:
52 /// @brief Constructs an empty vector.
54
55 ~Vector3f() {}
56
57 /// @brief Constructs a vector from two floating point values.
58 Vector3f(f32 fx, f32 fy, f32 fz) { set(fx, fy, fz); }
59
60 void set(float x, float y, float z) {
61 this->x = x;
62 this->y = y;
63 this->z = z;
64 }
65 };
66
67 /// @brief A sphere defined by a center point and a radius.
68 class Sphere3f {
69 public:
70 Sphere3f() {}
71
72 /// @brief Constructs a sphere from a center and radius.
73 Sphere3f(const Vector3f &center, float radius) : mPos(center), mRadius(radius) {}
74
75 Vector3f mPos;
76 float mRadius;
77 };
78}
Sphere3f(const Vector3f &center, float radius)
Constructs a sphere from a center and radius.
Definition math.hpp:73
A two-dimensional floating point vector.
Definition math.hpp:28
Vector2f()
Constructs an empty vector.
Definition math.hpp:31
float getLength() const
Gets the length of the vector.
Definition math.hpp:46
Vector2f(f32 fx, f32 fy)
Constructs a vector from two floating point values.
Definition math.hpp:36
A three-dimensional floating point vector.
Definition math.hpp:50
Vector3f()
Constructs an empty vector.
Definition math.hpp:53
Vector3f(f32 fx, f32 fy, f32 fz)
Constructs a vector from two floating point values.
Definition math.hpp:58
double fabs(double x)
Returns the absolute value of x.
Definition math.h:15
A three-dimensional floating point vector.
Definition vec.hpp:22