PlaneProxy.cpp 3.6 KB

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