123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #include "RunGame.h"
- #include "pub.h"
- void RunGame::Process(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)
- {
- /*
- 跑酷游戏处理接口,
- 暂时在同一个函数里分开处理左右脚的数据,往后再优化
- */
- if (left_zupt)
- {
- memcpy(left_last_pos, left_pos, 3 * sizeof(int));
- }
- if (right_zupt)
- {
- memcpy(right_last_pos, right_pos, 3 * sizeof(int));
- }
- int left_pos_tmp[3];
- int right_pos_tmp[3];
- for (int i = 0; i < 3; i++)
- {
- left_pos_tmp[i] = left_pos[i] - left_last_pos[i];
- right_pos_tmp[i] = right_pos[i] - right_last_pos[i];
- }
- /*
- if (left_zupt == 0)
- {
- std::cout << "rungame leftpos: " << left_pos_tmp[0] << " " << left_pos_tmp[1] << " " << left_pos_tmp[2] << std::endl;
- }
- if (right_zupt == 0)
- {
- std::cout << "rungame rightpos: " << right_pos_tmp[0] << " " << right_pos_tmp[1] << " " << right_pos_tmp[2] << std::endl;
- }
- */
- setResultConLeft(left_zupt);
- result[0] = getResultLeft(left_pos_tmp, girl_shoes);
- setResultConRight(right_zupt);
-
- result[1] = getResultRight(right_pos_tmp, girl_shoes);
- result[2] = getResultJump(jump);
- result[3] = getResultDown(down);
- }
- void RunGame::getResult(int* dec)
- {
- memcpy(dec, result, 4 * sizeof(int));
- }
- void RunGame::setResultConLeft(int zupt)
- {
- if (zupt == 1)
- {
- left_has_result = 1;
- left_pos_offset_min = 0;
- }
- }
- void RunGame::setResultConRight(int zupt)
- {
- if (zupt == 1)
- {
- right_has_result = 1;
- right_pos_offset_min = 0;
- }
- }
- int RunGame::getResultLeft(int *pos, int girl_shoes)
- {
- int isLeft = -1;
- int distance_threshold = 20;
- if (girl_shoes)
- distance_threshold = 12;
- if (pos[0] > left_pos_offset_min)
- {
- left_pos_offset_min = pos[0];
- }
- if (left_has_result == 1 && pos[0] - left_pos_offset_min < -distance_threshold)
- {
- printf("this motion is Left\n");
- isLeft = MOTION_LEFT;
- left_has_result = 0;
- }
- return isLeft;
- }
- int RunGame::getResultRight(int *pos, int girl_shoes)
- {
- int isRight = -1;
- int distance_threshold = 20;
- if (girl_shoes)
- distance_threshold = 12;
- if (pos[0] < right_pos_offset_min)
- {
- right_pos_offset_min = pos[0];
- }
- if (right_has_result == 1 && pos[0] - right_pos_offset_min > distance_threshold)
- {
- printf("this motion is Right\n");
- isRight = MOTION_RIGHT;
- right_has_result = 0;
- }
- return isRight;
- }
- int RunGame::getResultLeftRight(int* pos, int devNum)
- {
- if (devNum == LEFT_FOOT && pos[1] < 0)
- {
- return MOTION_LEFT;
- }
- if (devNum == RIGHT_FOOT && pos[1] > 0)
- {
- return MOTION_RIGHT;
- }
- return -1;
- }
- int RunGame::getResultJump(int jump)
- {
- int isJump = -1;
- if (last_jump == 0 && jump == 1)
- {
- printf("this motion is Jump\n");
- isJump = MOTION_JUMP;
- }
- last_jump = jump;
- return isJump;
- }
- int RunGame::getResultDown(int down)
- {
- int isDown = -1;
-
- if (last_down == 0 && down == 1)
- {
- printf("this motion is Down\n");
- isDown = MOTION_DOWN;
- }
- last_down = down;
- return isDown;
- }
- RunGame::RunGame()
- {
- last_down = 0;
- last_jump = 0;
- left_has_result = 0;
- right_has_result = 0;
- left_zupt = 0;
- right_zupt = 0;
- left_pos_offset_min = 0;
- right_pos_offset_min = 0;
- memset(result, 0, 4 * sizeof(int));
- memset(left_last_pos, 0, 3 * sizeof(int));
- memset(right_last_pos, 0, 3 * sizeof(int));
- }
|