1
// Wild Magic Source Code
3
// http://www.geometrictools.com
4
// Copyright (c) 1998-2007
6
// This library is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License as published by
8
// the Free Software Foundation; either version 2.1 of the License, or (at
9
// your option) any later version. The license is available for reading at
10
// either of the locations:
11
// http://www.gnu.org/copyleft/lgpl.html
12
// http://www.geometrictools.com/License/WildMagicLicense.pdf
13
// The license applies to versions 0 through 4 of Wild Magic.
15
// Version: 4.0.2 (2006/07/25)
20
#include "Wm4FoundationLIB.h"
31
Vector3 (); // uninitialized
32
Vector3 (Real fX, Real fY, Real fZ);
33
Vector3 (const Real* afTuple);
34
Vector3 (const Vector3& rkV);
37
operator const Real* () const;
39
Real operator[] (int i) const;
40
Real& operator[] (int i);
49
Vector3& operator= (const Vector3& rkV);
52
bool operator== (const Vector3& rkV) const;
53
bool operator!= (const Vector3& rkV) const;
54
bool operator< (const Vector3& rkV) const;
55
bool operator<= (const Vector3& rkV) const;
56
bool operator> (const Vector3& rkV) const;
57
bool operator>= (const Vector3& rkV) const;
59
// arithmetic operations
60
Vector3 operator+ (const Vector3& rkV) const;
61
Vector3 operator- (const Vector3& rkV) const;
62
Vector3 operator* (Real fScalar) const;
63
Vector3 operator/ (Real fScalar) const;
64
Vector3 operator- () const;
67
Vector3& operator+= (const Vector3& rkV);
68
Vector3& operator-= (const Vector3& rkV);
69
Vector3& operator*= (Real fScalar);
70
Vector3& operator/= (Real fScalar);
74
Real SquaredLength () const;
75
Real Dot (const Vector3& rkV) const;
78
// The cross products are computed using the right-handed rule. Be aware
79
// that some graphics APIs use a left-handed rule. If you have to compute
80
// a cross product with these functions and send the result to the API
81
// that expects left-handed, you will need to change sign on the vector
82
// (replace each component value c by -c).
83
Vector3 Cross (const Vector3& rkV) const;
84
Vector3 UnitCross (const Vector3& rkV) const;
86
// Compute the barycentric coordinates of the point with respect to the
87
// tetrahedron <V0,V1,V2,V3>, P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where
88
// b0 + b1 + b2 + b3 = 1.
89
void GetBarycentrics (const Vector3& rkV0, const Vector3& rkV1,
90
const Vector3& rkV2, const Vector3& rkV3, Real afBary[4]) const;
92
// Gram-Schmidt orthonormalization. Take linearly independent vectors
93
// U, V, and W and compute an orthonormal set (unit length, mutually
95
static void Orthonormalize (Vector3& rkU, Vector3& rkV, Vector3& rkW);
96
static void Orthonormalize (Vector3* akV);
98
// Input W must be a nonzero vector. The output is an orthonormal basis
99
// {U,V,W}. The input W is normalized by this function. If you know
100
// W is already unit length, use GenerateComplementBasis to compute U
102
static void GenerateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
105
// Input W must be a unit-length vector. The output vectors {U,V} are
106
// unit length and mutually perpendicular, and {U,V,W} is an orthonormal
108
static void GenerateComplementBasis (Vector3& rkU, Vector3& rkV,
111
// Compute the extreme values.
112
static void ComputeExtremes (int iVQuantity, const Vector3* akPoint,
113
Vector3& rkMin, Vector3& rkMax);
116
WM4_FOUNDATION_ITEM static const Vector3 ZERO; // (0,0,0)
117
WM4_FOUNDATION_ITEM static const Vector3 UNIT_X; // (1,0,0)
118
WM4_FOUNDATION_ITEM static const Vector3 UNIT_Y; // (0,1,0)
119
WM4_FOUNDATION_ITEM static const Vector3 UNIT_Z; // (0,0,1)
120
WM4_FOUNDATION_ITEM static const Vector3 ONE; // (1,1,1)
123
// support for comparisons
124
int CompareArrays (const Vector3& rkV) const;
129
// arithmetic operations
130
template <class Real>
131
Vector3<Real> operator* (Real fScalar, const Vector3<Real>& rkV);
134
template <class Real>
135
std::ostream& operator<< (std::ostream& rkOStr, const Vector3<Real>& rkV);
137
#include "Wm4Vector3.inl"
139
typedef Vector3<float> Vector3f;
140
typedef Vector3<double> Vector3d;