-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVector4.cpp
143 lines (121 loc) · 3.16 KB
/
Vector4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "Vector4.h"
#include "Vector3.h"
#include "Vector2.h"
#include <math.h>
namespace Engine
{
Vector4::Vector4(void)
: X(0.0f), Y(0.0f), Z(0.0f), W(0.0f)
{ }
Vector4::Vector4(float x, float y, float z, float w)
: X(x), Y(y), Z(z), W(w)
{ }
Vector4::Vector4(const Vector2 &vector2)
: X(vector2.X), Y(vector2.Y), Z(0.0f), W(0.0f)
{ }
Vector4::Vector4(const Vector3 &vector3)
: X(vector3.X), Y(vector3.Y), Z(vector3.Z), W(0.0f)
{ }
float Vector4::GetLength(void) const
{
return sqrt(X * X + Y * Y + Z * Z + W * W);
}
float Vector4::GetLengthSquared(void) const
{
return (X * X + Y * Y + Z * Z + W * W);
}
void Vector4::Normalize(void)
{
float length = this->GetLength();
X /= length;
Y /= length;
Z /= length;
W /= length;
}
Vector4 Vector4::operator+(const Vector4 &other) const
{
return Vector4(this->X + other.X,
this->Y + other.Y,
this->Z + other.Z,
this->W + other.W);
}
Vector4 Vector4::operator+=(const Vector4 &other)
{
this->X += other.X;
this->Y += other.Y;
this->Z += other.Z;
this->W += other.W;
return *this;
}
Vector4 Vector4::operator-(const Vector4 &other) const
{
return Vector4(this->X - other.X,
this->Y - other.Y,
this->Z - other.Z,
this->W - other.W);
}
Vector4 Vector4::operator-=(const Vector4 &other)
{
this->X -= other.X;
this->Y -= other.Y;
this->Z -= other.Z;
this->W -= other.W;
return *this;
}
Vector4 Vector4::operator*(float scalar) const
{
return Vector4(this->X * scalar,
this->Y * scalar,
this->Z * scalar,
this->W * scalar);
}
Vector4 Vector4::operator*=(float scalar)
{
this->X *= scalar;
this->Y *= scalar;
this->Z *= scalar;
this->W *= scalar;
return *this;
}
float Vector4::operator*(const Vector4 &other) const
{
return (this->X * other.X +
this->Y * other.Y +
this->Z * other.Z +
this->W * other.W);
}
bool Vector4::operator<(const Vector4 &other) const
{
return (this->X < other.X) && (this->Y < other.Y) && (this->Z < other.Z) && (this->W < other.W);
}
bool Vector4::operator<=(const Vector4 &other) const
{
return (this->X <= other.X) && (this->Y <= other.Y) && (this->Z <= other.Z) && (this->W <= other.W);
}
bool Vector4::operator>(const Vector4 &other) const
{
return (this->X > other.X) && (this->Y > other.Y) && (this->Z > other.Z) && (this->W > other.W);
}
bool Vector4::operator>=(const Vector4 &other) const
{
return (this->X >= other.X) && (this->Y >= other.Y) && (this->Z >= other.Z) && (this->W >= other.W);
}
bool Vector4::operator==(const Vector4 &other) const
{
return (this->X == other.X) && (this->Y == other.Y) && (this->Z == other.Z) && (this->W == other.W);
}
bool Vector4::operator!=(const Vector4 &other) const
{
return (this->X != other.X) || (this->Y != other.Y) || (this->Z != other.Z) || (this->W != other.W);
}
float Vector4::Dot(const Vector4 &left, const Vector4 &right)
{
return left * right;
}
Vector4 Vector4::Normalize(const Vector4 &vector)
{
Vector4 result(vector);
result.Normalize();
return result;
}
}