RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
cgameobject.h
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #ifndef RIOENGINE_CENGINE_CGAMEOBJECT_H_
31 #define RIOENGINE_CENGINE_CGAMEOBJECT_H_
32 
33 #include <QString>
34 #include "misc/transform.h"
35 #include "clengine/clnode.h"
39 #include "bullet/btbulletdynamicscommon.h"
40 #include "bullet/btbulletcollisioncommon.h"
41 
42 class CActionManager;
43 class CAction;
44 class CGameScene;
45 
46 class CGameObject : public CLNode {
47  Q_OBJECT
48  Q_PROPERTY(QList<QProperty> DynamicProperties READ dynamicProperties WRITE setDynamicProperties DESIGNABLE false)
49 
50  Q_PROPERTY(int CObjectType READ CObjectType WRITE setCObjectType )
51  Q_PROPERTY(int Tag READ tag WRITE setTag )
52  Q_CLASSINFO("CObjectType", "CustomEnum=CClasses") // TODO improve this
53  Q_PROPERTY(btVector3 Position READ position WRITE setPosition)
54  Q_PROPERTY(btQuaternion RotationQuat READ rotationQuat WRITE setRotation DESIGNABLE false )
55  Q_PROPERTY(btVector3 Rotation READ rotation WRITE setRotation STORED false )
56  Q_PROPERTY(btVector3 Scale READ scale WRITE setScale )
57  Q_PROPERTY(QString CObjectTypeName READ CObjectTypeName WRITE setCObjectTypeName DESIGNABLE false )
58 
59  // bullet physics properties
60  Q_PROPERTY(CBulletProperties::ActivationState ActivationState READ activationState WRITE setActivationState )
61  Q_PROPERTY(bool PhysicsEnabled READ bPhysicsEnabled WRITE setbPhysicsEnabled )
62  Q_PROPERTY(float Mass READ bMass WRITE setbMass )
63  Q_PROPERTY(float Restitution READ bRestitution WRITE setbRestitution )
64  Q_PROPERTY(float Friction READ bFriction WRITE setbFriction )
65  Q_PROPERTY(btVector3 LinearFactor READ bLinearFactor WRITE setbLinearFactor )
66  Q_PROPERTY(btVector3 AngularFactor READ bAngularFactor WRITE setbAngularFactor )
67  Q_PROPERTY(CBulletProperties::ShapeTypes ShapeType READ shapeType WRITE setShapeType )
68  Q_PROPERTY(float ShapeType_Radius READ bShapeTypeRadius WRITE setbShapeTypeRadius )
69  Q_PROPERTY(float ShapeType_Height READ bShapeTypeHeight WRITE setbShapeTypeHeight )
70  Q_PROPERTY(btVector3 ShapeType_Size READ bShapeTypeSize WRITE setbShapeTypeSize )
71  Q_PROPERTY(QString ShapeType_Vertices READ bShapeTypeVertices WRITE setbShapeTypeVertices )
72  Q_PROPERTY(btVector3 ShapeType_PlaneNormal READ bShapeTypePlaneNormal WRITE setbShapeTypePlaneNormal )
73  Q_PROPERTY(float ShapeType_PlaneConstant READ bShapeTypePlaneConstant WRITE setbShapeTypePlaneConstant )
74  // -----------------
75 
76 public:
77  CGameObject();
78  CGameObject(const CGameObject& game_object);
79  const CGameObject& operator=(const CGameObject& game_object);
80 
81  int CObjectType() const;
82  void setCObjectType(int type);
83 
84  const QString& CObjectTypeName() const;
85  void setCObjectTypeName(const QString& name);
86 
87  void setName(const std::string& name);
88  std::string name() const;
89 
90  int tag() const;
91  void setTag(int tag);
92 
93  const bool bPhysicsEnabled() const;
94  void setbPhysicsEnabled(bool enable_physics);
95 
96  const float bMass() const;
97  void setbMass(float mass);
98 
99  const float bRestitution() const;
100  void setbRestitution(float restitution);
101 
102  const float bFriction() const;
103  void setbFriction(float friction);
104 
105  const btVector3& bLinearFactor() const;
106  void setbLinearFactor(const btVector3& linear_factor);
107 
108  const btVector3& bAngularFactor() const;
109  void setbAngularFactor(const btVector3& angular_factor);
110 
111  const CBulletProperties::ShapeTypes shapeType() const;
112  void setShapeType(CBulletProperties::ShapeTypes shape_type);
113 
114  const CBulletProperties::ActivationState activationState() const;
115  void setActivationState(CBulletProperties::ActivationState activation_state);
116 
117  void setActionManager(CActionManager* action_manager);
118 
119  CActionManager* actionManager() const;
120  CGameScene* parentScene() const;
121  btCollisionShape* collisionShape();
122 
126  unsigned int uid() const;
127 
128  void addChild(CGameObject* child);
129 
135  virtual void remove();
136 
137  void deployIntoDynamicsWorld();
138  void removeFromDynamicsWorld();
139 
143  virtual void start();
144 
148  virtual void preUpdate();
149 
153  virtual void update();
154 
155  virtual void postWorldUpdate();
156  virtual void postUpdate();
157 
161  virtual void onCollisionWithObject(CGameObject* object);
162 
166  virtual void aboutToBeRemoved();
167 
171  virtual const btVector3& calcSize();
172 
173  // -------------- Custom setters and getters for Q_PROPERTYs
174  const btVector3 position(Transform::UnitType unit_type = Transform::UnitType::WORLD);
175  void setPosition(const btVector3 &value);
176  void setPosition(float x, float y, float z);
177 
178  const btVector3 scale();
179  void setScale(btVector3 &scale);
180  void setScale(float x, float y, float z);
181  void setScale(float scale);
182 
183  btVector3 rotation();
184  btQuaternion rotationQuat();
185  void setRotation(const btVector3& rotation);
186  void setRotation(const btQuaternion& rotation);
187  void setRotation(float x, float y, float z);
188  void setRotation(float w, float x, float y, float z);
189 
190  const QList<QProperty> dynamicProperties() const;
191  void setDynamicProperties(QList<QProperty> dynamic_properties);
192 
193  const float bShapeTypeRadius() const;
194  void setbShapeTypeRadius(float radius);
195 
196  const float bShapeTypeHeight() const;
197  void setbShapeTypeHeight(float height);
198 
199  const btVector3 bShapeTypeSize() const;
200  void setbShapeTypeSize(btVector3& size);
201 
202  const QString bShapeTypeVertices() const;
203  void setbShapeTypeVertices(QString vertices);
204 
205  const btVector3 bShapeTypePlaneNormal() const;
206  void setbShapeTypePlaneNormal(btVector3& normal);
207 
208  const float bShapeTypePlaneConstant() const;
209  void setbShapeTypePlaneConstant(float plane_constant);
210 
211  // actions
212 
216  void runAction(CAction* action);
217 
221  void stopAllActions();
222 
226  void stopAction(CAction* action);
227 
231  void stopActionByTag(unsigned int tag);
232 
237  CAction* getActionByTag(unsigned int tag);
238 
245  unsigned int numberOfRunningActions();
246 
247  ~CGameObject();
248 
249  CBulletProperties bulletProperties; // TODO create setter & getter
250 
251 protected:
252  virtual void copyValuesFromObject(const CGameObject& game_object);
253  virtual void __init();
254 
256  int m_tag;
257 
258 private:
259  void updateBulletProperties();
260 
261  int m_CObjectType;
262  unsigned int m_uid;
263 };
264 Q_DECLARE_METATYPE(CGameObject)
265 
266 #endif // RIOENGINE_CENGINE_CGAMEOBJECT_H_
Definition: clnode.h:37
virtual void copyValuesFromObject(const CGameObject &game_object)
Definition: cgameobject.cpp:76
virtual void __init()
Definition: cgameobject.cpp:49
const btVector3 & size() const
Definition: clnode.cpp:182
CActionManager * m_actionManager
Definition: cgameobject.h:255
QList< QProperty > DynamicProperties
Definition: cgameobject.h:48