123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- #include "Game.h"
- Game::Game(int gametype)
- {
- GameType = gametype;
- rotateTrajLeft = InertialTrajProcess();
- rotateTrajRight = InertialTrajProcess();
- leftFootStep = FootStep();
- rightFootStep = FootStep();
- rotateMatrix[0] = 1.0f;
- rotateMatrix[1] = 0.0f;
- rotateMatrix[2] = 0.0f;
- rotateMatrix[3] = 1.0f;
- leftStepRate = 0;
- rightStepRate = 0;
- leftRate = 0;
- rightRate = 0;
- interaction = Interaction();
- InteractionCMD = -1;
- if (GameType == RUNGAME)
- {
- rungame = RunGame();
- }
- else if (GameType == DANCEGAME)
- {
- dancegame = DanceGame();
- }
- else if (GameType == ORIGINTRAJ)
- {
- originTraj = OriginTraj();
- }
- else if (GameType == H5GAME)
- {
- jumpH5game = jumpH5();
- }
- }
- int Game::getInteractionCMD()
- {
- return InteractionCMD;
- }
- void Game::GameProcess(int timeStamp, int* right_pos, int* right_att, int right_zupt, int right_press,
- int* left_pos, int* left_att, int left_zupt, int left_press, int jump, int down, int rssi, int girl_shoes)
- {
- leftFootStep.stepCal(timeStamp, left_pos, left_zupt);
- rightFootStep.stepCal(timeStamp, right_pos, right_zupt);
- /*
- interaction.Process(right_pos, right_att, right_zupt, right_press,
- left_pos, left_att, left_zupt, left_press, jump, down, rssi);
- InteractionCMD = interaction.get_motion_state();
- */
-
- if (GameType == RUNGAME)
- {
- //跑酷游戏处理函数
- if (left_zupt)
- {
- rotateTrajLeft.ResetHeading(left_att[0]);
- }
- rotateTrajLeft.TrajRotate(left_pos);
-
- if (right_zupt)
- {
- rotateTrajRight.ResetHeading(right_att[0]);
- }
- rotateTrajRight.TrajRotate(right_pos);
-
- rungame.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, down, girl_shoes);
- //跑酷游戏处理结果获取
- rungame.getResult(resultMatrix);
- }
- else if (GameType == DANCEGAME)
- {
- dancegame.Process(right_pos, right_att, right_zupt, right_press , left_pos, left_att, left_zupt, left_press, jump, down, rssi);
- dancegame.getResult(resultMatrix);
- }
- else if (GameType == ORIGINTRAJ)
- {
- originTraj.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt);
- }
- else if (GameType == H5GAME)
- {
- if (left_zupt)
- {
- rotateTrajLeft.ResetHeading(left_att[0]);
- }
- rotateTrajLeft.TrajRotate(left_pos);
- if (right_zupt)
- {
- rotateTrajRight.ResetHeading(right_att[0]);
- }
- rotateTrajRight.TrajRotate(right_pos);
- jumpH5game.Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, timeStamp, rssi);
- jumpH5game.getResult(resultMatrix);
- }
- /*
- if (foot_data_file.is_open()&& GameType == DANCEGAME)
- {
- foot_data_file << timeStamp << " " << dancegame.getGamePos(LEFT_FOOT, 0) << " " << dancegame.getGamePos(LEFT_FOOT, 1) << " " << left_zupt <<
- " " << dancegame.getGamePos(RIGHT_FOOT, 0) << " " << dancegame.getGamePos(RIGHT_FOOT, 1) << " " << right_zupt << " " << rssi
- << " " << bingo << std::endl;
- bingo = 0;
- }
- */
-
- }
- 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)
- {
- rungame.Process( right_pos, right_att, right_zupt, left_pos, left_att, left_zupt, jump, down, girl_shoes);
- }
- void Game::getGameResult(int* matrix)
- {
- memcpy(matrix, resultMatrix, 4 * sizeof(int));
- }
- int Game::getStepStatus(int left_or_right)
- {
- if (left_or_right == LEFT_FOOT)
- return leftFootStep.getStepStatus();
- else if (left_or_right == RIGHT_FOOT)
- return rightFootStep.getStepStatus();
- else
- return -1;
- }
- int Game::getStepFreq( int left_or_right)
- {
- if (left_or_right == LEFT_FOOT)
- return leftFootStep.getStepFreq();
- else if (left_or_right == RIGHT_FOOT)
- return rightFootStep.getStepFreq();
- else
- return -1;
- }
- int Game::getStepCount(int left_or_right)
- {
- if (left_or_right == LEFT_FOOT)
- return leftFootStep.getStepCount();
- else if (left_or_right == RIGHT_FOOT)
- return rightFootStep.getStepCount();
- else
- return -1;
- }
- float Game::getGamePos(int left_or_right, int index)
- {
- if (index < 0 || index >2)
- return -1;
- if (GameType == RUNGAME)
- {
- return -1;
- }
- else if(GameType == DANCEGAME)
- {
- return dancegame.getGamePos(left_or_right, index);
- }
- else if (GameType == ORIGINTRAJ)
- {
- return originTraj.getGamePos(left_or_right, index);
- }
- else
- {
- return -1;
- }
- }
- string Game::getVersion()
- {
- return GAME_VERSION;
- }
- //解析鞋子的数据
- void Game::GameProcess(uint8_t* buf, int len) {
- right_pos_data[0] = int32_t(buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0);
- right_pos_data[1] = int32_t(buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7] << 0);
- right_pos_data[2] = int32_t(buf[8] << 24 | buf[9] << 16 | buf[10] << 8 | buf[11] << 0);
- left_pos_data[0] = int32_t(buf[12] << 24 | buf[13] << 16 | buf[14] << 8 | buf[15] << 0);
- left_pos_data[1] = int32_t(buf[16] << 24 | buf[17] << 16 | buf[18] << 8 | buf[19] << 0);
- left_pos_data[2] = int32_t(buf[20] << 24 | buf[21] << 16 | buf[22] << 8 | buf[23] << 0);
- right_att_data[0] = int(buf[24] << 8 | buf[25] << 0);
- right_att_data[1] = int(buf[26] << 8 | buf[27] << 0);
- right_att_data[2] = int(buf[28] << 8 | buf[29] << 0);
- left_att_data[0] = int(buf[30] << 8 | buf[31] << 0);
- left_att_data[1] = int(buf[32] << 8 | buf[33] << 0);
- left_att_data[2] = int(buf[34] << 8 | buf[35] << 0);
- right_acc_data[0] = int(buf[36] << 8 | buf[37] << 0);
- right_acc_data[1] = int(buf[38] << 8 | buf[39] << 0);
- right_acc_data[2] = int(buf[40] << 8 | buf[41] << 0);
- left_acc_data[0] = int(buf[42] << 8 | buf[43] << 0);
- left_acc_data[1] = int(buf[44] << 8 | buf[45] << 0);
- left_acc_data[2] = int(buf[46] << 8 | buf[47] << 0);
- girl_shoes = (buf[48] & 0x16) >> 4;
- s_zupt = (buf[48] & 0x08) >> 3;
- h_zupt = (buf[48] & 0x04) >> 2;
- down = (buf[48] & 0x02) >> 1;
- jump = (buf[48] & 0x01) >> 0;
- rssi = (int)buf[49];
- posTimeStamp = buf[50];
- std::cout << "package_time : " << posTimeStamp << std::endl;
- right_press = uint16_t(buf[51] << 8 | buf[52] << 0);
- left_press = uint16_t(buf[53] << 8 | buf[54] << 0);
- GameProcess(posTimeStamp,
- right_pos_data, right_att_data, s_zupt, (int)right_press,
- left_pos_data, left_att_data, h_zupt, (int)left_press,
- jump, down, rssi, girl_shoes);
- }
- //游戏开始的时候触发的动作
- void Game::start(string path_root)
- {
- string game_name;
-
- if (GameType == RUNGAME)
- {
- game_name = "rungame";
- }
- else if (GameType == DANCEGAME)
- {
- game_name = "dancegame";
- }
- stringstream ss;
- ss << time(NULL);
- foot_data_file.open(path_root + '/'+game_name + "_" + ss.str() + ".txt", fstream::out);
- }
- void Game::end()
- {
- foot_data_file.close();
- }
- void Game::isBingo()
- {
- bingo = 1;
- }
|