RoboidControl
Loading...
Searching...
No Matches
Vector3.h
Go to the documentation of this file.
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0.If a copy of the MPL was not distributed with this
3// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
4
5#ifndef VECTOR3_H
6#define VECTOR3_H
7
8#include "Vector2.h"
9
10namespace Passer {
11namespace LinearAlgebra {
12
13struct Spherical;
14
15extern "C" {
21typedef struct Vec3 {
22protected:
26 float x;
30 float y;
34 float z;
35
36} Vec3;
37}
38
42struct Vector3 : Vec3 {
43 friend struct Vec3;
44
45public:
47 Vector3();
52 Vector3(float right, float up, float forward);
60
62 ~Vector3();
63
65 const static Vector3 zero;
67 const static Vector3 one;
69 const static Vector3 forward;
71 const static Vector3 back;
73 const static Vector3 right;
75 const static Vector3 left;
77 const static Vector3 up;
79 const static Vector3 down;
80
81 // Access functions which are intended to replace the use of XYZ
82 inline float Forward() const { return z; };
83 inline float Up() const { return y; };
84 inline float Right() const { return x; };
85
91 bool operator==(const Vector3 &v);
92
96 static float Magnitude(const Vector3 &v);
99 float magnitude() const;
106 static float SqrMagnitude(const Vector3 &v);
112 float sqrMagnitude() const;
113
117 static Vector3 Normalize(const Vector3 &v);
120 Vector3 normalized() const;
121
124 Vector3 operator-() const;
125
129 Vector3 operator-(const Vector3 &v) const;
130 Vector3 operator-=(const Vector3 &v);
134 Vector3 operator+(const Vector3 &v) const;
135 Vector3 operator+=(const Vector3 &v);
136
143 static Vector3 Scale(const Vector3 &v1, const Vector3 &v2);
149 friend Vector3 operator*(const Vector3 &v, float f);
150 friend Vector3 operator*(float f, const Vector3 &v);
151 Vector3 operator*=(float f);
156 friend Vector3 operator/(const Vector3 &v, float f);
157 friend Vector3 operator/(float f, const Vector3 &v);
158 Vector3 operator/=(float f);
159
164 static float Distance(const Vector3 &v1, const Vector3 &v2);
165
170 static float Dot(const Vector3 &v1, const Vector3 &v2);
171
176 static Vector3 Cross(const Vector3 &v1, const Vector3 &v2);
177
182 static Vector3 Project(const Vector3 &v, const Vector3 &n);
188 static Vector3 ProjectOnPlane(const Vector3 &v, const Vector3 &n);
189
197 static float Angle(const Vector3 &v1, const Vector3 &v2);
203 static float SignedAngle(const Vector3 &v1, const Vector3 &v2,
204 const Vector3 &axis);
205
214 static Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float f);
215};
216
217} // namespace LinearAlgebra
218} // namespace Passer
219using namespace Passer::LinearAlgebra;
220
221#include "Spherical.h"
222
223#endif
Definition Angle.h:9
AngleOf< float > Angle
Definition Angle.h:42
Definition AbsoluteEncoder.h:5
A spherical vector.
Definition Spherical.h:21
3-dimensional Vector representation
Definition Vector3.h:21
float z
The forward axis of the vector.
Definition Vector3.h:34
float y
The upward axis of the vector.
Definition Vector3.h:30
float x
The right axis of the vector.
Definition Vector3.h:26
A 2=dimensional vector.
Definition Vector2.h:38
A 3-dimensional vector.
Definition Vector3.h:42
float Right() const
Definition Vector3.h:84
static const Vector3 back
A normalized back-oriented vector.
Definition Vector3.h:71
static const Vector3 left
A normalized left-oriented vector.
Definition Vector3.h:75
Vector3()
A new 3-dimensional zero vector.
Definition Vector3.cpp:15
static float Distance(const Vector3 &v1, const Vector3 &v2)
The distance between two vectors.
Definition Vector3.cpp:154
float Forward() const
Definition Vector3.h:82
Vector3(Spherical v)
Convert vector in spherical coordinates to 3d carthesian coordinates.
static const Vector3 one
A vector with one for all axis.
Definition Vector3.h:67
static float Dot(const Vector3 &v1, const Vector3 &v2)
The dot product of two vectors.
Definition Vector3.cpp:146
static float SqrMagnitude(const Vector3 &v)
The squared vector length.
Definition Vector3.cpp:73
static Vector3 Normalize(const Vector3 &v)
Convert the vector to a length of 1.
Definition Vector3.cpp:78
Vector3 operator+=(const Vector3 &v)
Definition Vector3.cpp:111
friend Vector3 operator*(const Vector3 &v, float f)
Scale the vector uniformly up.
static Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float f)
Lerp (linear interpolation) between two vectors.
Definition Vector3.cpp:215
~Vector3()
Vector3 destructor.
Definition Vector3.cpp:50
float magnitude() const
The vector length.
Definition Vector3.cpp:71
Vector3 normalized() const
Convert the vector to a length of 1.
Definition Vector3.cpp:86
bool operator==(const Vector3 &v)
Check if this vector to the given vector.
Definition Vector3.cpp:150
Vector3 operator/=(float f)
Definition Vector3.cpp:139
Vector3 operator+(const Vector3 &v) const
Add a vector to this vector.
Definition Vector3.cpp:108
static const Vector3 up
A normalized up-oriented vector.
Definition Vector3.h:77
static const Vector3 zero
A vector with zero for all axis.
Definition Vector3.h:65
static float SignedAngle(const Vector3 &v1, const Vector3 &v2, const Vector3 &axis)
The signed angle between two vectors.
Definition Vector3.cpp:200
static Vector3 Cross(const Vector3 &v1, const Vector3 &v2)
The cross product of two vectors.
Definition Vector3.cpp:158
static const Vector3 forward
A normalized forward-oriented vector.
Definition Vector3.h:69
friend Vector3 operator/(float f, const Vector3 &v)
Vector3 operator*=(float f)
Definition Vector3.cpp:127
static Vector3 ProjectOnPlane(const Vector3 &v, const Vector3 &n)
Project the vector on a plane defined by a normal orthogonal to the plane.
Definition Vector3.cpp:174
static const Vector3 down
A normalized down-oriented vector.
Definition Vector3.h:79
float sqrMagnitude() const
The squared vector length.
Definition Vector3.cpp:76
float Up() const
Definition Vector3.h:83
Vector3 operator-() const
Negate te vector such that it points in the opposite direction.
Definition Vector3.cpp:95
static float Magnitude(const Vector3 &v)
The vector length.
Definition Vector3.cpp:68
friend Vector3 operator/(const Vector3 &v, float f)
Scale the vector uniformly down.
static Vector3 Project(const Vector3 &v, const Vector3 &n)
Project the vector on another vector.
Definition Vector3.cpp:163
Vector3 operator-=(const Vector3 &v)
Definition Vector3.cpp:102
static const Vector3 right
A normalized right-oriented vector.
Definition Vector3.h:73
static Vector3 Scale(const Vector3 &v1, const Vector3 &v2)
Scale the vector using another vector.
Definition Vector3.cpp:118
friend Vector3 operator*(float f, const Vector3 &v)