persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
geometry.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8template <typename T> struct Point2D
9{
10 T x;
11 T z;
12
13 Point2D() : x(0), z(0)
14 {
15 }
16 Point2D(T x, T z) : x(x), z(z)
17 {
18 }
19
20 Point2D<T> operator+(const Point2D<T>& other) const
21 {
22 return Point2D<T>(x + other.x, z + other.z);
23 }
24
25 Point2D<T> operator-(const Point2D<T>& other) const
26 {
27 return Point2D<T>(x - other.x, z - other.z);
28 }
29
31 {
32 x = other.x;
33 z = other.z;
34 return *this;
35 }
36
37 bool operator==(const Point2D<T>& other) const = default;
38};
39
40template <typename T> struct Rectangle
41{
44
46 {
47 return this->position + this->size;
48 }
49
51 {
52 return this->position + Point2D<T>(0, size.z);
53 }
54
56 {
57 return this->position;
58 }
59
61 {
62 return this->position + Point2D<T>(size.x, 0);
63 }
64
65 T top() const
66 {
67 return position.z;
68 }
69
70 T left() const
71 {
72 return position.x;
73 }
74
75 T bottom() const
76 {
77 return position.z + size.z;
78 }
79
80 T right() const
81 {
82 return position.x + size.x;
83 }
84
85 T width() const
86 {
87 return size.x;
88 }
89
90 T height() const
91 {
92 return size.z;
93 }
94
95 bool checkCollision(const Rectangle<T>& other, bool ignoreTouching = true) const
96 {
97 if (ignoreTouching)
98 {
99 return (left() < other.right() && right() > other.left()) &&
100 (top() < other.bottom() && bottom() > other.top());
101 }
102
103 return (left() <= other.right() && right() >= other.left()) &&
104 (top() <= other.bottom() && bottom() >= other.top());
105 }
106
107 bool operator==(const Rectangle<T>& other) const = default;
108};
109
110template <typename T> struct Vec3
111{
112 T x;
113 T y;
114 T z;
115
116 Vec3() : x(0), y(0), z(0)
117 {
118 }
119 Vec3(T x, T y, T z) : x(x), y(y), z(z)
120 {
121 }
122
123 Vec3<T> operator+(const Vec3<T>& other) const
124 {
125 return Vec3<T>(x + other.x, y + other.y, z + other.z);
126 }
127
128 Vec3<T> operator-(const Vec3<T>& other) const
129 {
130 return Vec3<T>(x - other.x, y - other.y, z - other.z);
131 }
132
133 Vec3<T> operator*(T scalar) const
134 {
135 return Vec3<T>(x * scalar, y * scalar, z * scalar);
136 }
137
139 {
140 x += other.x;
141 y += other.y;
142 z += other.z;
143 return *this;
144 }
145
146 Vec3<T>& operator=(const Vec3<T>& other)
147 {
148 x = other.x;
149 y = other.y;
150 z = other.z;
151 return *this;
152 }
153
154 bool operator==(const Vec3<T>& other) const = default;
155
156 T dot(const Vec3<T>& other) const
157 {
158 return x * other.x + y * other.y + z * other.z;
159 }
160
161 Vec3<T> cross(const Vec3<T>& other) const
162 {
163 return Vec3<T>(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
164 }
165};
Point2D< T > operator+(const Point2D< T > &other) const
Definition geometry.hpp:20
Point2D(T x, T z)
Definition geometry.hpp:16
bool operator==(const Point2D< T > &other) const =default
Point2D< T > & operator=(const Point2D< T > &other)
Definition geometry.hpp:30
Point2D< T > operator-(const Point2D< T > &other) const
Definition geometry.hpp:25
Point2D< T > position
Definition geometry.hpp:42
T width() const
Definition geometry.hpp:85
bool operator==(const Rectangle< T > &other) const =default
T right() const
Definition geometry.hpp:80
Point2D< T > topRight() const
Definition geometry.hpp:60
T top() const
Definition geometry.hpp:65
T height() const
Definition geometry.hpp:90
Point2D< T > bottomRight() const
Definition geometry.hpp:45
Point2D< T > bottomLeft() const
Definition geometry.hpp:50
bool checkCollision(const Rectangle< T > &other, bool ignoreTouching=true) const
Definition geometry.hpp:95
Point2D< T > size
Definition geometry.hpp:43
T left() const
Definition geometry.hpp:70
T bottom() const
Definition geometry.hpp:75
Point2D< T > topLeft() const
Definition geometry.hpp:55
T dot(const Vec3< T > &other) const
Definition geometry.hpp:156
bool operator==(const Vec3< T > &other) const =default
Vec3< T > & operator+=(const Vec3< T > &other)
Definition geometry.hpp:138
Vec3< T > cross(const Vec3< T > &other) const
Definition geometry.hpp:161
Vec3< T > operator*(T scalar) const
Definition geometry.hpp:133
Vec3< T > operator-(const Vec3< T > &other) const
Definition geometry.hpp:128
Vec3< T > operator+(const Vec3< T > &other) const
Definition geometry.hpp:123
Vec3< T > & operator=(const Vec3< T > &other)
Definition geometry.hpp:146
Vec3(T x, T y, T z)
Definition geometry.hpp:119