Cafu Engine
CollisionModel_base.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_COLLISION_MODEL_BASE_HPP_INCLUDED
8 #define CAFU_CLIPSYS_COLLISION_MODEL_BASE_HPP_INCLUDED
9 
10 #include "Math3D/Vector3.hpp"
11 #include "Math3D/BoundingBox.hpp"
12 
13 
14 class btCollisionShape;
15 
16 
17 namespace cf
18 {
19  namespace SceneGraph { namespace aux { class PoolT; } }
20 
21 
22  namespace ClipSys
23  {
24  struct TraceResultT;
25  class TraceSolidT;
26 
27 
28  /// This is the base class for collision models, defining their common interface.
30  {
31  public:
32 
33  /// The (virtual) destructor.
34  virtual ~CollisionModelT() { }
35 
36  /// Returns the bounding box of this collision model.
37  virtual BoundingBox3dT GetBoundingBox() const = 0;
38 
39  /// Returns the contents of this collision model.
40  virtual unsigned long GetContents() const = 0;
41 
42  /// Saves the model to OutFile.
43  /// TODO: Review serialization/deser. of class hierarchies (e.g. compare to cf::SceneGraph)!
44  /// Right now this is fixed and works for CollisionModelStaticTs only!!!
45  virtual void SaveToFile(std::ostream& OutFile, SceneGraph::aux::PoolT& Pool) const = 0;
46 
47  /// Traces the given TraceSolidT instance from Start along Ray (up to the input value of Result.Fraction)
48  /// through the collision model, and reports the first collision, if any.
49  ///
50  /// @param TraceSolid
51  /// The TraceSolidT instance that is traced from Start along Ray.
52  ///
53  /// @param Start
54  /// The start point in model space where the trace begins.
55  ///
56  /// @param Ray
57  /// 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.
58  ///
59  /// @param ClipMask
60  /// Only surfaces whose clip flags match this mask participate in the test.
61  /// This is for optimization, because it allows the implementation to cull surfaces that are not of interest early.
62  ///
63  /// @param Result
64  /// The start value of Fraction is input via this reference, and the result of the trace returned.
65  /// Using an input/output parameter for returning the result, rather than a true return type, suggests itself because it makes
66  /// cascaded calls to this function natural (i.e. from (possibly many) super-objects and to (possibly many) sub-objects).
67  ///
68  /// @see TraceResultT
69  virtual void TraceConvexSolid(const TraceSolidT& TraceSolid, const Vector3dT& Start, const Vector3dT& Ray, unsigned long ClipMask, TraceResultT& Result) const = 0;
70 
71  /// Determines the volume contents of the model at the given point / in the given box.
72  /// The function considers all brush volumes in the collision model that contain the given point or intersect the given box,
73  /// and returns their combined ("or'ed") contents.
74  /// @param Point The point in model space at which the volume contents of this model is to be determined.
75  /// @param BoxRadius When nonzero, this is the radius of an imaginary box around Point.
76  /// @param ContMask Only volumes whose contents matches this mask participate in the test. This is for optimization, because it allows the implementation to cull volumes that are not of interest early.
77  /// @returns the combined volume content flags of the intersected volumes in the collision model.
78  // If the Point (and thus the associated box) is outside of all volumes, 0 is returned.
79  virtual unsigned long GetContents(const Vector3dT& Point, double BoxRadius, unsigned long ContMask) const = 0;
80 
81  /// Returns an adapter class for using CollisionModelT instances also as Bullet btCollisionShape instances.
82  virtual btCollisionShape* GetBulletAdapter() const = 0;
83  };
84  }
85 }
86 
87 #endif
virtual void SaveToFile(std::ostream &OutFile, SceneGraph::aux::PoolT &Pool) const =0
Saves the model to OutFile.
virtual btCollisionShape * GetBulletAdapter() const =0
Returns an adapter class for using CollisionModelT instances also as Bullet btCollisionShape instance...
Definition: _aux.hpp:111
This class represents a solid object that can be traced through collision worlds, models and shapes...
Definition: TraceSolid.hpp:30
virtual ~CollisionModelT()
The (virtual) destructor.
Definition: CollisionModel_base.hpp:34
virtual void TraceConvexSolid(const TraceSolidT &TraceSolid, const Vector3dT &Start, const Vector3dT &Ray, unsigned long ClipMask, TraceResultT &Result) const =0
Traces the given TraceSolidT instance from Start along Ray (up to the input value of Result...
This class describes the result of tracing an object (a ray, a bounding-box, or a convex solid) throu...
Definition: TraceResult.hpp:36
This is the base class for collision models, defining their common interface.
Definition: CollisionModel_base.hpp:29
virtual BoundingBox3dT GetBoundingBox() const =0
Returns the bounding box of this collision model.
virtual unsigned long GetContents() const =0
Returns the contents of this collision model.