Cafu Engine
RigidBody.hpp
1 /*
2 =================================================================================
3 This file is part of Cafu, the open-source game engine and graphics engine
4 for multiplayer, cross-platform, real-time 3D action.
5 Copyright (C) 2002-2013 Carsten Fuchs Software.
6 
7 Cafu is free software: you can redistribute it and/or modify it under the terms
8 of the GNU General Public License as published by the Free Software Foundation,
9 either version 3 of the License, or (at your option) any later version.
10 
11 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17 
18 For support and more information about Cafu, visit us at <http://www.cafu.de>.
19 =================================================================================
20 */
21 
22 #ifndef CAFU_RIGID_BODY_HPP_INCLUDED
23 #define CAFU_RIGID_BODY_HPP_INCLUDED
24 
25 #include "BaseEntity.hpp"
26 #include "btBulletDynamicsCommon.h"
27 
28 
29 struct luaL_Reg;
30 namespace cf { namespace SceneGraph { class GenericNodeT; } }
31 
32 
33 namespace GAME_NAME
34 {
35  class EntRigidBodyT : public BaseEntityT, public btMotionState
36  {
37  public:
38 
39  EntRigidBodyT(const EntityCreateParamsT& Params);
40  ~EntRigidBodyT();
41 
42  // Implement the BaseEntityT interface.
43  void TakeDamage(BaseEntityT* Entity, char Amount, const VectorT& ImpactDir);
44  void Think(float FrameTime, unsigned long ServerFrameNr);
45  void Draw(bool FirstPersonView, float LodDist) const;
46 
47  // Implement the btMotionState interface.
48  void getWorldTransform(btTransform& worldTrans) const;
49  void setWorldTransform(const btTransform& worldTrans);
50 
51 
52  const cf::TypeSys::TypeInfoT* GetType() const;
53  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
54  static const cf::TypeSys::TypeInfoT TypeInfo;
55 
56 
57  private:
58 
59  // Override the base class methods.
60  void DoSerialize(cf::Network::OutStreamT& Stream) const;
61  void DoDeserialize(cf::Network::InStreamT& Stream);
62 
63  const cf::SceneGraph::GenericNodeT* m_RootNode; ///< The root node of the scene graph of the model (brushwork) of this entity.
64  btCollisionShape* m_CollisionShape; ///< The collision shape for use with the rigid body.
65  btRigidBody* m_RigidBody; ///< The rigid body for use in the physics world.
66  const Vector3dT m_HalfExtents; ///< Half of the extents (the "radius") of the bounding-box of this model.
67  btQuaternion m_Rotation; ///< Complementing the origin, this is the spatial "orientation" of the model (the "better" alternative to heading, pitch and bank).
68 
69 
70  // Script methods (to be called from the map/entity Lua scripts).
71  static int ApplyImpulse(lua_State* LuaState);
72  static int SetGravity(lua_State* LuaState);
73 
74  static const luaL_Reg MethodsList[];
75  };
76 }
77 
78 #endif
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:222
Definition: EntityCreateParams.hpp:38
Definition: BaseEntity.hpp:85
This class is used for writing data into a StateT instance (serialization).
Definition: State.hpp:96
Definition: RigidBody.hpp:35
Definition: TypeSys.hpp:67
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:94
Definition: Node.hpp:50