aboutsummaryrefslogtreecommitdiff
path: root/dep/include/g3dlite/G3D/Triangle.h
diff options
context:
space:
mode:
authorclick <none@none>2010-06-05 00:59:25 +0200
committerclick <none@none>2010-06-05 00:59:25 +0200
commite77716188861d4aa83b227a90e04a66b63baeb1f (patch)
treece72764181a760314ec851f7535052dcf75649db /dep/include/g3dlite/G3D/Triangle.h
parent1426c2970f42a2d065198806f750bf5dd28d580b (diff)
HIGHLY EXPERIMENTAL - USE AT YOUR OWN RISK
Implement the use of the new vmap3-format by Lynx3d (mad props to you for this, and thanks for the talks earlier) + reduced Vmap size to less than one third, and improve precision + indoor/outdoor check which allows automatic unmounting of players + additional area information from WMOAreaTable.dbc, removed existing "hacks" + WMO liquid information for swimming and fishing correctly in buildings/cities/caves/instances (lava and slime WILL hurt from now on!) - buildfiles for windows are not properly done, and will need to be sorted out NOTE: Do NOT annoy Lynx3d about this, any issues with this "port" is entirely our fault ! THIS REVISION IS CONSIDERED UNSTABLE AND CONTAINS WORK IN PROGRESS - USE AT YOUR OWN RISK! --HG-- branch : trunk
Diffstat (limited to 'dep/include/g3dlite/G3D/Triangle.h')
-rw-r--r--dep/include/g3dlite/G3D/Triangle.h79
1 files changed, 61 insertions, 18 deletions
diff --git a/dep/include/g3dlite/G3D/Triangle.h b/dep/include/g3dlite/G3D/Triangle.h
index 6852dac9492..590dbaad946 100644
--- a/dep/include/g3dlite/G3D/Triangle.h
+++ b/dep/include/g3dlite/G3D/Triangle.h
@@ -1,14 +1,14 @@
/**
@file Triangle.h
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
+
+ @maintainer Morgan McGuire, http://graphics.cs.williams.edu
+
@created 2003-04-05
- @edited 2004-03-14
+ @edited 2008-10-06
@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.
+ Copyright 2000-2009, Morgan McGuire.
All rights reserved.
*/
@@ -19,6 +19,8 @@
#include "G3D/g3dmath.h"
#include "G3D/Vector3.h"
#include "G3D/Plane.h"
+#include "G3D/BoundsTrait.h"
+#include "G3D/debugAssert.h"
#include <string>
namespace G3D {
@@ -38,25 +40,30 @@ private:
/** edgeDirection[i] is the normalized vector v[i+1] - v[i] */
Vector3 edgeDirection[3];
- double edgeMagnitude[3];
+ float edgeMagnitude[3];
Plane _plane;
Vector3::Axis _primaryAxis;
/** vertex[1] - vertex[0] */
- Vector3 edge01;
+ Vector3 _edge01;
+
/** vertex[2] - vertex[0] */
- Vector3 edge02;
+ Vector3 _edge02;
float _area;
void init(const Vector3& v0, const Vector3& v1, const Vector3& v2);
public:
+
+ Triangle(class BinaryInput& b);
+ void serialize(class BinaryOutput& b);
+ void deserialize(class BinaryInput& b);
Triangle();
-
+
Triangle(const Vector3& v0, const Vector3& v1, const Vector3& v2);
-
+
~Triangle();
/** 0, 1, or 2 */
@@ -65,7 +72,17 @@ public:
return _vertex[n];
}
- double area() const;
+ /** vertex[1] - vertex[0] */
+ inline const Vector3& edge01() const {
+ return _edge01;
+ }
+
+ /** vertex[2] - vertex[0] */
+ inline const Vector3& edge02() const {
+ return _edge02;
+ }
+
+ float area() const;
Vector3::Axis primaryAxis() const {
return _primaryAxis;
@@ -81,6 +98,13 @@ public:
/** Returns a random point in the triangle. */
Vector3 randomPoint() const;
+ inline void getRandomSurfacePoint
+ (Vector3& P,
+ Vector3& N = Vector3::ignore()) const {
+ P = randomPoint();
+ N = normal();
+ }
+
/**
For two triangles to be equal they must have
the same vertices <I>in the same order</I>.
@@ -96,22 +120,41 @@ public:
return true;
}
- inline unsigned int hashCode() const {
+ inline size_t hashCode() const {
return
_vertex[0].hashCode() +
(_vertex[1].hashCode() >> 2) +
- _vertex[2].hashCode();
+ (_vertex[2].hashCode() >> 3);
}
void getBounds(class AABox&) const;
+ /**
+ @brief Intersect the ray at distance less than @a distance.
+
+ @param distance Set to the maximum distance (can be G3D::inf())
+ to search for an intersection. On return, this is the smaller
+ of the distance to the intersection, if one exists, and the original
+ value.
+
+ @param baryCoord If a triangle is hit before @a distance, a
+ the barycentric coordinates of the hit location on the triangle.
+ Otherwise, unmodified.
+
+ @return True if there was an intersection before the original distance.
+ */
+ bool intersect(const class Ray& ray, float& distance, float baryCoord[3]) const;
+};
+
+} // namespace G3D
+
+template <> struct HashTrait<G3D::Triangle> {
+ static size_t hashCode(const G3D::Triangle& key) { return key.hashCode(); }
};
-} // namespace
-inline unsigned int hashCode(const G3D::Triangle& t) {
- return t.hashCode();
-}
+template<> struct BoundsTrait<class G3D::Triangle> {
+ static void getBounds(const G3D::Triangle& t, G3D::AABox& out) { t.getBounds(out); }
+};
#endif
-