aboutsummaryrefslogtreecommitdiff
path: root/dep/src/g3dlite/Plane.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dep/src/g3dlite/Plane.cpp')
-rw-r--r--dep/src/g3dlite/Plane.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/dep/src/g3dlite/Plane.cpp b/dep/src/g3dlite/Plane.cpp
index 5ae60b0f762..9b7991c0333 100644
--- a/dep/src/g3dlite/Plane.cpp
+++ b/dep/src/g3dlite/Plane.cpp
@@ -1,33 +1,51 @@
/**
@file Plane.cpp
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
+
+ @maintainer Morgan McGuire, http://graphics.cs.williams.edu
+
@created 2003-02-06
@edited 2006-01-29
*/
#include "G3D/platform.h"
-#include "G3D/format.h"
#include "G3D/Plane.h"
+#include "G3D/BinaryOutput.h"
+#include "G3D/BinaryInput.h"
#include "G3D/stringutils.h"
namespace G3D {
+Plane::Plane(class BinaryInput& b) {
+ deserialize(b);
+}
+
+
+void Plane::serialize(class BinaryOutput& b) const {
+ _normal.serialize(b);
+ b.writeFloat64(_distance);
+}
+
+
+void Plane::deserialize(class BinaryInput& b) {
+ _normal.deserialize(b);
+ _distance = (float)b.readFloat64();
+}
+
+
Plane::Plane(
Vector4 point0,
Vector4 point1,
Vector4 point2) {
debugAssertM(
- point0.w != 0 ||
- point1.w != 0 ||
+ 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) &&
+ while ((point0.w == 0) &&
((point1.w == 0) || (point2.w != 0))) {
Vector4 temp = point0;
point0 = point1;
@@ -60,6 +78,7 @@ Plane::Plane(
_distance = _normal.dot(point0.xyz());
}
+
Plane::Plane(
const Vector3& point0,
const Vector3& point1,
@@ -69,14 +88,16 @@ Plane::Plane(
_distance = _normal.dot(point0);
}
+
Plane::Plane(
const Vector3& __normal,
const Vector3& point) {
- _normal = __normal.direction();
+ _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();
@@ -85,11 +106,13 @@ 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);
@@ -101,6 +124,7 @@ void Plane::getEquation(Vector3& n, double& d) const {
d = -_distance;
}
+
void Plane::getEquation(float& a, float& b, float& c, float& d) const {
double _a, _b, _c, _d;
getEquation(_a, _b, _c, _d);
@@ -117,9 +141,9 @@ 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);
}
}
-