GteIntrRay3Capsule3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
13 
14 // The queries consider the capsule to be a solid.
15 //
16 // The test-intersection queries are based on distance computations.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
22 class TIQuery<Real, Ray3<Real>, Capsule3<Real>>
23 {
24 public:
25  struct Result
26  {
27  bool intersect;
28  };
29 
30  Result operator()(Ray3<Real> const& ray, Capsule3<Real> const& capsule);
31 };
32 
33 template <typename Real>
34 class FIQuery<Real, Ray3<Real>, Capsule3<Real>>
35  :
36  public FIQuery<Real, Line3<Real>, Capsule3<Real>>
37 {
38 public:
39  struct Result
40  :
41  public FIQuery<Real, Line3<Real>, Capsule3<Real>>::Result
42  {
43  // No additional information to compute.
44  };
45 
46  Result operator()(Ray3<Real> const& ray, Capsule3<Real> const& capsule);
47 
48 protected:
49  void DoQuery(Vector3<Real> const& rayOrigin,
50  Vector3<Real> const& rayDirection, Capsule3<Real> const& capsule,
51  Result& result);
52 };
53 
54 
55 template <typename Real>
58  Ray3<Real> const& ray, Capsule3<Real> const& capsule)
59 {
60  Result result;
62  auto rsResult = rsQuery(ray, capsule.segment);
63  result.intersect = (rsResult.distance <= capsule.radius);
64  return result;
65 }
66 
67 template <typename Real>
70  Ray3<Real> const& ray, Capsule3<Real> const& capsule)
71 {
72  Result result;
73  DoQuery(ray.origin, ray.direction, capsule, result);
74  for (int i = 0; i < result.numIntersections; ++i)
75  {
76  result.point[i] = ray.origin + result.parameter[i] * ray.direction;
77  }
78  return result;
79 }
80 
81 template <typename Real>
83  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
84  Capsule3<Real> const& capsule, Result& result)
85 {
86  FIQuery<Real, Line3<Real>, Capsule3<Real>>::DoQuery(rayOrigin,
87  rayDirection, capsule, result);
88 
89  if (result.intersect)
90  {
91  // The line containing the ray intersects the capsule; the t-interval
92  // is [t0,t1]. The ray intersects the capsule as long as [t0,t1]
93  // overlaps the ray t-interval [0,+infinity).
94  std::array<Real, 2> rayInterval =
95  { (Real)0, std::numeric_limits<Real>::max() };
96  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
97  auto iiResult = iiQuery(result.parameter, rayInterval);
98  if (iiResult.intersect)
99  {
100  result.numIntersections = iiResult.numIntersections;
101  result.parameter = iiResult.overlap;
102  }
103  else
104  {
105  result.intersect = false;
106  result.numIntersections = 0;
107  }
108  }
109 }
110 
111 
112 }
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00