aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/OPCODE/Ice/IceHPoint.h
diff options
context:
space:
mode:
authordan miller2007-10-19 05:24:38 +0000
committerdan miller2007-10-19 05:24:38 +0000
commitf205de7847da7ae1c10212d82e7042d0100b4ce0 (patch)
tree9acc9608a6880502aaeda43af52c33e278e95b9c /libraries/ode-0.9/OPCODE/Ice/IceHPoint.h
parenttrying to fix my screwup part deux (diff)
downloadopensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.zip
opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.gz
opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.bz2
opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.xz
from the start... checking in ode-0.9
Diffstat (limited to 'libraries/ode-0.9/OPCODE/Ice/IceHPoint.h')
-rw-r--r--libraries/ode-0.9/OPCODE/Ice/IceHPoint.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/libraries/ode-0.9/OPCODE/Ice/IceHPoint.h b/libraries/ode-0.9/OPCODE/Ice/IceHPoint.h
new file mode 100644
index 0000000..a3770cd
--- /dev/null
+++ b/libraries/ode-0.9/OPCODE/Ice/IceHPoint.h
@@ -0,0 +1,160 @@
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2/**
3 * Contains code for homogeneous points.
4 * \file IceHPoint.h
5 * \author Pierre Terdiman
6 * \date April, 4, 2000
7 */
8///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
10///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11// Include Guard
12#ifndef __ICEHPOINT_H__
13#define __ICEHPOINT_H__
14
15 class ICEMATHS_API HPoint : public Point
16 {
17 public:
18
19 //! Empty constructor
20 inline_ HPoint() {}
21 //! Constructor from floats
22 inline_ HPoint(float xx, float yy, float zz, float ww=0.0f) : Point(xx, yy, zz), w(ww) {}
23 //! Constructor from array
24 inline_ HPoint(const float f[4]) : Point(f), w(f[3]) {}
25 //! Constructor from a Point
26 inline_ HPoint(const Point& p, float ww=0.0f) : Point(p), w(ww) {}
27 //! Destructor
28 inline_ ~HPoint() {}
29
30 //! Clear the point
31 inline_ HPoint& Zero() { x = y = z = w = 0.0f; return *this; }
32
33 //! Assignment from values
34 inline_ HPoint& Set(float xx, float yy, float zz, float ww ) { x = xx; y = yy; z = zz; w = ww; return *this; }
35 //! Assignment from array
36 inline_ HPoint& Set(const float f[4]) { x = f[X]; y = f[Y]; z = f[Z]; w = f[W]; return *this; }
37 //! Assignment from another h-point
38 inline_ HPoint& Set(const HPoint& src) { x = src.x; y = src.y; z = src.z; w = src.w; return *this; }
39
40 //! Add a vector
41 inline_ HPoint& Add(float xx, float yy, float zz, float ww ) { x += xx; y += yy; z += zz; w += ww; return *this; }
42 //! Add a vector
43 inline_ HPoint& Add(const float f[4]) { x += f[X]; y += f[Y]; z += f[Z]; w += f[W]; return *this; }
44
45 //! Subtract a vector
46 inline_ HPoint& Sub(float xx, float yy, float zz, float ww ) { x -= xx; y -= yy; z -= zz; w -= ww; return *this; }
47 //! Subtract a vector
48 inline_ HPoint& Sub(const float f[4]) { x -= f[X]; y -= f[Y]; z -= f[Z]; w -= f[W]; return *this; }
49
50 //! Multiplies by a scalar
51 inline_ HPoint& Mul(float s) { x *= s; y *= s; z *= s; w *= s; return *this; }
52
53 //! Returns MIN(x, y, z, w);
54 float Min() const { return MIN(x, MIN(y, MIN(z, w))); }
55 //! Returns MAX(x, y, z, w);
56 float Max() const { return MAX(x, MAX(y, MAX(z, w))); }
57 //! Sets each element to be componentwise minimum
58 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; }
59 //! Sets each element to be componentwise maximum
60 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; }
61
62 //! Computes square magnitude
63 inline_ float SquareMagnitude() const { return x*x + y*y + z*z + w*w; }
64 //! Computes magnitude
65 inline_ float Magnitude() const { return sqrtf(x*x + y*y + z*z + w*w); }
66
67 //! Normalize the vector
68 inline_ HPoint& Normalize()
69 {
70 float M = Magnitude();
71 if(M)
72 {
73 M = 1.0f / M;
74 x *= M;
75 y *= M;
76 z *= M;
77 w *= M;
78 }
79 return *this;
80 }
81
82 // Arithmetic operators
83 //! Operator for HPoint Negate = - HPoint;
84 inline_ HPoint operator-() const { return HPoint(-x, -y, -z, -w); }
85
86 //! Operator for HPoint Plus = HPoint + HPoint;
87 inline_ HPoint operator+(const HPoint& p) const { return HPoint(x + p.x, y + p.y, z + p.z, w + p.w); }
88 //! Operator for HPoint Minus = HPoint - HPoint;
89 inline_ HPoint operator-(const HPoint& p) const { return HPoint(x - p.x, y - p.y, z - p.z, w - p.w); }
90
91 //! Operator for HPoint Mul = HPoint * HPoint;
92 inline_ HPoint operator*(const HPoint& p) const { return HPoint(x * p.x, y * p.y, z * p.z, w * p.w); }
93 //! Operator for HPoint Scale = HPoint * float;
94 inline_ HPoint operator*(float s) const { return HPoint(x * s, y * s, z * s, w * s); }
95 //! Operator for HPoint Scale = float * HPoint;
96 inline_ friend HPoint operator*(float s, const HPoint& p) { return HPoint(s * p.x, s * p.y, s * p.z, s * p.w); }
97
98 //! Operator for HPoint Div = HPoint / HPoint;
99 inline_ HPoint operator/(const HPoint& p) const { return HPoint(x / p.x, y / p.y, z / p.z, w / p.w); }
100 //! Operator for HPoint Scale = HPoint / float;
101 inline_ HPoint operator/(float s) const { s = 1.0f / s; return HPoint(x * s, y * s, z * s, w * s); }
102 //! Operator for HPoint Scale = float / HPoint;
103 inline_ friend HPoint operator/(float s, const HPoint& p) { return HPoint(s / p.x, s / p.y, s / p.z, s / p.w); }
104
105 //! Operator for float DotProd = HPoint | HPoint;
106 inline_ float operator|(const HPoint& p) const { return x*p.x + y*p.y + z*p.z + w*p.w; }
107 // No cross-product in 4D
108
109 //! Operator for HPoint += HPoint;
110 inline_ HPoint& operator+=(const HPoint& p) { x += p.x; y += p.y; z += p.z; w += p.w; return *this; }
111 //! Operator for HPoint += float;
112 inline_ HPoint& operator+=(float s) { x += s; y += s; z += s; w += s; return *this; }
113
114 //! Operator for HPoint -= HPoint;
115 inline_ HPoint& operator-=(const HPoint& p) { x -= p.x; y -= p.y; z -= p.z; w -= p.w; return *this; }
116 //! Operator for HPoint -= float;
117 inline_ HPoint& operator-=(float s) { x -= s; y -= s; z -= s; w -= s; return *this; }
118
119 //! Operator for HPoint *= HPoint;
120 inline_ HPoint& operator*=(const HPoint& p) { x *= p.x; y *= p.y; z *= p.z; w *= p.w; return *this; }
121 //! Operator for HPoint *= float;
122 inline_ HPoint& operator*=(float s) { x*=s; y*=s; z*=s; w*=s; return *this; }
123
124 //! Operator for HPoint /= HPoint;
125 inline_ HPoint& operator/=(const HPoint& p) { x /= p.x; y /= p.y; z /= p.z; w /= p.w; return *this; }
126 //! Operator for HPoint /= float;
127 inline_ HPoint& operator/=(float s) { s = 1.0f / s; x*=s; y*=s; z*=s; w*=s; return *this; }
128
129 // Arithmetic operators
130
131 //! Operator for Point Mul = HPoint * Matrix3x3;
132 Point operator*(const Matrix3x3& mat) const;
133 //! Operator for HPoint Mul = HPoint * Matrix4x4;
134 HPoint operator*(const Matrix4x4& mat) const;
135
136 // HPoint *= Matrix3x3 doesn't exist, the matrix is first casted to a 4x4
137 //! Operator for HPoint *= Matrix4x4
138 HPoint& operator*=(const Matrix4x4& mat);
139
140 // Logical operators
141
142 //! Operator for "if(HPoint==HPoint)"
143 inline_ bool operator==(const HPoint& p) const { return ( (x==p.x)&&(y==p.y)&&(z==p.z)&&(w==p.w)); }
144 //! Operator for "if(HPoint!=HPoint)"
145 inline_ bool operator!=(const HPoint& p) const { return ( (x!=p.x)||(y!=p.y)||(z!=p.z)||(w!=p.w)); }
146
147 // Cast operators
148
149 //! Cast a HPoint to a Point. w is discarded.
150#ifdef _MSC_VER
151 inline_ operator Point() const { return Point(x, y, z); }
152 // gcc complains that conversion to a base class will never use a type conversion operator
153#endif
154
155 public:
156 float w;
157 };
158
159#endif // __ICEHPOINT_H__
160