-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vector4.h
98 lines (82 loc) · 1.42 KB
/
Vector4.h
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
#pragma once
#include "Vector3.h"
class Vector4
{
public:
float x, y, z, w;
Vector4()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
w = 0.0f;
}
Vector4(float x, float y, float z, float w)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
Vector4(float* v)
{
x = v[0];
y = v[1];
z = v[2];
w = v[3];
}
Vector4(const float* v)
{
x = v[0];
y = v[1];
z = v[2];
w = v[3];
}
Vector4(const Vector3& v)
{
x = v.x;
y = v.y;
z = v.z;
w = 1.f;
}
inline float& operator[](int i)
{
return ((float*)this)[i];
}
inline float operator[](int i) const
{
return ((float*)this)[i];
}
Vector4 operator*(const Vector4& v)
{
float _w = w * v.w - x * v.x - y * v.y - z * v.z;
float _x = x * v.w + w * v.x + y * v.z - z * v.y;
float _y = y * v.w + w * v.y + z * v.x - x * v.z;
float _z = z * v.w + w * v.z + x * v.y - y * v.x;
return Vector4(_x, _y, _z, _w);
}
Vector4 operator*(const Vector3& v)
{
float _w = -x * v.x - y * v.y - z * v.z;
float _x = w * v.x + y * v.z - z * v.y;
float _y = w * v.y + z * v.x - x * v.z;
float _z = w * v.z + x * v.y - y * v.x;
return Vector4(_x, _y, _z, _w);
}
inline float Dot(const Vector4& v)
{
return x * v.x + y * v.y + z * v.z + w * v.w;
}
inline Vector4 Conjugate() const
{
return Vector4(-x, -y, -z, w);
}
inline Vector3 XYZ() const
{
return Vector3(x, y, z);
}
inline operator __m128() const
{
return *(__m128*)this;
}
};