You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovaCManipulable3DEntity.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "ovaCManipulable3DEntity.h"
  2. REGISTER_OBJECT_FACTORY(CManipulable3DEntity, "ovaCManipulable3DEntity");
  3. CManipulable3DEntity::CManipulable3DEntity(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc) : OMK::SimulatedObject(controller, objectDesc) { }
  4. CManipulable3DEntity::~CManipulable3DEntity() { }
  5. /*
  6. ,m_rPositionOutput(addOutput < OMK::Translation > ("position", new OMK::Polator < OMK::Translation > ()))
  7. ,m_rOrientationOutput(addOutput < OMK::HPRRotation > ("orientation", new OMK::Polator < OMK::HPRRotation > ()))
  8. ,m_rScaleOutput(addOutput < OMK::Scale > ("scale", new OMK::Polator < OMK::Scale > ()))
  9. ,m_isGoal(false)
  10. {
  11. visualiseOutput < OMK::vTranslationInputHandler >(m_rPositionOutput, "DCS_position") ;
  12. visualiseOutput < OMK::vHPRRotationInputHandler >(m_rOrientationOutput, "DCS_orientation") ;
  13. visualiseOutput < OMK::vScaleInputHandler >(m_rScaleOutput, "DCS_scale") ;
  14. }
  15. */
  16. void CManipulable3DEntity::init() { }
  17. //void CManipulable3DEntity::init() { m_rTransformOutput.set(m_oTransform); }
  18. #define duration 1250
  19. #define fadein 500
  20. #define fadeout 500
  21. void CManipulable3DEntity::compute()
  22. {
  23. if (m_isGoal)
  24. {
  25. int delta = getSimulatedDate() - m_iGoalDate;
  26. if (delta < duration)
  27. {
  28. if (delta < fadein)
  29. {
  30. double coef = (fadein - delta) / (double)fadein; // 1-0
  31. double rotation = 180 * pow(coef, 3);
  32. m_orientation[0] = 0;
  33. m_orientation[1] = 3 * rotation;
  34. m_orientation[2] = rotation * sin(M_PI * pow(coef, 3) * 1);
  35. m_position[0] = 0;
  36. m_position[1] = 5 + 7 * sin(coef * M_PI / 2);
  37. m_position[2] = 0;
  38. }
  39. if (delta > duration - fadeout)
  40. {
  41. double coef = (delta - duration + fadeout) / double(fadeout); // 0-1
  42. double rotation = 3 * 180 * pow(coef, 4);
  43. m_orientation[0] = rotation;
  44. m_orientation[1] = 3 * rotation * sin(M_PI * pow(coef, 3) * 2);
  45. m_orientation[2] = 0;
  46. m_position[0] = 0;
  47. m_position[1] = 5 + 7 * coef * sin(coef * M_PI / 2);
  48. m_position[2] = 0;
  49. }
  50. if (delta >= fadein && delta <= duration - fadeout)
  51. {
  52. m_orientation[0] = 0;
  53. m_orientation[1] = 0;
  54. m_orientation[2] = 0;
  55. m_position[0] = 0;
  56. m_position[1] = 5;
  57. m_position[2] = 0;
  58. }
  59. }
  60. }
  61. /*
  62. m_rTransformOutput.set(m_oTransform);
  63. */
  64. }
  65. bool CManipulable3DEntity::processEvent(OMK::Event* pEvent)
  66. {
  67. if (pEvent->eventId == g_sManipulate3DEntity_Goal)
  68. {
  69. m_isGoal = true;
  70. m_iGoalDate = getSimulatedDate();
  71. }
  72. if (pEvent->eventId == g_sManipulate3DEntity_Reset)
  73. {
  74. m_position[0] = 0;
  75. m_position[1] = 0.2;
  76. m_position[2] = 0;
  77. m_orientation[0] = 0;
  78. m_orientation[1] = 0;
  79. m_orientation[2] = 0;
  80. #if defined _DEBUG_
  81. std::cout << "### reseted\n";
  82. #endif
  83. return true;
  84. }
  85. if (pEvent->eventId == g_sManipulate3DEntity_Translate)
  86. {
  87. PositionEvent* event = dynamic_cast <PositionEvent*>(pEvent);
  88. if (event)
  89. {
  90. const Position& value = event->value;
  91. m_position[0] += value[0];
  92. m_position[1] += value[1];
  93. m_position[2] += value[2];
  94. #if defined _DEBUG_
  95. std::cout << "### translated\n";
  96. #endif
  97. return true;
  98. }
  99. }
  100. if (pEvent->eventId == g_sManipulate3DEntity_SetPosition)
  101. {
  102. PositionEvent* event = dynamic_cast <PositionEvent*>(pEvent);
  103. if (event)
  104. {
  105. const Position& value = event->value;
  106. m_position[0] = value[0];
  107. m_position[1] = value[1];
  108. m_position[2] = value[2];
  109. #if defined _DEBUG_
  110. std::cout << "### moved\n";
  111. #endif
  112. return true;
  113. }
  114. }
  115. if (pEvent->eventId == g_sManipulate3DEntity_Scale)
  116. {
  117. ScaleEvent* event = dynamic_cast <ScaleEvent*>(pEvent);
  118. if (event)
  119. {
  120. const Scale& value = event->value;
  121. m_oScale[0] *= value[0];
  122. m_oScale[1] *= value[1];
  123. m_oScale[2] *= value[2];
  124. #if defined _DEBUG_
  125. std::cout << "### scaled\n";
  126. #endif
  127. return true;
  128. }
  129. }
  130. if (pEvent->eventId == g_sManipulate3DEntity_SetScale)
  131. {
  132. ScaleEvent* event = dynamic_cast <ScaleEvent*>(pEvent);
  133. if (event)
  134. {
  135. const Scale& value = event->value;
  136. m_oScale[0] = value[0];
  137. m_oScale[1] = value[1];
  138. m_oScale[2] = value[2];
  139. #if defined _DEBUG_
  140. std::cout << "### scaled fixed\n";
  141. #endif
  142. return true;
  143. }
  144. }
  145. if (pEvent->eventId == g_sManipulate3DEntity_Rotate)
  146. {
  147. OrientationEvent* event = dynamic_cast <OrientationEvent*>(pEvent);
  148. if (event)
  149. {
  150. const Orientation& value = event->value;
  151. m_orientation[0] += value[0];
  152. m_orientation[1] += value[1];
  153. m_orientation[2] += value[2];
  154. #if defined _DEBUG_
  155. std::cout << "### rotated\n";
  156. #endif
  157. return true;
  158. }
  159. }
  160. if (pEvent->eventId == g_sManipulate3DEntity_SetOrientation)
  161. {
  162. OrientationEvent* event = dynamic_cast <OrientationEvent*>(pEvent);
  163. if (event)
  164. {
  165. const Orientation& value = event->value;
  166. m_orientation[0] = value[0];
  167. m_orientation[1] = value[1];
  168. m_orientation[2] = value[2];
  169. #if defined _DEBUG_
  170. std::cout << "### orirentation set\n";
  171. #endif
  172. return true;
  173. }
  174. }
  175. return false;
  176. }