root/trunk/dep/include/g3dlite/G3D/Vector4.inl

Revision 2, 5.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/**
2  @file Vector4.inl
3
4  @maintainer Morgan McGuire, matrix@graphics3d.com
5
6  @created 2002-07-09
7  @edited  2003-02-10
8 */
9
10//----------------------------------------------------------------------------
11
12inline unsigned int hashCode(const G3D::Vector4& v) {
13     return v.hashCode();
14}
15
16namespace G3D {
17
18//----------------------------------------------------------------------------
19inline Vector4::Vector4() {
20    x = y = z = w = 0;
21}
22
23//----------------------------------------------------------------------------
24
25inline Vector4::Vector4 (float fX, float fY, float fZ, float fW) {
26    x = fX;
27    y = fY;
28    z = fZ;
29    w = fW;
30}
31
32//----------------------------------------------------------------------------
33inline Vector4::Vector4 (float afCoordinate[4]) {
34    x = afCoordinate[0];
35    y = afCoordinate[1];
36    z = afCoordinate[2];
37    w = afCoordinate[3];
38}
39
40//----------------------------------------------------------------------------
41inline Vector4::Vector4(const Vector4& rkVector) {
42    x = rkVector.x;
43    y = rkVector.y;
44    z = rkVector.z;
45    w = rkVector.w;
46}
47//----------------------------------------------------------------------------
48inline Vector4::Vector4(const Vector3& rkVector, float fW) {
49    x = rkVector.x;
50    y = rkVector.y;
51    z = rkVector.z;
52    w = fW;
53}
54
55//----------------------------------------------------------------------------
56inline float& Vector4::operator[] (int i) {
57    return ((float*)this)[i];
58}
59
60//----------------------------------------------------------------------------
61inline const float& Vector4::operator[] (int i) const {
62    return ((float*)this)[i];
63}
64
65//----------------------------------------------------------------------------
66inline Vector4::operator float* () {
67    return (float*)this;
68}
69
70inline Vector4::operator const float* () const {
71    return (float*)this;
72}
73
74//----------------------------------------------------------------------------
75inline Vector4& Vector4::operator= (const Vector4& rkVector) {
76    x = rkVector.x;
77    y = rkVector.y;
78    z = rkVector.z;
79    w = rkVector.w;
80    return *this;
81}
82
83//----------------------------------------------------------------------------
84inline bool Vector4::operator== (const Vector4& rkVector) const {
85    return ( (x == rkVector.x) && (y == rkVector.y) && (z == rkVector.z) && (w == rkVector.w));
86}
87
88//----------------------------------------------------------------------------
89inline bool Vector4::operator!= (const Vector4& rkVector) const {
90    return ( x != rkVector.x || y != rkVector.y || z != rkVector.z || w != rkVector.w);
91}
92
93//----------------------------------------------------------------------------
94inline Vector4 Vector4::operator+ (const Vector4& rkVector) const {
95    return Vector4(x + rkVector.x, y + rkVector.y, z + rkVector.z, w + rkVector.w);
96}
97
98//----------------------------------------------------------------------------
99inline Vector4 Vector4::operator- (const Vector4& rkVector) const {
100    return Vector4(x - rkVector.x, y - rkVector.y, z - rkVector.z, w - rkVector.w);
101}
102
103//----------------------------------------------------------------------------
104inline Vector4 Vector4::operator* (float fScalar) const {
105    return Vector4(fScalar*x, fScalar*y, fScalar*z, fScalar*w);
106}
107
108//----------------------------------------------------------------------------
109inline Vector4 Vector4::operator- () const {
110    return Vector4( -x, -y, -z, -w);
111}
112
113//----------------------------------------------------------------------------
114inline Vector4& Vector4::operator+= (const Vector4& rkVector) {
115    x += rkVector.x;
116    y += rkVector.y;
117    z += rkVector.z;
118    w += rkVector.w;
119    return *this;
120}
121
122//----------------------------------------------------------------------------
123inline Vector4& Vector4::operator-= (const Vector4& rkVector) {
124    x -= rkVector.x;
125    y -= rkVector.y;
126    z -= rkVector.z;
127    w -= rkVector.w;
128    return *this;
129}
130
131//----------------------------------------------------------------------------
132
133inline Vector4 Vector4::lerp(const Vector4& v, float alpha) const {
134    return (*this) + (v - *this) * alpha;
135}
136
137
138//----------------------------------------------------------------------------
139inline Vector4& Vector4::operator*= (float fScalar) {
140    x *= fScalar;
141    y *= fScalar;
142    z *= fScalar;
143    w *= fScalar;
144    return *this;
145}
146
147
148//----------------------------------------------------------------------------
149inline float Vector4::dot(const Vector4& rkVector) const {
150    return x*rkVector.x + y*rkVector.y + z*rkVector.z + w*rkVector.w;
151}
152
153//----------------------------------------------------------------------------
154inline Vector4 Vector4::min(const Vector4 &v) const {
155    return Vector4(G3D::min(v.x, x), G3D::min(v.y, y), G3D::min(v.z, z), G3D::min(v.w, w));
156}
157
158//----------------------------------------------------------------------------
159inline Vector4 Vector4::max(const Vector4 &v) const {
160    return Vector4(G3D::max(v.x, x), G3D::max(v.y, y), G3D::max(v.z, z), G3D::max(v.w, w));
161}
162
163//----------------------------------------------------------------------------
164inline bool Vector4::isZero() const {
165    return (x == 0.0f) && (y == 0.0f) && (z == 0.0f) && (w == 0.0f);
166}
167
168//----------------------------------------------------------------------------
169
170inline bool Vector4::isFinite() const {
171    return G3D::isFinite(x) && G3D::isFinite(y) && G3D::isFinite(z) && G3D::isFinite(w);
172}
173
174//----------------------------------------------------------------------------
175
176inline bool Vector4::isUnit() const {
177    return squaredLength() == 1.0;
178}
179
180//----------------------------------------------------------------------------
181
182inline float Vector4::length() const {
183    return sqrtf(squaredLength());
184}
185
186//----------------------------------------------------------------------------
187
188inline float Vector4::squaredLength() const {
189    return x * x + y * y + z * z + w * w;
190}
191
192}
193
Note: See TracBrowser for help on using the browser.