SphereProxy.cpp 3.8 KB

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