-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vector.cpp
151 lines (133 loc) · 3.4 KB
/
Vector.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
144
145
146
147
148
149
150
151
#include <math.h>
#include "Vector.h"
namespace juzutil
{
//////////////////////////////////////////////////////////////////////////
//
// VECTOR2
//
//////////////////////////////////////////////////////////////////////////
Vector2::Vector2(const Vector3& vec)
{
m_x = vec.GetX(); m_y = vec.GetY();
}
float Vector2::Size() const
{
return sqrt(m_x * m_x + m_y * m_y);
}
bool Vector2::Equals(const Vector2& vec, float e) const
{
if(fabsf(m_x - vec.m_x) > e)
{
return false;
}
if(fabsf(m_y - vec.m_y) > e)
{
return false;
}
return true;
}
const Vector3 Vector3::GetMajorAxis() const
{
float x = fabsf(m_x);
float y = fabsf(m_y);
float z = fabsf(m_z);
if (fabsf(x) >= fabsf(y)) {
if (fabsf(x) >= fabsf(z)) {
return Vector3(1.0f, 0.0f, 0.0f);
} else {
return Vector3(0.0f, 0.0f, 1.0f);
}
} else {
if (fabsf(y) >= fabsf(z)) {
return Vector3(0.0f, 1.0f, 0.0f);
} else {
return Vector3(0.0f, 0.0f, 1.0f);
}
}
}
void Vector2::Round()
{
m_x = floor(m_x + 0.5f);
m_y = floor(m_y + 0.5f);
}
const Vector2 operator*(float scale, const Vector2& vec)
{
return Vector2(scale * vec.m_x, scale * vec.m_y);
}
//////////////////////////////////////////////////////////////////////////
//
// VECTOR3
//
//////////////////////////////////////////////////////////////////////////
float Vector3::Size() const
{
return sqrt(m_x * m_x + m_y * m_y + m_z * m_z);
}
bool Vector3::Equals(const Vector3& vec, float e) const
{
if(fabsf(m_x - vec.m_x) > e)
{
return false;
}
if(fabsf(m_y - vec.m_y) > e)
{
return false;
}
if(fabsf(m_z - vec.m_z) > e)
{
return false;
}
return true;
}
void Vector3::Round()
{
m_x = floor(m_x + 0.5f);
m_y = floor(m_y + 0.5f);
m_z = floor(m_z + 0.5f);
}
const Vector3 operator*(float scale, const Vector3& vec)
{
return Vector3(scale * vec.m_x, scale * vec.m_y, scale * vec.m_z);
}
//////////////////////////////////////////////////////////////////////////
//
// VECTOR3
//
//////////////////////////////////////////////////////////////////////////
float Vector4::Size() const
{
return sqrt(m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w);
}
bool Vector4::Equals(const Vector4& vec, float e) const
{
if(fabsf(m_x - vec.m_x) > e)
{
return false;
}
if(fabsf(m_y - vec.m_y) > e)
{
return false;
}
if(fabsf(m_z - vec.m_z) > e)
{
return false;
}
if(fabsf(m_w - vec.m_w) > e)
{
return false;
}
return true;
}
void Vector4::Round()
{
m_x = floor(m_x + 0.5f);
m_y = floor(m_y + 0.5f);
m_z = floor(m_z + 0.5f);
m_w = floor(m_w + 0.5f);
}
const Vector4 operator*(float scale, const Vector4& vec)
{
return Vector4(scale * vec.m_x, scale * vec.m_y, scale * vec.m_z, scale * vec.m_w);
}
}