From: Charles McGarvey Date: Thu, 17 Sep 2009 03:54:12 +0000 (-0600) Subject: miscellaneous cleanup X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=fe9614821670d9affcb68fb3e45723b9d40d0b7e;p=chaz%2Fyoink miscellaneous cleanup --- diff --git a/src/Moof/Aabb.cc b/src/Moof/Aabb.cc index 1fb382f..842d9d8 100644 --- a/src/Moof/Aabb.cc +++ b/src/Moof/Aabb.cc @@ -140,7 +140,7 @@ void Aabb::draw(Scalar alpha) const bool Aabb::isVisible(const Camera& cam) const { - return cam.getFrustum().containsAabb(*this); + return cam.getFrustum().contains(*this); } diff --git a/src/Moof/Frustum.cc b/src/Moof/Frustum.cc index dddbde0..51705f2 100644 --- a/src/Moof/Frustum.cc +++ b/src/Moof/Frustum.cc @@ -60,7 +60,7 @@ void Frustum::init(const Matrix4& modelview, Scalar fovy, Scalar aspect, init(modelview, projection); } -Frustum::Collision Frustum::containsAabb(const Aabb& aabb) const +Frustum::Collision Frustum::contains(const Aabb& aabb) const { Vector3 corners[8]; int nTotalInside = 0; @@ -73,7 +73,7 @@ Frustum::Collision Frustum::containsAabb(const Aabb& aabb) const for (int j = 0; j < 8; ++j) { - if (planes_[i].intersectsPoint(corners[j]) == + if (planes_[i].intersects(corners[j]) == Plane::NEGATIVE) { --nInside; @@ -89,11 +89,11 @@ Frustum::Collision Frustum::containsAabb(const Aabb& aabb) const } -Frustum::Collision Frustum::containsSphere(const Sphere& sphere) const +Frustum::Collision Frustum::contains(const Sphere& sphere) const { for (int i = 0; i < 6; ++i) { - Plane::Halfspace halfspace = planes_[i].intersectsSphere(sphere); + Plane::Halfspace halfspace = planes_[i].intersects(sphere); if (halfspace == Plane::NEGATIVE) return OUTSIDE; else if (halfspace == Plane::INTERSECT) return INTERSECT; diff --git a/src/Moof/Frustum.hh b/src/Moof/Frustum.hh index 4154f14..0d08831 100644 --- a/src/Moof/Frustum.hh +++ b/src/Moof/Frustum.hh @@ -66,8 +66,8 @@ public: void init(const Matrix4& modelview, Scalar fovy, Scalar aspect, Scalar abutting, Scalar distant); - Collision containsAabb(const Aabb& aabb) const; - Collision containsSphere(const Sphere& sphere) const; + Collision contains(const Aabb& aabb) const; + Collision contains(const Sphere& sphere) const; }; diff --git a/src/Moof/Octree.cc b/src/Moof/Octree.cc index bd1b410..9bb04e8 100644 --- a/src/Moof/Octree.cc +++ b/src/Moof/Octree.cc @@ -72,28 +72,28 @@ OctreeNodeP Octree::insert(EntityP entity, OctreeNodeP node) goto done; } - halfspace = xy.intersectsSphere(entity->getSphere()); + halfspace = xy.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = xy.intersectsAabb(entity->getAabb()); + halfspace = xy.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) { Plane xz = node->getAabb().getPlaneXZ(); - halfspace = xz.intersectsSphere(entity->getSphere()); + halfspace = xz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = xz.intersectsAabb(entity->getAabb()); + halfspace = xz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) { Plane yz = node->getAabb().getPlaneYZ(); - halfspace = yz.intersectsSphere(entity->getSphere()); + halfspace = yz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = yz.intersectsAabb(entity->getAabb()); + halfspace = yz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) @@ -108,10 +108,10 @@ OctreeNodeP Octree::insert(EntityP entity, OctreeNodeP node) else if (halfspace == Plane::NEGATIVE) { Plane yz = node->getAabb().getPlaneYZ(); - halfspace = yz.intersectsSphere(entity->getSphere()); + halfspace = yz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = yz.intersectsAabb(entity->getAabb()); + halfspace = yz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) @@ -127,19 +127,19 @@ OctreeNodeP Octree::insert(EntityP entity, OctreeNodeP node) else if (halfspace == Plane::NEGATIVE) { Plane xz = node->getAabb().getPlaneXZ(); - halfspace = xz.intersectsSphere(entity->getSphere()); + halfspace = xz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = xz.intersectsAabb(entity->getAabb()); + halfspace = xz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) { Plane yz = node->getAabb().getPlaneYZ(); - halfspace = yz.intersectsSphere(entity->getSphere()); + halfspace = yz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = yz.intersectsAabb(entity->getAabb()); + halfspace = yz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) @@ -154,10 +154,10 @@ OctreeNodeP Octree::insert(EntityP entity, OctreeNodeP node) else if (halfspace == Plane::NEGATIVE) { Plane yz = node->getAabb().getPlaneYZ(); - halfspace = yz.intersectsSphere(entity->getSphere()); + halfspace = yz.intersects(entity->getSphere()); if (halfspace == Plane::INTERSECT) { - halfspace = yz.intersectsAabb(entity->getAabb()); + halfspace = yz.intersects(entity->getAabb()); } if (halfspace == Plane::POSITIVE) @@ -244,11 +244,11 @@ void Octree::drawIfVisible(Scalar alpha, const Camera& cam, OctreeNodeP node) // try to cull by sphere Frustum::Collision collision = - cam.getFrustum().containsSphere(node->getSphere()); + cam.getFrustum().contains(node->getSphere()); if (collision == Frustum::OUTSIDE) return; // try to cull by aabb - collision = cam.getFrustum().containsAabb(node->getAabb()); + collision = cam.getFrustum().contains(node->getAabb()); if (collision == Frustum::OUTSIDE) return; diff --git a/src/Moof/Plane.cc b/src/Moof/Plane.cc index 975ef13..5390934 100644 --- a/src/Moof/Plane.cc +++ b/src/Moof/Plane.cc @@ -34,7 +34,7 @@ namespace Mf { -Plane::Halfspace Plane::intersectsAabb(const Aabb& aabb) const +Plane::Halfspace Plane::intersects(const Aabb& aabb) const { Vector3 corners[8]; int nPositive = 8; @@ -43,7 +43,7 @@ Plane::Halfspace Plane::intersectsAabb(const Aabb& aabb) const for (int i = 0; i < 8; ++i) { - if (intersectsPoint(corners[i]) == NEGATIVE) + if (intersects(corners[i]) == NEGATIVE) { --nPositive; } @@ -54,7 +54,7 @@ Plane::Halfspace Plane::intersectsAabb(const Aabb& aabb) const else return INTERSECT; } -Plane::Halfspace Plane::intersectsSphere(const Sphere& sphere) const +Plane::Halfspace Plane::intersects(const Sphere& sphere) const { Scalar distance = getDistanceToPoint(sphere.point); diff --git a/src/Moof/Plane.hh b/src/Moof/Plane.hh index 248a312..4739bb8 100644 --- a/src/Moof/Plane.hh +++ b/src/Moof/Plane.hh @@ -39,6 +39,11 @@ class Aabb; class Sphere; +/* + * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, B, C] + * is normal to the plane. + */ + struct Plane { Vector3 normal; @@ -60,6 +65,8 @@ struct Plane d(scalar) {} + /* Causes the normal of the plane to become normalized. The scalar may also + * be changed to keep the equation true. */ void normalize() { Scalar mag = normal.length(); @@ -68,12 +75,15 @@ struct Plane d /= mag; } + /** + * Determine the shortest distance between a point and the plane. */ + inline Scalar getDistanceToPoint(const Vector3& point) const { return cml::dot(point, normal) + d; } - inline Halfspace intersectsPoint(const Vector3& point) const + inline Halfspace intersects(const Vector3& point) const { Scalar distance = getDistanceToPoint(point); @@ -82,8 +92,8 @@ struct Plane else return POSITIVE; } - Halfspace intersectsAabb(const Aabb& aabb) const; - Halfspace intersectsSphere(const Sphere& sphere) const; + Halfspace intersects(const Aabb& aabb) const; + Halfspace intersects(const Sphere& sphere) const; }; diff --git a/src/Moof/Sphere.cc b/src/Moof/Sphere.cc index 352d58d..d8d089d 100644 --- a/src/Moof/Sphere.cc +++ b/src/Moof/Sphere.cc @@ -26,9 +26,9 @@ *******************************************************************************/ -#include -#include -#include +#include "Camera.hh" +#include "OpenGL.hh" +#include "Sphere.hh" namespace Mf { @@ -36,16 +36,17 @@ namespace Mf { void Sphere::encloseVertices(const Vector3 vertices[], unsigned count) { + // TODO } void Sphere::draw(Scalar alpha) const { - + // TODO } bool Sphere::isVisible(const Camera& cam) const { - return cam.getFrustum().containsSphere(*this); + return cam.getFrustum().contains(*this); } diff --git a/src/Moof/Sphere.hh b/src/Moof/Sphere.hh index b20ca74..8a9d5e6 100644 --- a/src/Moof/Sphere.hh +++ b/src/Moof/Sphere.hh @@ -38,7 +38,7 @@ namespace Mf { /** - * Axis-aligned Bounding Box + * A round object. */ struct Sphere : public Cullable, public Drawable