Cafu Engine
ClipWorld.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_CLIPSYS_CLIPWORLD_HPP_INCLUDED
8 #define CAFU_CLIPSYS_CLIPWORLD_HPP_INCLUDED
9 
10 #include "Math3D/BoundingBox.hpp"
11 
12 
13 namespace cf
14 {
15  namespace ClipSys
16  {
17  class ClipModelT;
18  class ClipSectorT;
19  class CollisionModelT;
20  struct TraceResultT;
21  struct WorldTraceResultT;
22  class TraceSolidT;
23 
24 
25  /// The clip world manages all the clip models that exist in a world (their "union").
26  /// This is done in a very efficient manner, even if clip models change (i.e. move, rotate, morph (update geometry) etc.) over time.
27  class ClipWorldT
28  {
29  public:
30 
31  /// The constructor.
32  ClipWorldT(const CollisionModelT* WorldCollMdl_);
33 
34  /// The destructor.
35  ~ClipWorldT();
36 
37  /// Traces the given convex solid from Start along Ray (up to the input value of Result.Fraction) through the clip world,
38  /// and reports the first collision, if any.
39  /// @param TraceSolid The convex solid to trace through the world.
40  /// @param Start The start point in world space where the trace begins.
41  /// @param Ray The ray along which the trace is performed. Note that with F being the input value of Result.Fraction, the endpoint is at Start+Ray*F.
42  /// @param ClipMask Only surfaces whose clip flags match this mask participate in the test. This is for optimization, because it allows the implementation to cull surfaces that are not of interest early.
43  /// @param Ignore A clip model that is to be ignored during the trace, even if the content mask matches.
44  /// This is normally used to "hide" the clip model from which the trace emanates in order to prevent it colliding with itself.
45  /// @param Result The start value of Fraction is input via this reference, and the result of the trace returned.
46  /// Using an input/output parameter for returning the result, rather than a true return type, suggests itself because it makes
47  /// cascaded calls to this function natural (i.e. from (possibly many) super-objects and to (possibly many) sub-objects).
48  /// @param HitClipModel A pointer to the clip model instance with which the reported collision occurred, or NULL if there was no collision.
49  /// @see TraceResultT
50  void TraceConvexSolid(const TraceSolidT& TraceSolid, const Vector3dT& Start, const Vector3dT& Ray,
51  unsigned long ClipMask, const ClipModelT* Ignore, TraceResultT& Result, ClipModelT** HitClipModel = NULL) const;
52 
53  /// Determines the set of clip models that touch a given bounding-box and meet a given contents mask.
54  ///
55  /// @note The return list is always exclusive the world, that is, the world clip model is *never*
56  /// mentioned in the list, even if it meets all criteria otherwise.
57  ///
58  /// @param ClipModels The method returns the found clip models by appending them to this list. Note: The list is *always* exclusive the "world" clip model!
59  /// @param ContentMask The content filter mask; only clip models that meet this content mask are returned.
60  /// @param BB The bounding-box to be queried for clip models.
61  void GetClipModelsFromBB(ArrayT<ClipModelT*>& ClipModels, unsigned long ContentMask, const BoundingBox3dT& BB) const;
62 
63  /// Traces the given convex solid through the clip world.
64  /// The method considers the clip world and all clip models therein, reporting the
65  /// first collision with each, if any, in the order as they were encountered along
66  /// the trace (ordered by increasing `Fraction`).
67  /// This method is intended as a future replacement for the other Trace...()
68  /// methods. For now, see there for further details.
69  void Trace(const TraceSolidT& TraceSolid, const Vector3dT& Start, const Vector3dT& Ray,
70  unsigned long ClipMask, const ClipModelT* Ignore, ArrayT<WorldTraceResultT>& Results) const;
71 
72 
73  private:
74 
75  friend class ClipModelT;
76 
77  // Private interface (also for use by ClipModelT friend class).
78  void GetGridRectFromBB(unsigned long GridRect[], const BoundingBox3dT& BB) const;
79 
80  ClipWorldT(const ClipWorldT&); ///< Use of the Copy Constructor is not allowed.
81  void operator = (const ClipWorldT&); ///< Use of the Assignment Operator is not allowed.
82 
83  const CollisionModelT* WorldCollMdl; ///< The collision model for the world. Never explicitly kept in the Sectors! Should probably be of type ClipModelT though!
84  const BoundingBox3dT WorldBB; ///< The absolute dimensions of the world.
85  const unsigned long SectorSubdivs; ///< The number of clip sectors along each side of the uniform grid.
86  const Vector3dT SectorSideLen; ///< The side lengths of each sector.
87  ClipSectorT* Sectors; ///< The clip sectors that cover the world (as a uniform grid of SectorSubdivs*SectorSubdivs cells).
88  };
89  }
90 }
91 
92 #endif
A clip model represents an object in the world against which clipping queries can be performed...
Definition: ClipModel.hpp:31
This class represents a solid object that can be traced through collision worlds, models and shapes...
Definition: TraceSolid.hpp:30
Definition: ClipWorld_private.hpp:31
void Trace(const TraceSolidT &TraceSolid, const Vector3dT &Start, const Vector3dT &Ray, unsigned long ClipMask, const ClipModelT *Ignore, ArrayT< WorldTraceResultT > &Results) const
Traces the given convex solid through the clip world.
Definition: ClipWorld.cpp:132
~ClipWorldT()
The destructor.
Definition: ClipWorld.cpp:30
This class describes the result of tracing an object (a ray, a bounding-box, or a convex solid) throu...
Definition: TraceResult.hpp:36
ClipWorldT(const CollisionModelT *WorldCollMdl_)
The constructor.
Definition: ClipWorld.cpp:20
This is the base class for collision models, defining their common interface.
Definition: CollisionModel_base.hpp:29
void GetClipModelsFromBB(ArrayT< ClipModelT * > &ClipModels, unsigned long ContentMask, const BoundingBox3dT &BB) const
Determines the set of clip models that touch a given bounding-box and meet a given contents mask...
Definition: ClipWorld.cpp:94
The clip world manages all the clip models that exist in a world (their "union"). ...
Definition: ClipWorld.hpp:27
void TraceConvexSolid(const TraceSolidT &TraceSolid, const Vector3dT &Start, const Vector3dT &Ray, unsigned long ClipMask, const ClipModelT *Ignore, TraceResultT &Result, ClipModelT **HitClipModel=NULL) const
Traces the given convex solid from Start along Ray (up to the input value of Result.Fraction) through the clip world, and reports the first collision, if any.
Definition: ClipWorld.cpp:48
Definition: Renderer.hpp:16