Cafu Engine
CompCollisionModel.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_GAMESYS_COMPONENT_COLLISION_MODEL_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_COLLISION_MODEL_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 #include "Math3D/Quaternion.hpp"
12 
13 
14 namespace cf { namespace ClipSys { class ClipModelT; } }
15 namespace cf { namespace ClipSys { class CollisionModelT; } }
16 
17 
18 namespace cf
19 {
20  namespace GameSys
21  {
22  /// This component adds a collision model to its entity.
24  {
25  public:
26 
27  /// The constructor.
29 
30  /// The copy constructor.
31  /// @param Comp The component to create a copy of.
33 
34  /// The destructor.
36 
37  // Sets the given bounding-box as the collision model.
38  // Instead of loading a collision model from a file, user code can call this method
39  // to set a bounding-box with the given dimensions as the collision model.
40  void SetBoundingBox(const BoundingBox3dT& BB, const char* MatName);
41 
42 
43  // Base class overrides.
45  const char* GetName() const { return "CollisionModel"; }
46  void UpdateDependencies(EntityT* Entity);
47  unsigned int GetEditorColor() const { return 0xAAAAAA; }
48  const cf::ClipSys::ClipModelT* GetClipModel() override { UpdateClipModel(); return m_ClipModel; }
49 
50 
51  // The TypeSys related declarations for this class.
52  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
53  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
54  static const cf::TypeSys::TypeInfoT TypeInfo;
55 
56 
57  protected:
58 
59  // The Lua API methods of this class.
60  static int SetBoundingBox(lua_State* LuaState);
61  static int toString(lua_State* LuaState);
62 
63  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
64  static const char* DocClass;
65  static const cf::TypeSys::MethsDocT DocMethods[];
66  static const cf::TypeSys::VarsDocT DocVars[];
67 
68 
69  private:
70 
71  void DoDeserialize(cf::Network::InStreamT& Stream, bool IsIniting) override;
72  void DoServerFrame(float t) override;
73  void CleanUp();
74  void UpdateClipModel();
75 
76  TypeSys::VarT<std::string> m_CollMdlName; ///< The file name of the collision model.
77  std::string m_PrevName; ///< The previous file name, used to detect changes in `m_CollMdlName`.
78  const cf::ClipSys::CollisionModelT* m_CollisionModel; ///< The collision model of this component, NULL for none.
79  TypeSys::VarT<bool> m_IgnoreOrient; ///< If true, the orientation of the entity does not affect the orientation of the collision model.
80 
81  cf::ClipSys::ClipModelT* m_ClipModel; ///< The clip model of this component, NULL for none.
82  Vector3fT m_ClipPrevOrigin;
83  cf::math::QuaternionfT m_ClipPrevQuat;
84  };
85  }
86 }
87 
88 #endif
A clip model represents an object in the world against which clipping queries can be performed...
Definition: ClipModel.hpp:31
This class represents game entities, which are the basic elements of a world.
Definition: Entity.hpp:53
const cf::ClipSys::ClipModelT * GetClipModel() override
This method returns the clip model of this component, if any.
Definition: CompCollisionModel.hpp:48
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompCollisionModel.hpp:63
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:207
unsigned int GetEditorColor() const
Returns a color that the Map Editor can use to render the representation of this component's entity...
Definition: CompCollisionModel.hpp:47
void UpdateDependencies(EntityT *Entity)
This method is called whenever something "external" to this component has changed: ...
Definition: CompCollisionModel.cpp:107
~ComponentCollisionModelT()
The destructor.
Definition: CompCollisionModel.cpp:79
const char * GetName() const
Returns the name of this component.
Definition: CompCollisionModel.hpp:45
This component adds a collision model to its entity.
Definition: CompCollisionModel.hpp:23
This is the base class for collision models, defining their common interface.
Definition: CollisionModel_base.hpp:29
ComponentCollisionModelT * Clone() const
The virtual copy constructor.
Definition: CompCollisionModel.cpp:101
ComponentCollisionModelT()
The constructor.
Definition: CompCollisionModel.cpp:49
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54