My Project
BlockDynamicObject.h
1 #pragma once
2 #include "BlockEngine/BlockCommon.h"
3 #include "TileObject.h"
4 
5 namespace ParaEngine
6 {
7  /* base class for dynamic object in block world.
8  * The base implementation supports simple sphere physics.
9  */
11  {
12  public:
14  virtual ~CBlockDynamicObject();
15 
16  ATTRIBUTE_DEFINE_CLASS(CBlockDynamicObject);
17  ATTRIBUTE_SUPPORT_CREATE_FACTORY(CBlockDynamicObject);
18 
20  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
21 
22 
23  ATTRIBUTE_METHOD1(CBlockDynamicObject, GetLifetime_s, float*) { *p1 = cls->GetLifetime(); return S_OK; }
24  ATTRIBUTE_METHOD1(CBlockDynamicObject, SetLifetime_s, float) { cls->SetLifetime(p1); return S_OK; }
25 
26  ATTRIBUTE_METHOD1(CBlockDynamicObject, GetFadeOutTime_s, float*) { *p1 = cls->GetFadeOutTime(); return S_OK; }
27  ATTRIBUTE_METHOD1(CBlockDynamicObject, SetFadeOutTime_s, float) { cls->SetFadeOutTime(p1); return S_OK; }
28 
29  ATTRIBUTE_METHOD1(CBlockDynamicObject, CanBounce_s, bool*) { *p1 = cls->CanBounce(); return S_OK; }
30  ATTRIBUTE_METHOD1(CBlockDynamicObject, SetCanBounce_s, bool) { cls->SetCanBounce(p1); return S_OK; }
31 
32  ATTRIBUTE_METHOD1(CBlockDynamicObject, GetSpeed_s, Vector3*) { *p1 = cls->GetSpeed(); return S_OK; }
33  ATTRIBUTE_METHOD1(CBlockDynamicObject, SetSpeed_s, Vector3) { cls->SetSpeed(p1); return S_OK; }
34 
35 
36  public:
37  virtual bool IsTileObject() { return false; };
38  virtual void SetPosition(const DVector3 & v);
39 
40  virtual void Animate(double dTimeDelta, int nRenderNumber = 0);
41 
44  virtual bool TestCollision(CBaseCamera* pCamera);
45 
46  void UpdateParams();
47 
48  float GetLifetime() const { return m_lifetime; }
49  void SetLifetime(float val) { m_lifetime = val; }
50 
51  float GetFadeOutTime() const { return m_fade_out_time; }
52  void SetFadeOutTime(float val) { m_fade_out_time = val; }
53 
55  bool CanBounce() const { return m_can_bounce; }
56  void SetCanBounce(bool val) { m_can_bounce = val; }
57 
58  const Vector3& GetSpeed() const { return m_vSpeed; }
59  void SetSpeed(const Vector3& val) { m_vSpeed = val; }
60 
61 
62  virtual void SetParent(CBaseObject* pParent);
63  virtual CBaseObject* GetParent();
64  virtual bool IsDead();
65  virtual void SetDead();
66 
67  bool IsOnGround() const;
68  void SetOnGround(bool val);
69  protected:
70 
71  Vector3 m_vSpeed;
72 
73  Vector3 m_vBlockCenter;
74  Vector3 m_vOffsetFromCenter;
75  Uint16x3 m_vBlockPos;
76 
78  float m_lifetime;
79  float m_fade_out_time;
80 
81  bool m_is_stopped;
82  bool m_can_bounce;
83  bool m_isOnGround;
84 
85  bool m_bIsDead;
86 
88  public:
89  static float default_min_speed;
90  static float default_surface_decay;
91  static float default_air_decay;
92  static float default_gravity;
93  static float default_speedlost_perbounce;
94  };
95 }
96 
97 
float m_lifetime
in seconds
Definition: BlockDynamicObject.h:78
3-dimensional vector with double precision.
Definition: ParaDVector3.h:17
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual bool TestCollision(CBaseCamera *pCamera)
check if the object's original shape can be seen via a camera.
Definition: BlockDynamicObject.cpp:35
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual void SetParent(CBaseObject *pParent)
this function is called by parent class to set the child's parent.
Definition: BlockDynamicObject.cpp:41
basic block world coordinate
Definition: BlockCoordinate.h:72
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: BlockDynamicObject.cpp:255
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Definition: BaseCamera.h:70
bool CanBounce() const
whether the object will bounce when hitting the ground.
Definition: BlockDynamicObject.h:55
virtual void Animate(double dTimeDelta, int nRenderNumber=0)
animate the model by a given delta time.
Definition: BlockDynamicObject.cpp:95
virtual void SetPosition(const DVector3 &v)
always bottom center of the bounding shape
Definition: BlockDynamicObject.cpp:86
Tile Object have position and bounding rect and can usually be attached to quad-tree terrain tile...
Definition: TileObject.h:10
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
virtual bool IsDead()
whether this object should be removed some time in the future.
Definition: BlockDynamicObject.cpp:51
virtual bool IsTileObject()
if true, we will attach this object to quad-tree terrain tile according to its attributes when adding...
Definition: BlockDynamicObject.h:37
Definition: BlockDynamicObject.h:10