Skip to content

Commit 1416b1c

Browse files
committed
Added several intersection tests.
1 parent 6033622 commit 1416b1c

File tree

14 files changed

+57
-18
lines changed

14 files changed

+57
-18
lines changed

src/Geometry/Capsule.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,16 @@ bool Capsule::Intersects(const OBB &obb) const
285285
*/
286286
bool Capsule::Intersects(const Sphere &sphere) const
287287
{
288+
///\todo Optimize to avoid square roots.
288289
return l.Distance(sphere.pos) <= r + sphere.r;
289290
}
291+
292+
bool Capsule::Intersects(const Capsule &capsule) const
293+
{
294+
///\todo Optimize to avoid square roots.
295+
return l.Distance(capsule.l) <= r + capsule.r;
296+
}
297+
290298
/*
291299
bool Capsule::Intersects(const Triangle &triangle) const
292300
{

src/Geometry/Capsule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class Capsule
141141
bool Intersects(const LineSegment &lineSegment) const;
142142
bool Intersects(const Plane &plane) const;
143143
bool Intersects(const Sphere &sphere) const;
144+
bool Intersects(const Capsule &capsule) const;
144145
// bool Intersects(const AABB &aabb) const;
145146
// bool Intersects(const OBB &obb) const;
146147
// bool Intersects(const Triangle &triangle) const;

src/Geometry/Frustum.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ Polyhedron Frustum::ToPolyhedron() const
339339
return Polyhedron();
340340
}
341341
*/
342+
343+
/*
342344
bool Frustum::Intersects(const Ray &ray, float &outDistance) const
343345
{
344346
assume(false && "Not implemented!");
@@ -368,13 +370,12 @@ bool Frustum::Intersects(const OBB &obb) const
368370
assume(false && "Not implemented!");
369371
return false;
370372
}
371-
373+
*/
372374
bool Frustum::Intersects(const Plane &plane) const
373375
{
374-
assume(false && "Not implemented!");
375-
return false;
376+
return plane.Intersects(*this);
376377
}
377-
378+
/*
378379
bool Frustum::Intersects(const Sphere &sphere) const
379380
{
380381
assume(false && "Not implemented!");
@@ -416,7 +417,7 @@ bool Frustum::Intersects(const Polyhedron &polyhedron) const
416417
assume(false && "Not implemented!");
417418
return false;
418419
}
419-
420+
*/
420421
#ifdef MATH_ENABLE_STL_SUPPORT
421422

422423
std::string FrustumTypeToString(FrustumType t)

src/Geometry/Frustum.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,19 @@ class Frustum
175175

176176
/// \todo Instead of returning a bool, return a value that specifies if the object lies completely
177177
/// on the negative or positive halfspace.
178-
bool Intersects(const Ray &ray, float &outDistance) const;
179-
bool Intersects(const Line &line, float &outDistance) const;
180-
bool Intersects(const LineSegment &lineSegment, float &outDistance) const;
181-
bool Intersects(const AABB &aabb) const;
182-
bool Intersects(const OBB &obb) const;
178+
// bool Intersects(const Ray &ray, float &outDistance) const;
179+
// bool Intersects(const Line &line, float &outDistance) const;
180+
// bool Intersects(const LineSegment &lineSegment, float &outDistance) const;
181+
// bool Intersects(const AABB &aabb) const;
182+
// bool Intersects(const OBB &obb) const;
183183
bool Intersects(const Plane &plane) const;
184-
bool Intersects(const Sphere &sphere) const;
185-
bool Intersects(const Ellipsoid &ellipsoid) const;
186-
bool Intersects(const Triangle &triangle) const;
187-
bool Intersects(const Cylinder &cylinder) const;
188-
bool Intersects(const Torus &torus) const;
189-
bool Intersects(const Frustum &frustum) const;
190-
bool Intersects(const Polyhedron &polyhedron) const;
184+
// bool Intersects(const Sphere &sphere) const;
185+
// bool Intersects(const Ellipsoid &ellipsoid) const;
186+
// bool Intersects(const Triangle &triangle) const;
187+
// bool Intersects(const Cylinder &cylinder) const;
188+
// bool Intersects(const Torus &torus) const;
189+
// bool Intersects(const Frustum &frustum) const;
190+
// bool Intersects(const Polyhedron &polyhedron) const;
191191

192192
#ifdef MATH_ENABLE_STL_SUPPORT
193193
/// Returns a human-readable representation of this Frustum. Most useful for debugging purposes.

src/Geometry/Line.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ bool Line::Intersects(const OBB &obb, float *dNear, float *dFar) const
205205
return obb.Intersects(*this, dNear, dFar);
206206
}
207207

208+
bool Line::Intersects(const Capsule &capsule) const
209+
{
210+
return capsule.Intersects(*this);
211+
}
212+
208213
float3 Line::ClosestPoint(const float3 &targetPoint, float *d) const
209214
{
210215
float u = Dot(targetPoint - pos, dir);

src/Geometry/Line.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ class Line
6565
float Distance(const Sphere &other) const;
6666
float Distance(const Capsule &other) const;
6767

68-
6968
bool Intersects(const Triangle &triangle, float *d, float3 *intersectionPoint) const;
7069
bool Intersects(const Plane &plane, float *d) const;
7170
bool Intersects(const Sphere &s, float3 *intersectionPoint = 0, float3 *intersectionNormal = 0, float *d = 0) const;
7271
bool Intersects(const AABB &aabb, float *dNear, float *dFar) const;
7372
bool Intersects(const OBB &obb, float *dNear, float *dFar) const;
73+
bool Intersects(const Capsule &capsule) const;
7474

7575
/// Returns the closest point on <b>this</b> line to the given object.
7676
float3 ClosestPoint(const float3 &targetPoint, float *d = 0) const;

src/Geometry/LineSegment.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ bool LineSegment::Intersects(const Plane &plane) const
227227
return d * d2 <= 0.f;
228228
}
229229

230+
bool LineSegment::Intersects(const Capsule &capsule) const
231+
{
232+
return capsule.Intersects(*this);
233+
}
234+
230235
bool LineSegment::Intersects(const Plane &plane, float *d) const
231236
{
232237
return plane.Intersects(*this, d);

src/Geometry/LineSegment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class LineSegment
9393
bool Intersects(const Sphere &s, float3 *intersectionPoint = 0, float3 *intersectionNormal = 0, float *d = 0) const;
9494
bool Intersects(const AABB &aabb, float *dNear = 0, float *dFar = 0) const;
9595
bool Intersects(const OBB &obb, float *dNear, float *dFar) const;
96+
bool Intersects(const Capsule &capsule) const;
9697

9798
///\todo Implement.
9899
// bool Intersect(const Frustum &frustum) const;

src/Geometry/Plane.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ bool Plane::Intersects(const Sphere &sphere) const
405405
return Distance(sphere.pos) <= sphere.r;
406406
}
407407

408+
bool Plane::Intersects(const Capsule &capsule) const
409+
{
410+
return capsule.Intersects(*this);
411+
}
412+
408413
/// Set Christer Ericson's Real-Time Collision Detection, p.164.
409414
bool Plane::Intersects(const AABB &aabb) const
410415
{

src/Geometry/Plane.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class Plane
158158
bool Intersects(const OBB &obb) const;
159159
bool Intersects(const Triangle &triangle) const;
160160
bool Intersects(const Frustum &frustum) const;
161+
bool Intersects(const Capsule &capsule) const;
161162
// bool Intersect(const Polyhedron &polyhedron) const;
162163

163164
/// Clips a line segment against this plane.

0 commit comments

Comments
 (0)