aboutsummaryrefslogtreecommitdiff
path: root/externals/g3dlite/G3D.lib/source/Triangle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/g3dlite/G3D.lib/source/Triangle.cpp')
-rw-r--r--externals/g3dlite/G3D.lib/source/Triangle.cpp135
1 files changed, 0 insertions, 135 deletions
diff --git a/externals/g3dlite/G3D.lib/source/Triangle.cpp b/externals/g3dlite/G3D.lib/source/Triangle.cpp
deleted file mode 100644
index ad264b1f72a..00000000000
--- a/externals/g3dlite/G3D.lib/source/Triangle.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- @file Triangle.cpp
-
- @maintainer Morgan McGuire, graphics3d.com
-
- @created 2001-04-06
- @edited 2006-01-20
-
- Copyright 2000-2006, Morgan McGuire.
- All rights reserved.
- */
-
-#include "G3D/platform.h"
-#include "G3D/Triangle.h"
-#include "G3D/Plane.h"
-#include "G3D/BinaryInput.h"
-#include "G3D/BinaryOutput.h"
-#include "G3D/debugAssert.h"
-#include "G3D/AABox.h"
-
-namespace G3D {
-
-
-void Triangle::init(const Vector3& v0, const Vector3& v1, const Vector3& v2) {
-
- _plane = Plane(v0, v1, v2);
- _vertex[0] = v0;
- _vertex[1] = v1;
- _vertex[2] = v2;
-
- static int next[] = {1,2,0};
-
- for (int i = 0; i < 3; ++i) {
- const Vector3& e = _vertex[next[i]] - _vertex[i];
- edgeMagnitude[i] = e.magnitude();
-
- if (edgeMagnitude[i] == 0) {
- edgeDirection[i] = Vector3::zero();
- } else {
- edgeDirection[i] = e / (float)edgeMagnitude[i];
- }
- }
-
- _edge01 = _vertex[1] - _vertex[0];
- _edge02 = _vertex[2] - _vertex[0];
-
- _primaryAxis = _plane.normal().primaryAxis();
- _area = 0.5f * edgeDirection[0].cross(edgeDirection[2]).magnitude() * (edgeMagnitude[0] * edgeMagnitude[2]);
- //0.5f * (_vertex[1] - _vertex[0]).cross(_vertex[2] - _vertex[0]).dot(_plane.normal());
-}
-
-
-Triangle::Triangle() {
- init(Vector3::zero(), Vector3::zero(), Vector3::zero());
-}
-
-
-Triangle::Triangle(const Vector3& v0, const Vector3& v1, const Vector3& v2) {
- init(v0, v1, v2);
-}
-
-
-Triangle::~Triangle() {
-}
-
-
-Triangle::Triangle(class BinaryInput& b) {
- deserialize(b);
-}
-
-
-void Triangle::serialize(class BinaryOutput& b) {
- _vertex[0].serialize(b);
- _vertex[1].serialize(b);
- _vertex[2].serialize(b);
-}
-
-
-void Triangle::deserialize(class BinaryInput& b) {
- _vertex[0].deserialize(b);
- _vertex[1].deserialize(b);
- _vertex[2].deserialize(b);
- init(_vertex[0], _vertex[1], _vertex[2]);
-}
-
-
-float Triangle::area() const {
- return _area;
-}
-
-
-const Vector3& Triangle::normal() const {
- return _plane.normal();
-}
-
-
-const Plane& Triangle::plane() const {
- return _plane;
-}
-
-
-Vector3 Triangle::center() const {
- return (_vertex[0] + _vertex[1] + _vertex[2]) / 3.0;
-}
-
-Vector3 Triangle::randomPoint() const {
- // Choose a random point in the parallelogram
-
- float s = uniformRandom();
- float t = uniformRandom();
-
- if (t > 1.0f - s) {
- // Outside the triangle; reflect about the
- // diagonal of the parallelogram
- t = 1.0f - t;
- s = 1.0f - s;
- }
-
- return _edge01 * s + _edge02 * t + _vertex[0];
-}
-
-
-void Triangle::getBounds(AABox& out) const {
- Vector3 lo = _vertex[0];
- Vector3 hi = lo;
-
- for (int i = 1; i < 3; ++i) {
- lo = lo.min(_vertex[i]);
- hi = hi.max(_vertex[i]);
- }
-
- out = AABox(lo, hi);
-}
-
-} // G3D