-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vector4f.h
101 lines (74 loc) · 2.4 KB
/
Vector4f.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
99
100
101
#ifndef VECTOR_4F_H
#define VECTOR_4F_H
class Vector2f;
class Vector3f;
class Vector4f
{
public:
Vector4f( float f = 0.f );
Vector4f( float fx, float fy, float fz, float fw );
Vector4f( float buffer[ 4 ] );
Vector4f( const Vector2f& xy, float z, float w );
Vector4f( float x, const Vector2f& yz, float w );
Vector4f( float x, float y, const Vector2f& zw );
Vector4f( const Vector2f& xy, const Vector2f& zw );
Vector4f( const Vector3f& xyz, float w );
Vector4f( float x, const Vector3f& yzw );
// copy constructors
Vector4f( const Vector4f& rv );
// assignment operators
Vector4f& operator = ( const Vector4f& rv );
// no destructor necessary
// returns the ith element
const float& operator [] ( int i ) const;
float& operator [] ( int i );
float& x();
float& y();
float& z();
float& w();
float x() const;
float y() const;
float z() const;
float w() const;
Vector2f xy() const;
Vector2f yz() const;
Vector2f zw() const;
Vector2f wx() const;
Vector3f xyz() const;
Vector3f yzw() const;
Vector3f zwx() const;
Vector3f wxy() const;
Vector3f xyw() const;
Vector3f yzx() const;
Vector3f zwy() const;
Vector3f wxz() const;
float abs() const;
float absSquared() const;
void normalize();
Vector4f normalized() const;
// if v.z != 0, v = v / v.w
void homogenize();
Vector4f homogenized() const;
void negate();
// ---- Utility ----
const float *getElements() const;
void print() const;
static float dot( const Vector4f& v0, const Vector4f& v1 );
static Vector4f lerp( const Vector4f& v0, const Vector4f& v1, float alpha );
private:
float m_elements[ 4 ];
};
// component-wise operators
Vector4f operator + ( const Vector4f& v0, const Vector4f& v1 );
Vector4f operator - ( const Vector4f& v0, const Vector4f& v1 );
Vector4f operator * ( const Vector4f& v0, const Vector4f& v1 );
Vector4f operator / ( const Vector4f& v0, const Vector4f& v1 );
// unary negation
Vector4f operator - ( const Vector4f& v );
// multiply and divide by scalar
Vector4f operator * ( float f, const Vector4f& v );
Vector4f operator * ( const Vector4f& v, float f );
Vector4f operator / ( const Vector4f& v, float f );
bool operator == ( const Vector4f& v0, const Vector4f& v1 );
bool operator != ( const Vector4f& v0, const Vector4f& v1 );
#endif // VECTOR_4F_H