-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvector4d.cpp
41 lines (30 loc) · 1.22 KB
/
tvector4d.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
#include "tvector4d.h"
TVector4D::TVector4D() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
TVector4D::TVector4D(float x, float y, float z) : x(x), y(y), z(z), w(0.0f) {}
TVector4D::TVector4D(float x, float y, float z, float w)
: x(x), y(y), z(z), w(w) {}
TVector4D::TVector4D(const TVector3D &vector)
: x(vector.x), y(vector.y), z(vector.z), w(0.0f) {}
TVector4D::TVector4D(const TVector3D &vector, float w)
: x(vector.x), y(vector.y), z(vector.z), w(w) {}
TVector4D::TVector4D(const TPoint &p) : x(p.x), y(p.y), z(0.0f), w(0.0f) {}
float TVector4D::length() const {
return std::sqrt(x * x + y * y + z * z + w * w);
}
float TVector4D::lengthSquared() const {
return x * x + y * y + z * z + w * w;
}
bool TVector4D::isCeroVector() const {
return x == 0.0f && y == 0.0f && z == 0.0f && w == 0.0f;
}
TPoint TVector4D::toPoint() const {
return TPoint(static_cast<int>(round(x)),
static_cast<int>(round(y)));
}
float TVector4D::dotProduct(const TVector4D &v1,
const TVector4D &v2) const {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
}
TVector4D TVector4D::normalize() const {
return TVector4D(x / length(), y / length(), z / length(), w / length());
}