-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector3.cpp
More file actions
72 lines (60 loc) · 1.74 KB
/
vector3.cpp
File metadata and controls
72 lines (60 loc) · 1.74 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
68
69
70
71
72
#include "vector3.h"
#include "point3.h"
libMesh::Vector3 libMesh::Vector3::XAxis = { 1.0f, 0.0f, 0.0f };
libMesh::Vector3 libMesh::Vector3::YAxis = { 0.0f, 1.0f, 0.0f };
libMesh::Vector3 libMesh::Vector3::ZAxis = { 0.0f, 0.0f, 1.0f };
libMesh::Vector3::Vector3() : Vector3(0.0f, 0.0f, 0.0f)
{
}
libMesh::Vector3::Vector3(float x, float y, float z) : x(x), y(y), z(z)
{
}
libMesh::Vector3::Vector3(const Vector3 &other) : x(other.x), y(other.y), z(other.z)
{
}
float libMesh::Vector3::dot(Vector3 other)
{
return x * other.x + y * other.y + z * other.z;
}
libMesh::Vector3 libMesh::Vector3::cross(Vector3 other)
{
auto result = Vector3();
result.x = (y * other.z) - (z * other.y);
result.y = (z * other.x) - (x * other.z);
result.z = (x * other.y) - (y * other.x);
return result;
}
void libMesh::Vector3::transform(Transformation t)
{
float newX = (x * t.m00 + y * t.m10 + z * t.m20) / t.m33;
float newY = (x * t.m01 + y * t.m11 + z * t.m21) / t.m33;
float newZ = (x * t.m02 + y * t.m12 + z * t.m22) / t.m33;
x = newX;
y = newY;
z = newZ;
}
libMesh::Vector3 libMesh::Vector3::transformed(Transformation t)
{
float newX = (x * t.m00 + y * t.m10 + z * t.m20) / t.m33;
float newY = (x * t.m01 + y * t.m11 + z * t.m21) / t.m33;
float newZ = (x * t.m02 + y * t.m12 + z * t.m22) / t.m33;
return Vector3(newX, newY, newZ);
}
void libMesh::Vector3::scale(float value)
{
x *= value;
y *= value;
z *= value;
}
libMesh::Vector3 libMesh::Vector3::scaled(float value)
{
return Vector3(x * value, y * value, z * value);
}
bool libMesh::Vector3::operator==(const Vector3 &other) const
{
return false;
}
bool libMesh::Vector3::operator!=(const Vector3 &other) const
{
return !(*this == other);
}