PhysicObjLocator.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //============================================================================================
  2. // Spirenkov Maxim, 2004
  3. //============================================================================================
  4. // Mission objects
  5. //============================================================================================
  6. // PhysicObjLocator
  7. //============================================================================================
  8. #include "PhysicObjLocator.h"
  9. //============================================================================================
  10. PhysicObjLocator::PhysicObjLocator()
  11. {
  12. locatorIndex = -1;
  13. error = false;
  14. }
  15. PhysicObjLocator::~PhysicObjLocator()
  16. {
  17. }
  18. //============================================================================================
  19. //Инициализировать объект
  20. bool PhysicObjLocator::Create(MOPReader & reader)
  21. {
  22. if(!MissionObject::Create(reader)) return false;
  23. //Освобождаем старые ресурсы
  24. po.Reset();
  25. locatorIndex = -1;
  26. //Параметры
  27. objectName = reader.String();
  28. locatorName = reader.String();
  29. error = false;
  30. return true;
  31. }
  32. //Инициализировать объект
  33. bool PhysicObjLocator::EditMode_Create(MOPReader & reader)
  34. {
  35. SetUpdate(&PhysicObjLocator::EditMode_Draw, ML_ALPHA1);
  36. Create(reader);
  37. return true;
  38. }
  39. //Обновить параметры
  40. bool PhysicObjLocator::EditMode_Update(MOPReader & reader)
  41. {
  42. Create(reader);
  43. return true;
  44. }
  45. //Получить размеры описывающего ящика
  46. void PhysicObjLocator::EditMode_GetSelectBox(Vector & min, Vector & max)
  47. {
  48. min = -0.2f;
  49. max = 0.2f;
  50. }
  51. //Получить матрицу объекта
  52. Matrix & PhysicObjLocator::GetMatrix(Matrix & mtx)
  53. {
  54. //Проверяем на валидность геометрию
  55. if(!po.Validate() && !error)
  56. {
  57. bool isPtr = FindObject(objectName, po);
  58. if(isPtr)
  59. {
  60. MO_IS_IF_NOT(id_IMissionPhysObject, "IMissionPhysObject", po.Ptr())
  61. {
  62. isPtr = false;
  63. }
  64. }
  65. if(!isPtr)
  66. {
  67. po.Reset();
  68. if(!EditMode_IsOn() && !error)
  69. {
  70. error = true;
  71. LogicDebugError("Physic object \"%s\" not found", objectName.c_str());
  72. return mtx;
  73. }
  74. }
  75. }
  76. if(locatorIndex < 0 || EditMode_IsOn())
  77. {
  78. if(locatorName.NotEmpty() && po.Validate())
  79. {
  80. locatorIndex = ((IMissionPhysObject *)po.Ptr())->GetLocatorIndexByName(locatorName);
  81. if(locatorIndex < 0)
  82. {
  83. if(EditMode_IsOn())
  84. {
  85. locatorName.Empty();
  86. error = true;
  87. LogicDebugError("Physic object \"%s\" not content locator \"%s\" at pattern", objectName.c_str(), locatorName.c_str());
  88. }
  89. return mtx;
  90. }
  91. }else{
  92. return mtx;
  93. }
  94. }
  95. bool res = ((IMissionPhysObject *)po.Ptr())->GetLocator(locatorIndex, mtx);
  96. Assert(res);
  97. return mtx;
  98. };
  99. //Нарисовать модельку
  100. void _cdecl PhysicObjLocator::EditMode_Draw(float dltTime, long level)
  101. {
  102. if(!EditMode_IsVisible()) return;
  103. if(!EditMode_IsSelect()) return;
  104. Matrix matrix;
  105. matrix.SetZero();
  106. GetMatrix(matrix);
  107. Render().DrawMatrix(matrix);
  108. Render().DrawSphere(matrix.pos, 0.01f, 0x90ffff80);
  109. Render().Print(matrix.pos, 5.0f, 1.0f, 0xffffff80, "Physic locator");
  110. Render().Print(matrix.pos, 5.0f, 2.0f, 0xffffff80, "\"%s\"", GetObjectID().c_str());
  111. };
  112. //============================================================================================
  113. //Параметры инициализации
  114. //============================================================================================
  115. MOP_BEGINLISTCG(PhysicObjLocator, "Physic locator", '1.00', 100, "Object make access to Physic object locator", "Physics")
  116. MOP_STRINGC("Physic object", "", "Mission object's name type of \"Physic object\"")
  117. MOP_STRINGC("Locator", "", "Locator name defined in \"Physic object pattern\"")
  118. MOP_ENDLIST(PhysicObjLocator)