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;
for (int j = 0; j < 8; ++j)
{
- if (planes_[i].intersectsPoint(corners[j]) ==
+ if (planes_[i].intersects(corners[j]) ==
Plane::NEGATIVE)
{
--nInside;
}
-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;
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)
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)
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)
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)
// 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;
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;
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();
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);
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;
};