Unravel Engine C++ Reference
Loading...
Searching...
No Matches
plane.h
Go to the documentation of this file.
1#pragma once
2
3#include "transform.hpp"
4#include <glm/glm.hpp>
5#include <glm/gtc/matrix_transform.hpp>
6
7namespace math
8{
9using namespace glm;
10
11//-----------------------------------------------------------------------------
12// Main class declarations
13//-----------------------------------------------------------------------------
14//-----------------------------------------------------------------------------
15// Name : plane (Class)
19//-----------------------------------------------------------------------------
20struct plane
21{
22 //-------------------------------------------------------------------------
23 // Friend List
24 //-------------------------------------------------------------------------
25
35 friend auto operator*(float s, const plane& p) -> plane;
36
42 static auto xy_plane() -> plane;
43
49 static auto xz_plane() -> plane;
50
56 static auto yz_plane() -> plane;
57 //-------------------------------------------------------------------------
58 // Constructors & Destructors
59 //-------------------------------------------------------------------------
60
67
75 plane(const vec4& p);
76
87 plane(float _a, float _b, float _c, float _d);
88
89 //-------------------------------------------------------------------------
90 // Public Static Methods
91 //-------------------------------------------------------------------------
92
100 static auto dot(const plane& p, const vec4& v) -> float;
101
109 static auto dot_coord(const plane& p, const vec3& v) -> float;
110
118 static auto dot_normal(const plane& p, const vec3& v) -> float;
119
127 static auto from_point_normal(const vec3& point, const vec3& normal) -> plane;
128
137 static auto from_points(const vec3& v1, const vec3& v2, const vec3& v3) -> plane;
138
146 static auto mul(const plane& p, const mat4& m) -> plane;
147
156 static auto normalize(const plane& p) -> plane;
157
167 static auto scale(const plane& p, float s) -> plane;
168
169 //-------------------------------------------------------------------------
170 // Public Operators
171 //-------------------------------------------------------------------------
178 auto operator*(float s) const -> plane;
179
186 auto operator/(float s) const -> plane;
187
194 auto operator*=(float s) -> plane&;
195
202 auto operator/=(float s) -> plane&;
203
209 auto operator+() const -> plane;
210
218 auto operator-() const -> plane;
219
228 auto operator==(const plane& p) const -> bool;
229
238 auto operator!=(const plane& p) const -> bool;
239
248 auto operator=(const vec4& rhs) -> plane&;
249
250 //-------------------------------------------------------------------------
251 // Public Members
252 //-------------------------------------------------------------------------
253
260 vec4 data = {0.0f, 0.0f, 0.0f, 0.0f};
261};
262
263//-----------------------------------------------------------------------------
264// Global Inline Operators (plane)
265//-----------------------------------------------------------------------------
275inline auto operator*(float s, const plane& p) -> plane
276{
277 return plane(p.data * s);
278}
279} // namespace math
math::vec3 normal
Definition defaults.cpp:53
Definition bbox.cpp:5
auto operator*(float s, const plane &p) -> plane
Scalar multiplication for a plane.
Definition plane.h:275
std::vector< float > scale
Storage for infinite plane.
Definition plane.h:21
static auto xz_plane() -> plane
XZ plane.
Definition plane.cpp:111
auto operator*=(float s) -> plane &
Multiplies and assigns the plane by a scalar value.
Definition plane.cpp:58
static auto normalize(const plane &p) -> plane
Normalizes the plane.
Definition plane.cpp:37
static auto xy_plane() -> plane
XY plane.
Definition plane.cpp:106
static auto from_point_normal(const vec3 &point, const vec3 &normal) -> plane
Creates a plane from a point and a normal.
Definition plane.cpp:20
auto operator+() const -> plane
Unary plus operator.
Definition plane.cpp:70
friend auto operator*(float s, const plane &p) -> plane
Scalar multiplication for a plane.
Definition plane.h:275
auto operator/(float s) const -> plane
Divides the plane by a scalar value.
Definition plane.cpp:53
static auto from_points(const vec3 &v1, const vec3 &v2, const vec3 &v3) -> plane
Creates a plane from three points.
Definition plane.cpp:26
static auto dot_normal(const plane &p, const vec3 &v) -> float
Computes the dot product of the plane normal and a vec3.
Definition plane.cpp:15
auto operator/=(float s) -> plane &
Divides and assigns the plane by a scalar value.
Definition plane.cpp:64
plane()
Default constructor.
static auto dot(const plane &p, const vec4 &v) -> float
Computes the dot product of the plane and a vec4.
Definition plane.cpp:5
static auto yz_plane() -> plane
YZ plane.
Definition plane.cpp:116
static auto dot_coord(const plane &p, const vec3 &v) -> float
Computes the dot product of the plane and a vec3 (considering the plane's distance).
Definition plane.cpp:10
static auto mul(const plane &p, const mat4 &m) -> plane
Transforms a plane by a 4x4 matrix.
Definition plane.cpp:32
vec4 data
The components of the plane.
Definition plane.h:260