aboutsummaryrefslogtreecommitdiff
path: root/dep/src/g3dlite/Plane.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /dep/src/g3dlite/Plane.cpp
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'dep/src/g3dlite/Plane.cpp')
-rw-r--r--dep/src/g3dlite/Plane.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/dep/src/g3dlite/Plane.cpp b/dep/src/g3dlite/Plane.cpp
index 86ca12c934b..10ee7ff0f0c 100644
--- a/dep/src/g3dlite/Plane.cpp
+++ b/dep/src/g3dlite/Plane.cpp
@@ -1,24 +1,32 @@
/**
@file Plane.cpp
+
@maintainer Morgan McGuire, matrix@graphics3d.com
+
@created 2003-02-06
@edited 2006-01-29
*/
+
#include "G3D/platform.h"
#include "G3D/format.h"
#include "G3D/Plane.h"
#include "G3D/stringutils.h"
+
namespace G3D {
+
Plane::Plane(
Vector4 point0,
Vector4 point1,
Vector4 point2) {
+
debugAssertM(
point0.w != 0 ||
point1.w != 0 ||
point2.w != 0,
"At least one point must be finite.");
+
// Rotate the points around so that the finite points come first.
+
while ((point0.w == 0) &&
((point1.w == 0) || (point2.w != 0))) {
Vector4 temp = point0;
@@ -26,8 +34,10 @@ Plane::Plane(
point1 = point2;
point2 = temp;
}
+
Vector3 dir1;
Vector3 dir2;
+
if (point1.w == 0) {
// 1 finite, 2 infinite points; the plane must contain
// the direction of the two direcitons
@@ -45,25 +55,31 @@ Plane::Plane(
dir1 = point1.xyz() - point0.xyz();
dir2 = point2.xyz();
}
+
_normal = dir1.cross(dir2).direction();
_distance = _normal.dot(point0.xyz());
}
+
Plane::Plane(
const Vector3& point0,
const Vector3& point1,
const Vector3& point2) {
+
_normal = (point1 - point0).cross(point2 - point0).direction();
_distance = _normal.dot(point0);
}
+
Plane::Plane(
const Vector3& __normal,
const Vector3& point) {
+
_normal = __normal.direction();
_distance = _normal.dot(point);
}
+
Plane Plane::fromEquation(float a, float b, float c, float d) {
Vector3 n(a, b, c);
float magnitude = n.magnitude();
@@ -72,21 +88,25 @@ Plane Plane::fromEquation(float a, float b, float c, float d) {
return Plane(n, -d);
}
+
void Plane::flip() {
_normal = -_normal;
_distance = -_distance;
}
+
void Plane::getEquation(Vector3& n, float& d) const {
double _d;
getEquation(n, _d);
d = (float)_d;
}
+
void Plane::getEquation(Vector3& n, double& d) const {
n = _normal;
d = -_distance;
}
+
void Plane::getEquation(float& a, float& b, float& c, float& d) const {
double _a, _b, _c, _d;
getEquation(_a, _b, _c, _d);
@@ -95,6 +115,7 @@ void Plane::getEquation(float& a, float& b, float& c, float& d) const {
c = (float)_c;
d = (float)_d;
}
+
void Plane::getEquation(double& a, double& b, double& c, double& d) const {
a = _normal.x;
b = _normal.y;
@@ -102,8 +123,10 @@ void Plane::getEquation(double& a, double& b, double& c, double& d) const {
d = -_distance;
}
+
std::string Plane::toString() const {
return format("Plane(%g, %g, %g, %g)", _normal.x, _normal.y, _normal.z, _distance);
}
+
}