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
18 template <>
19 float Math<float>::abs(float v) {
20 return fabs(v);
21 }
22
23 typedef Math<float> Mathf;
24
25 /// @brief A two-dimensional floating point vector.
26 class Vector2f : public nw4r::math::VEC2 {
27 public:
28 /// @brief Constructs an empty vector.
30
31 ~Vector2f() {}
32
33 /// @brief Constructs a vector from two floating point values.
34 Vector2f(f32 fx, f32 fy) { set(fx, fy); }
35
36 void set(float x, float y) {
37 this->x = x;
38 this->y = y;
39 }
40
41 float normalise();
42
43 /// @brief Gets the length of the vector.
44 float getLength() const { return EGG::Mathf::sqrt(x * x + y * y); }
45 };
46
47 /// @brief A three-dimensional floating point vector.
48 class Vector3f : public nw4r::math::VEC3 {
49 public:
50 /// @brief Constructs an empty vector.
52
53 ~Vector3f() {}
54
55 /// @brief Constructs a vector from two floating point values.
56 Vector3f(f32 fx, f32 fy, f32 fz) { set(fx, fy, fz); }
57
58 void set(float x, float y, float z) {
59 this->x = x;
60 this->y = y;
61 this->z = z;
62 }
63 };
64
65 /// @brief A sphere defined by a center point and a radius.
66 class Sphere3f {
67 public:
68 Sphere3f() {}
69
70 /// @brief Constructs a sphere from a center and radius.
71 Sphere3f(const Vector3f &center, float radius) : mPos(center), mRadius(radius) {}
72
73 Vector3f mPos;
74 float mRadius;
75 };
76}
Sphere3f(const Vector3f &center, float radius)
Constructs a sphere from a center and radius.
Definition math.hpp:71
A two-dimensional floating point vector.
Definition math.hpp:26
Vector2f()
Constructs an empty vector.
Definition math.hpp:29
float getLength() const
Gets the length of the vector.
Definition math.hpp:44
Vector2f(f32 fx, f32 fy)
Constructs a vector from two floating point values.
Definition math.hpp:34
A three-dimensional floating point vector.
Definition math.hpp:48
Vector3f()
Constructs an empty vector.
Definition math.hpp:51
Vector3f(f32 fx, f32 fy, f32 fz)
Constructs a vector from two floating point values.
Definition math.hpp:56
double fabs(double x)
Returns the absolute value of x.
Definition math.h:15
A three-dimensional floating point vector.
Definition vec.hpp:22