CapsuleProxy.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "CapsuleProxy.h"
  2. #include "PhysicsScene.h"
  3. CapsuleProxy::CapsuleProxy(float radius, float height, const Matrix& transform, bool isDynamic, float density, PhysicsScene& scene) :
  4. CONSTRUCT_MCALLS,//m_calls(__FILE__, __LINE__),
  5. m_helper(m_calls),
  6. m_realCapsule(NULL),
  7. IPhysCapsule(&scene),
  8. IProxy(scene),
  9. m_radius(radius),
  10. m_height(height),
  11. m_isDynamic(isDynamic),
  12. m_density(density)
  13. {
  14. m_helper.m_transform = transform;
  15. }
  16. CapsuleProxy::~CapsuleProxy(void)
  17. {
  18. if (m_realCapsule)
  19. m_realCapsule->Release(), m_realCapsule = NULL;
  20. DELETE_MCALLS
  21. //for (unsigned int i = 0; i < m_calls.Size(); ++i) def_delete(m_calls[i]);
  22. //m_calls.DelAll();
  23. }
  24. //////////////////////////////////////////////////////////////////////////
  25. // IPhysCapsule
  26. //////////////////////////////////////////////////////////////////////////
  27. //Установить радиус
  28. void CapsuleProxy::SetRadius(float radius)
  29. {
  30. m_radius = radius;
  31. m_calls.Add
  32. (
  33. MakeDeferrer<IPhysCapsule, void, float>(DEF_FREF(IPhysCapsule::SetRadius), radius)
  34. );
  35. }
  36. //Получить радиус
  37. float CapsuleProxy::GetRadius()
  38. {
  39. if (!m_realCapsule)
  40. return m_radius;
  41. return m_realCapsule->GetRadius();
  42. }
  43. //Установить высоту
  44. void CapsuleProxy::SetHeight(float height)
  45. {
  46. m_height = height;
  47. m_calls.Add
  48. (
  49. MakeDeferrer<IPhysCapsule, void, float>(DEF_FREF(IPhysCapsule::SetHeight), height)
  50. );
  51. }
  52. //Получить высоту
  53. float CapsuleProxy::GetHeight()
  54. {
  55. if (!m_realCapsule)
  56. return m_height;
  57. return m_realCapsule->GetHeight();
  58. }
  59. //////////////////////////////////////////////////////////////////////////
  60. // IPhysRigidBody
  61. //////////////////////////////////////////////////////////////////////////
  62. //Получить позицию и ориентацию в мире
  63. void CapsuleProxy::GetTransform(Matrix & mtx)
  64. {
  65. if (!m_realCapsule)
  66. m_helper.GetTransform(mtx);
  67. else
  68. m_realCapsule->GetTransform(mtx);
  69. }
  70. //Получить массу
  71. float CapsuleProxy::GetMass()
  72. {
  73. if (!m_realCapsule)
  74. return m_helper.GetMass();
  75. return m_realCapsule->GetMass();
  76. }
  77. //Установить центр масс
  78. Vector CapsuleProxy::GetCenterMass()
  79. {
  80. if (!m_realCapsule)
  81. return m_helper.GetCenterMass();
  82. return m_realCapsule->GetCenterMass();
  83. }
  84. //Получить группы
  85. PhysicsCollisionGroup CapsuleProxy::GetGroup()
  86. {
  87. if (!m_realCapsule)
  88. return m_helper.GetGroup();
  89. return m_realCapsule->GetGroup();
  90. }
  91. // получить внутренности - !только для использования внутри сервиса
  92. void CapsuleProxy::GetInternals(PhysInternal & internals) const
  93. {
  94. if (!m_realCapsule)
  95. throw "invalid call";
  96. return m_realCapsule->GetInternals(internals);
  97. }
  98. // получить материал
  99. IPhysMaterial * CapsuleProxy::GetPhysMaterial() const
  100. {
  101. if (!m_realCapsule)
  102. return NULL;
  103. return m_realCapsule->GetPhysMaterial();
  104. }
  105. // получить линейную составляющую скорости
  106. Vector CapsuleProxy::GetLinearVelocity() const
  107. {
  108. if (!m_realCapsule)
  109. return Vector(0.0f);
  110. return m_realCapsule->GetLinearVelocity();
  111. }
  112. //////////////////////////////////////////////////////////////////////////
  113. // IPhysBase
  114. //////////////////////////////////////////////////////////////////////////
  115. bool CapsuleProxy::Release()
  116. {
  117. return IProxy::AddReleaseCount();
  118. //m_bReleaseCall = true;
  119. //return false;
  120. }
  121. //////////////////////////////////////////////////////////////////////////
  122. // IProxy
  123. //////////////////////////////////////////////////////////////////////////
  124. void CapsuleProxy::OnSyncCreate()
  125. {
  126. if (m_realCapsule)
  127. return;
  128. m_realCapsule = NEW PhysCapsule(GetFileName(), GetFileLine(), m_radius, m_height, m_helper.m_transform, m_isDynamic, m_density, &m_scene);
  129. Assert(m_realCapsule);
  130. SetRealPhysObject(m_realCapsule);
  131. PhysInternal internals;
  132. m_realCapsule->GetInternals(internals);
  133. internals.actor->userData = (IPhysBase*)this;
  134. }
  135. void CapsuleProxy::OnSyncCalls()
  136. {
  137. Assert(m_realCapsule);
  138. for (unsigned int i = 0; i < m_calls.Size(); ++i)
  139. {
  140. m_calls[i]->Call(m_realCapsule);
  141. def_delete(m_calls[i]);
  142. }
  143. m_calls.Empty();
  144. }
  145. bool CapsuleProxy::OnSyncRelease()
  146. {
  147. return IProxy::ReleaseCounts(this);
  148. //if (m_bReleaseCall)
  149. // return IPhysBase::Release();
  150. //return false;
  151. }
  152. void CapsuleProxy::OnSyncTrace()
  153. {
  154. TRACE_MCALLS
  155. }