MeshProxy.cpp 3.7 KB

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