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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Contains code for homogeneous points.
* \file IceHPoint.h
* \author Pierre Terdiman
* \date April, 4, 2000
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __ICEHPOINT_H__
#define __ICEHPOINT_H__
class ICEMATHS_API HPoint : public IcePoint
{
public:
//! Empty constructor
inline_ HPoint() {}
//! Constructor from floats
inline_ HPoint(float _x, float _y, float _z, float _w=0.0f) : IcePoint(_x, _y, _z), w(_w) {}
//! Constructor from array
inline_ HPoint(const float f[4]) : IcePoint(f), w(f[3]) {}
//! Constructor from a IcePoint
inline_ HPoint(const IcePoint& p, float _w=0.0f) : IcePoint(p), w(_w) {}
//! Destructor
inline_ ~HPoint() {}
//! Clear the point
inline_ HPoint& Zero() { x = y = z = w = 0.0f; return *this; }
//! Assignment from values
inline_ HPoint& Set(float _x, float _y, float _z, float _w ) { x = _x; y = _y; z = _z; w = _w; return *this; }
//! Assignment from array
inline_ HPoint& Set(const float f[4]) { x = f[_X]; y = f[_Y]; z = f[_Z]; w = f[_W]; return *this; }
//! Assignment from another h-point
inline_ HPoint& Set(const HPoint& src) { x = src.x; y = src.y; z = src.z; w = src.w; return *this; }
//! Add a vector
inline_ HPoint& Add(float _x, float _y, float _z, float _w ) { x += _x; y += _y; z += _z; w += _w; return *this; }
//! Add a vector
inline_ HPoint& Add(const float f[4]) { x += f[_X]; y += f[_Y]; z += f[_Z]; w += f[_W]; return *this; }
//! Subtract a vector
inline_ HPoint& Sub(float _x, float _y, float _z, float _w ) { x -= _x; y -= _y; z -= _z; w -= _w; return *this; }
//! Subtract a vector
inline_ HPoint& Sub(const float f[4]) { x -= f[_X]; y -= f[_Y]; z -= f[_Z]; w -= f[_W]; return *this; }
//! Multiplies by a scalar
inline_ HPoint& Mul(float s) { x *= s; y *= s; z *= s; w *= s; return *this; }
//! Returns MIN(x, y, z, w);
float Min() const { return MIN(x, MIN(y, MIN(z, w))); }
//! Returns MAX(x, y, z, w);
float Max() const { return MAX(x, MAX(y, MAX(z, w))); }
//! Sets each element to be componentwise minimum
HPoint& Min(const HPoint& p) { x = MIN(x, p.x); y = MIN(y, p.y); z = MIN(z, p.z); w = MIN(w, p.w); return *this; }
//! Sets each element to be componentwise maximum
HPoint& Max(const HPoint& p) { x = MAX(x, p.x); y = MAX(y, p.y); z = MAX(z, p.z); w = MAX(w, p.w); return *this; }
//! Computes square magnitude
inline_ float SquareMagnitude() const { return x*x + y*y + z*z + w*w; }
//! Computes magnitude
inline_ float Magnitude() const { return sqrtf(x*x + y*y + z*z + w*w); }
//! Normalize the vector
inline_ HPoint& Normalize()
{
float M = Magnitude();
if(M)
{
M = 1.0f / M;
x *= M;
y *= M;
z *= M;
w *= M;
}
return *this;
}
// Arithmetic operators
//! Operator for HPoint Negate = - HPoint;
inline_ HPoint operator-() const { return HPoint(-x, -y, -z, -w); }
//! Operator for HPoint Plus = HPoint + HPoint;
inline_ HPoint operator+(const HPoint& p) const { return HPoint(x + p.x, y + p.y, z + p.z, w + p.w); }
//! Operator for HPoint Minus = HPoint - HPoint;
inline_ HPoint operator-(const HPoint& p) const { return HPoint(x - p.x, y - p.y, z - p.z, w - p.w); }
//! Operator for HPoint Mul = HPoint * HPoint;
inline_ HPoint operator*(const HPoint& p) const { return HPoint(x * p.x, y * p.y, z * p.z, w * p.w); }
//! Operator for HPoint Scale = HPoint * float;
inline_ HPoint operator*(float s) const { return HPoint(x * s, y * s, z * s, w * s); }
//! Operator for HPoint Scale = float * HPoint;
inline_ friend HPoint operator*(float s, const HPoint& p) { return HPoint(s * p.x, s * p.y, s * p.z, s * p.w); }
//! Operator for HPoint Div = HPoint / HPoint;
inline_ HPoint operator/(const HPoint& p) const { return HPoint(x / p.x, y / p.y, z / p.z, w / p.w); }
//! Operator for HPoint Scale = HPoint / float;
inline_ HPoint operator/(float s) const { s = 1.0f / s; return HPoint(x * s, y * s, z * s, w * s); }
//! Operator for HPoint Scale = float / HPoint;
inline_ friend HPoint operator/(float s, const HPoint& p) { return HPoint(s / p.x, s / p.y, s / p.z, s / p.w); }
//! Operator for float DotProd = HPoint | HPoint;
inline_ float operator|(const HPoint& p) const { return x*p.x + y*p.y + z*p.z + w*p.w; }
// No cross-product in 4D
//! Operator for HPoint += HPoint;
inline_ HPoint& operator+=(const HPoint& p) { x += p.x; y += p.y; z += p.z; w += p.w; return *this; }
//! Operator for HPoint += float;
inline_ HPoint& operator+=(float s) { x += s; y += s; z += s; w += s; return *this; }
//! Operator for HPoint -= HPoint;
inline_ HPoint& operator-=(const HPoint& p) { x -= p.x; y -= p.y; z -= p.z; w -= p.w; return *this; }
//! Operator for HPoint -= float;
inline_ HPoint& operator-=(float s) { x -= s; y -= s; z -= s; w -= s; return *this; }
//! Operator for HPoint *= HPoint;
inline_ HPoint& operator*=(const HPoint& p) { x *= p.x; y *= p.y; z *= p.z; w *= p.w; return *this; }
//! Operator for HPoint *= float;
inline_ HPoint& operator*=(float s) { x*=s; y*=s; z*=s; w*=s; return *this; }
//! Operator for HPoint /= HPoint;
inline_ HPoint& operator/=(const HPoint& p) { x /= p.x; y /= p.y; z /= p.z; w /= p.w; return *this; }
//! Operator for HPoint /= float;
inline_ HPoint& operator/=(float s) { s = 1.0f / s; x*=s; y*=s; z*=s; w*=s; return *this; }
// Arithmetic operators
//! Operator for IcePoint Mul = HPoint * Matrix3x3;
IcePoint operator*(const Matrix3x3& mat) const;
//! Operator for HPoint Mul = HPoint * Matrix4x4;
HPoint operator*(const Matrix4x4& mat) const;
// HPoint *= Matrix3x3 doesn't exist, the matrix is first casted to a 4x4
//! Operator for HPoint *= Matrix4x4
HPoint& operator*=(const Matrix4x4& mat);
// Logical operators
//! Operator for "if(HPoint==HPoint)"
inline_ bool operator==(const HPoint& p) const { return ( (x==p.x)&&(y==p.y)&&(z==p.z)&&(w==p.w)); }
//! Operator for "if(HPoint!=HPoint)"
inline_ bool operator!=(const HPoint& p) const { return ( (x!=p.x)||(y!=p.y)||(z!=p.z)||(w!=p.w)); }
// Cast operators
//! Cast a HPoint to a IcePoint. w is discarded.
inline_ operator IcePoint() const { return IcePoint(x, y, z); }
public:
float w;
};
#endif // __ICEHPOINT_H__
|