diff options
author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /dep/include/g3dlite/G3D/Triangle.h | |
parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'dep/include/g3dlite/G3D/Triangle.h')
-rw-r--r-- | dep/include/g3dlite/G3D/Triangle.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dep/include/g3dlite/G3D/Triangle.h b/dep/include/g3dlite/G3D/Triangle.h index 146fa0b6455..6852dac9492 100644 --- a/dep/include/g3dlite/G3D/Triangle.h +++ b/dep/include/g3dlite/G3D/Triangle.h @@ -1,20 +1,28 @@ /** @file Triangle.h + @maintainer Morgan McGuire, matrix@graphics3d.com + @created 2003-04-05 @edited 2004-03-14 + @cite Random point method by Greg Turk, Generating random points in triangles. In A. S. Glassner, ed., Graphics Gems, pp. 24-28. Academic Press, 1990 + Copyright 2000-2006, Morgan McGuire. All rights reserved. */ + #ifndef G3D_TRIANGLE_H #define G3D_TRIANGLE_H + #include "G3D/platform.h" #include "G3D/g3dmath.h" #include "G3D/Vector3.h" #include "G3D/Plane.h" #include <string> + namespace G3D { + /** A generic triangle representation. This should not be used as the underlying triangle for creating models; it is intended @@ -25,37 +33,54 @@ class Triangle { private: friend class CollisionDetection; friend class Ray; + Vector3 _vertex[3]; + /** edgeDirection[i] is the normalized vector v[i+1] - v[i] */ Vector3 edgeDirection[3]; double edgeMagnitude[3]; Plane _plane; Vector3::Axis _primaryAxis; + /** vertex[1] - vertex[0] */ Vector3 edge01; /** vertex[2] - vertex[0] */ Vector3 edge02; + float _area; + void init(const Vector3& v0, const Vector3& v1, const Vector3& v2); + public: + Triangle(); + Triangle(const Vector3& v0, const Vector3& v1, const Vector3& v2); + ~Triangle(); + /** 0, 1, or 2 */ inline const Vector3& vertex(int n) const { debugAssert((n >= 0) && (n < 3)); return _vertex[n]; } + double area() const; + Vector3::Axis primaryAxis() const { return _primaryAxis; } + const Vector3& normal() const; + /** Barycenter */ Vector3 center() const; + const Plane& plane() const; + /** Returns a random point in the triangle. */ Vector3 randomPoint() const; + /** For two triangles to be equal they must have the same vertices <I>in the same order</I>. @@ -67,19 +92,26 @@ public: return false; } } + return true; } + inline unsigned int hashCode() const { return _vertex[0].hashCode() + (_vertex[1].hashCode() >> 2) + _vertex[2].hashCode(); } + void getBounds(class AABox&) const; + }; + } // namespace + inline unsigned int hashCode(const G3D::Triangle& t) { return t.hashCode(); } + #endif |