#include "RuinsExplore.h" RuinsExplore::RuinsExplore() { last_jump = 0; last_jump_time = 0; left_zupt = 0; right_zupt = 0; memset(result, 0, 4 * sizeof(int)); } void RuinsExplore::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press, int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press, int jump, int down, int girl_shoes) { /* 跑酷游戏处理接口, 暂时在同一个函数里分开处理左右脚的数据,往后再优化 */ int left_pos_tmp[3]; int right_pos_tmp[3]; left_acc_status = getAccStatus(left_zupt, left_acc, left_acc_max, left_acc_min); right_acc_status = getAccStatus(right_zupt, right_acc, right_acc_max, right_acc_min); result[2] = getResultJump(jump); } int RuinsExplore::getResultJump(int jump) { int isJump = -1; last_jump_time++; if (last_jump == 0 && jump == 1 && left_acc_status == 1 && right_acc_status == 1) { static int jump_count = 0; printf(" RuinsExplore' motion is Jump : %d\n", jump_count++); isJump = MOTION_JUMP; last_jump_time = 0; } else { if (last_jump == 0 && jump == 1 && !(left_acc_status == 1 && right_acc_status == 1)) { std::cout << " RuinsExplore appear error command on zero_vel status (jump command) " << endl; } } last_jump = jump; return isJump; } void RuinsExplore::getResult(int* dec) { memcpy(dec, result, 4 * sizeof(int)); } int RuinsExplore::getAccStatus(int zupt, int* acc, int* max_acc, int* min_acc) { /* * 在游戏测试的时候发现有左右乱飞的情况,现在以及乱跳的情况,现在用加速度过滤这一个情况 * 尽量不在嵌入式上修改 */ if (zupt) { memcpy(max_acc, acc, 3 * sizeof(int)); memcpy(min_acc, acc, 3 * sizeof(int)); } else { for (int i = 0; i < 3; i++) { if (max_acc[i] < acc[i]) { max_acc[i] = acc[i]; } if (min_acc[i] > acc[i]) { min_acc[i] = acc[i]; } } } for (int i = 0; i < 3; i++) { if (max_acc[i] - min_acc[i] > 1024) { return 1; } } return 0; }