RuinsExplore.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "RuinsExplore.h"
  2. RuinsExplore::RuinsExplore()
  3. {
  4. last_jump = 0;
  5. last_jump_time = 0;
  6. left_zupt = 0;
  7. right_zupt = 0;
  8. memset(result, 0, 4 * sizeof(int));
  9. }
  10. void RuinsExplore::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
  11. int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
  12. int jump, int down, int girl_shoes)
  13. {
  14. /*
  15. 跑酷游戏处理接口,
  16. 暂时在同一个函数里分开处理左右脚的数据,往后再优化
  17. */
  18. int left_pos_tmp[3];
  19. int right_pos_tmp[3];
  20. left_acc_status = getAccStatus(left_zupt, left_acc, left_acc_max, left_acc_min);
  21. right_acc_status = getAccStatus(right_zupt, right_acc, right_acc_max, right_acc_min);
  22. result[2] = getResultJump(jump);
  23. }
  24. int RuinsExplore::getResultJump(int jump)
  25. {
  26. int isJump = -1;
  27. last_jump_time++;
  28. if (last_jump == 0 && jump == 1 && left_acc_status == 1 && right_acc_status == 1)
  29. {
  30. static int jump_count = 0;
  31. printf(" RuinsExplore' motion is Jump : %d\n", jump_count++);
  32. isJump = MOTION_JUMP;
  33. last_jump_time = 0;
  34. }
  35. else
  36. {
  37. if (last_jump == 0 && jump == 1 && !(left_acc_status == 1 && right_acc_status == 1))
  38. {
  39. std::cout << " RuinsExplore appear error command on zero_vel status (jump command) " << endl;
  40. }
  41. }
  42. last_jump = jump;
  43. return isJump;
  44. }
  45. void RuinsExplore::getResult(int* dec)
  46. {
  47. memcpy(dec, result, 4 * sizeof(int));
  48. }
  49. int RuinsExplore::getAccStatus(int zupt, int* acc, int* max_acc, int* min_acc)
  50. {
  51. /*
  52. * 在游戏测试的时候发现有左右乱飞的情况,现在以及乱跳的情况,现在用加速度过滤这一个情况
  53. * 尽量不在嵌入式上修改
  54. */
  55. if (zupt)
  56. {
  57. memcpy(max_acc, acc, 3 * sizeof(int));
  58. memcpy(min_acc, acc, 3 * sizeof(int));
  59. }
  60. else
  61. {
  62. for (int i = 0; i < 3; i++)
  63. {
  64. if (max_acc[i] < acc[i])
  65. {
  66. max_acc[i] = acc[i];
  67. }
  68. if (min_acc[i] > acc[i])
  69. {
  70. min_acc[i] = acc[i];
  71. }
  72. }
  73. }
  74. for (int i = 0; i < 3; i++)
  75. {
  76. if (max_acc[i] - min_acc[i] > 1024)
  77. {
  78. return 1;
  79. }
  80. }
  81. return 0;
  82. }