-
Notifications
You must be signed in to change notification settings - Fork 0
/
VECTOR4D.cpp
89 lines (65 loc) · 1.7 KB
/
VECTOR4D.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
//////////////////////////////////////////////////////////////////////////////////////////
// VECTOR4D.cpp
// Function definitions for 4d vector class
// You may use this code however you wish, but if you do, please credit me and
// provide a link to my website in a readme file or similar
// Downloaded from: www.paulsprojects.net
//////////////////////////////////////////////////////////////////////////////////////////
#include "VECTOR4D.h"
void VECTOR4D::RotateX(double angle)
{
(*this)=GetRotatedX(angle);
}
VECTOR4D VECTOR4D::GetRotatedX(double angle) const
{
VECTOR3D v3d(x, y, z);
v3d.RotateX(angle);
return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
}
void VECTOR4D::RotateY(double angle)
{
(*this)=GetRotatedY(angle);
}
VECTOR4D VECTOR4D::GetRotatedY(double angle) const
{
VECTOR3D v3d(x, y, z);
v3d.RotateY(angle);
return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
}
void VECTOR4D::RotateZ(double angle)
{
(*this)=GetRotatedZ(angle);
}
VECTOR4D VECTOR4D::GetRotatedZ(double angle) const
{
VECTOR3D v3d(x, y, z);
v3d.RotateZ(angle);
return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
}
void VECTOR4D::RotateAxis(double angle, const VECTOR3D & axis)
{
(*this)=GetRotatedAxis(angle, axis);
}
VECTOR4D VECTOR4D::GetRotatedAxis(double angle, const VECTOR3D & axis) const
{
VECTOR3D v3d(x, y, z);
v3d.RotateAxis(angle, axis);
return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
}
VECTOR4D operator*(float scaleFactor, const VECTOR4D & rhs)
{
return rhs*scaleFactor;
}
bool VECTOR4D::operator==(const VECTOR4D & rhs) const
{
if(x==rhs.x && y==rhs.y && z==rhs.z && w==rhs.w)
return true;
return false;
}
VECTOR4D::operator VECTOR3D()
{
if(w==0.0f || w==1.0f)
return VECTOR3D(x, y, z);
else
return VECTOR3D(x/w, y/w, z/w);
}