Game.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "Game.h"
  2. Game::Game(int gametype)
  3. {
  4. GameType = gametype;
  5. rotateTrajLeft = InertialTrajProcess();
  6. rotateTrajRight = InertialTrajProcess();
  7. leftFootStep = FootStep();
  8. rightFootStep = FootStep();
  9. rotateMatrix[0] = 1.0f;
  10. rotateMatrix[1] = 0.0f;
  11. rotateMatrix[2] = 0.0f;
  12. rotateMatrix[3] = 1.0f;
  13. leftStepRate = 0;
  14. rightStepRate = 0;
  15. leftRate = 0;
  16. rightRate = 0;
  17. if (GameType == RUNGAME)
  18. {
  19. rungame = RunGame();
  20. }
  21. else if (GameType == DANCEGAME)
  22. {
  23. dancegame = DanceGame();
  24. }
  25. else if (GameType == ORIGINTRAJ)
  26. {
  27. originTraj = OriginTraj();
  28. }
  29. }
  30. void Game::GameProcess(int timeStamp, int* right_pos, int* right_att, int right_zupt, int* left_pos, int* left_att, int left_zupt, int jump, int down, int rssi, int girl_shoes)
  31. {
  32. leftFootStep.stepCal(timeStamp, left_pos, left_zupt);
  33. rightFootStep.stepCal(timeStamp, right_pos, right_zupt);
  34. if (GameType == RUNGAME)
  35. {
  36. //跑酷游戏处理函数
  37. if (left_zupt)
  38. {
  39. rotateTrajLeft.ResetHeading(left_att[0]);
  40. }
  41. rotateTrajLeft.TrajRotate(left_pos);
  42. if (right_zupt)
  43. {
  44. rotateTrajRight.ResetHeading(right_att[0]);
  45. }
  46. rotateTrajRight.TrajRotate(right_pos);
  47. rungame.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, down, girl_shoes);
  48. //跑酷游戏处理结果获取
  49. rungame.getResult(resultMatrix);
  50. }
  51. else if (GameType == DANCEGAME)
  52. {
  53. dancegame.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, down, rssi);
  54. dancegame.getResult(resultMatrix);
  55. }
  56. else if (GameType == ORIGINTRAJ)
  57. {
  58. originTraj.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt);
  59. }
  60. }
  61. void Game::RunGameProcess(int* right_pos, int* right_att, int right_zupt, int* left_pos, int* left_att, int left_zupt, int jump, int down, int girl_shoes)
  62. {
  63. rungame.Process( right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, down, girl_shoes);
  64. }
  65. void Game::getGameResult(int* matrix)
  66. {
  67. memcpy(matrix, resultMatrix, 4 * sizeof(int));
  68. }
  69. int Game::getStepStatus(int left_or_right)
  70. {
  71. if (left_or_right == LEFT_FOOT)
  72. return leftFootStep.getStepStatus();
  73. else if (left_or_right == RIGHT_FOOT)
  74. return rightFootStep.getStepStatus();
  75. else
  76. return -1;
  77. }
  78. int Game::getStepFreq( int left_or_right)
  79. {
  80. if (left_or_right == LEFT_FOOT)
  81. return leftFootStep.getStepFreq();
  82. else if (left_or_right == RIGHT_FOOT)
  83. return rightFootStep.getStepFreq();
  84. else
  85. return -1;
  86. }
  87. int Game::getStepCount(int left_or_right)
  88. {
  89. if (left_or_right == LEFT_FOOT)
  90. return leftFootStep.getStepCount();
  91. else if (left_or_right == RIGHT_FOOT)
  92. return rightFootStep.getStepCount();
  93. else
  94. return -1;
  95. }
  96. float Game::getGamePos(int left_or_right, int index)
  97. {
  98. if (index < 0 || index >2)
  99. return -1;
  100. if (GameType == RUNGAME)
  101. {
  102. return -1;
  103. }
  104. else if(GameType == DANCEGAME)
  105. {
  106. return dancegame.getGamePos(left_or_right, index);
  107. }
  108. else if (GameType == ORIGINTRAJ)
  109. {
  110. return originTraj.getGamePos(left_or_right, index);
  111. }
  112. else
  113. {
  114. return -1;
  115. }
  116. }
  117. string Game::getVersion()
  118. {
  119. return GAME_VERSION;
  120. }