-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector4.h
More file actions
67 lines (55 loc) · 1.47 KB
/
Vector4.h
File metadata and controls
67 lines (55 loc) · 1.47 KB
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
#pragma once
class Vector4 {
public:
float m_x, m_y, m_z, m_w;
Vector4() : m_x(0), m_y(0), m_z(0), m_w(0) {}
Vector4(float x, float y, float z, float w) : m_x(x), m_y(y), m_z(z), m_w(w) {}
Vector4(const Vector4& copy) { m_x = copy.m_x; m_y = copy.m_y; m_z = copy.m_z; m_w = copy.m_w; }
float getX(void) const { return m_x; }
float getY(void) const { return m_y; }
float getZ(void) const { return m_z; }
float getW(void) const { return m_w; }
Vector4 normalize() {
float length = sqrt(m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w);
return Vector4(m_x / length, m_y / length, m_z / length, m_w / length);
}
float dotProduct(const Vector4& v) const
{
return m_x * v.m_x + m_y * v.m_y + m_z * v.m_z + m_w * v.m_w;
}
inline Vector4 operator + (const Vector4& v) const
{
return Vector4(m_x + v.m_x, m_y + v.m_y, m_z + v.m_z, m_w + v.m_w);
}
inline Vector4 operator - (const Vector4& v) const
{
return Vector4(m_x - v.m_x, m_y - v.m_y, m_z - v.m_z, m_w - v.m_w);
}
inline Vector4 operator * (float f) const
{
return Vector4(m_x * f, m_y * f, m_z * f, m_w * f);
}
inline Vector4 operator / (float f) const
{
return Vector4(m_x / f, m_y / f, m_z / f, m_w / f);
}
void set(int index, float value) {
switch (index)
{
case 0:
m_x = value;
break;
case 1:
m_y = value;
break;
case 2:
m_z = value;
break;
case 3:
m_w = value;
break;
default:
break;
}
}
};