~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/WildMagic4/Wm4Vector3.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Wild Magic Source Code
 
2
// David Eberly
 
3
// http://www.geometrictools.com
 
4
// Copyright (c) 1998-2007
 
5
//
 
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.
 
14
//
 
15
// Version: 4.0.2 (2006/07/25)
 
16
 
 
17
#ifndef WM4VECTOR3_H
 
18
#define WM4VECTOR3_H
 
19
 
 
20
#include "Wm4FoundationLIB.h"
 
21
#include "Wm4Math.h"
 
22
 
 
23
namespace Wm4
 
24
{
 
25
 
 
26
template <class Real>
 
27
class Vector3
 
28
{
 
29
public:
 
30
    // construction
 
31
    Vector3 ();  // uninitialized
 
32
    Vector3 (Real fX, Real fY, Real fZ);
 
33
    Vector3 (const Real* afTuple);
 
34
    Vector3 (const Vector3& rkV);
 
35
 
 
36
    // coordinate access
 
37
    operator const Real* () const;
 
38
    operator Real* ();
 
39
    Real operator[] (int i) const;
 
40
    Real& operator[] (int i);
 
41
    Real X () const;
 
42
    Real& X ();
 
43
    Real Y () const;
 
44
    Real& Y ();
 
45
    Real Z () const;
 
46
    Real& Z ();
 
47
 
 
48
    // assignment
 
49
    Vector3& operator= (const Vector3& rkV);
 
50
 
 
51
    // comparison
 
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;
 
58
 
 
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;
 
65
 
 
66
    // arithmetic updates
 
67
    Vector3& operator+= (const Vector3& rkV);
 
68
    Vector3& operator-= (const Vector3& rkV);
 
69
    Vector3& operator*= (Real fScalar);
 
70
    Vector3& operator/= (Real fScalar);
 
71
 
 
72
    // vector operations
 
73
    Real Length () const;
 
74
    Real SquaredLength () const;
 
75
    Real Dot (const Vector3& rkV) const;
 
76
    Real Normalize ();
 
77
 
 
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;
 
85
 
 
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;
 
91
 
 
92
    // Gram-Schmidt orthonormalization.  Take linearly independent vectors
 
93
    // U, V, and W and compute an orthonormal set (unit length, mutually
 
94
    // perpendicular).
 
95
    static void Orthonormalize (Vector3& rkU, Vector3& rkV, Vector3& rkW);
 
96
    static void Orthonormalize (Vector3* akV);
 
97
 
 
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
 
101
    // and V.
 
102
    static void GenerateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
 
103
        Vector3& rkW);
 
104
 
 
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
 
107
    // basis.
 
108
    static void GenerateComplementBasis (Vector3& rkU, Vector3& rkV,
 
109
        const Vector3& rkW);
 
110
 
 
111
    // Compute the extreme values.
 
112
    static void ComputeExtremes (int iVQuantity, const Vector3* akPoint,
 
113
        Vector3& rkMin, Vector3& rkMax);
 
114
 
 
115
    // special vectors
 
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)
 
121
 
 
122
private:
 
123
    // support for comparisons
 
124
    int CompareArrays (const Vector3& rkV) const;
 
125
 
 
126
    Real m_afTuple[3];
 
127
};
 
128
 
 
129
// arithmetic operations
 
130
template <class Real>
 
131
Vector3<Real> operator* (Real fScalar, const Vector3<Real>& rkV);
 
132
 
 
133
// debugging output
 
134
template <class Real>
 
135
std::ostream& operator<< (std::ostream& rkOStr, const Vector3<Real>& rkV);
 
136
 
 
137
#include "Wm4Vector3.inl"
 
138
 
 
139
typedef Vector3<float> Vector3f;
 
140
typedef Vector3<double> Vector3d;
 
141
 
 
142
}
 
143
 
 
144
#endif