BoxProxy.cpp 3.8 KB

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