📄 position.h
字号:
};/*--------------------------------------------------------------*/class PositionInfo {public: PositionInfo(); Initialize(const char team, const int number, char *team_name); ~PositionInfo(); float GetMarkerDistance(int marker); float GetMarkerAngle(int marker); float GetMarkerGlobalX(int marker); float GetMarkerGlobalY(int marker); inline void GetMarkerGlobalXY(int marker, float *x, float *y) {*x = GetMarkerGlobalX(marker), *y = GetMarkerGlobalY(marker);} float MarkerValid(int marker); int ClosestGoal(); int ClosestFlag(); int ClosestUnseenPlayer(char *side, float *global_x, float *global_y); int MyVelValid(); float GetMyVelMagnitude(); float GetMyVelDirection(); float GetPlayerDistance(char side, int number); float GetPlayerAngle(char side, int number); float GetPlayerAngleRad(char side, int number); float PlayerDistanceValid(char side, int number); float PlayerAngleValid(char side, int number); float PlayerValid(char side, int number); float GetPlayerVelMagnitude(char side, int num); /* from the server */ float GetPlayerVelDirection(char side, int num); /* In relative terms */ int PlayerVelValid(char side, int num); inline float GetTeammateDistance(int number) {return GetPlayerDistance(MySide,number);} inline float GetTeammateAngle(int number) {return GetPlayerAngle(MySide,number);} inline float GetTeammateAngleRad(int number) {return GetPlayerAngleRad(MySide,number);} inline float TeammateDistanceValid(int number) {return PlayerDistanceValid(MySide,number);} inline float TeammateAngleValid(int number) {return PlayerAngleValid(MySide,number);} inline float TeammateValid(int number) {return PlayerValid(MySide,number);} inline float GetTeammateVelMagnitude(int num) {return GetPlayerVelMagnitude(MySide,num);} inline float GetTeammateVelDirection(int num) {return GetPlayerVelDirection(MySide,num);} inline int TeammateVelValid(int num) {return PlayerVelValid(MySide,num);} inline float GetOpponentDistance(int number) {return GetPlayerDistance(TheirSide,number);} inline float GetOpponentAngle(int number) {return GetPlayerAngle(TheirSide,number);} inline float GetOpponentAngleRad(int number) {return GetPlayerAngleRad(TheirSide,number);} inline float OpponentDistanceValid(int number) {return PlayerDistanceValid(TheirSide,number);} inline float OpponentAngleValid(int number) {return PlayerAngleValid(TheirSide,number);} inline float OpponentValid(int number) {return PlayerValid(TheirSide,number);} inline float GetOpponentVelMagnitude(int num) {return GetPlayerVelMagnitude(TheirSide,num);} inline float GetOpponentVelDirection(int num) {return GetPlayerVelDirection(TheirSide,num);} inline int OpponentVelValid(int num) {return PlayerVelValid(TheirSide,num);} float GetBallDistance(); float GetBallAngle(); float GetBallAngleRad(); float GetBallRelVelDirection(); /* My calculation using relatives */ float GetBallRelVelMagnitude(); float GetBallTrajectoryAbsoluteDirection(); /* My calculation using globals */ float GetBallTrajectoryRelativeDirection(); float GetBallTrajectoryMagnitude(); float GetBallVelMagnitude(); /* from the server */ float GetBallVelDirection(); /* In relative terms */ float BallDistanceValid(); float BallAngleValid(); float BallValid(); float BallRelVelocityValid(); float BallTrajectoryValid(); int BallVelValid(); void SeeLine(int line, float dist, float ang, int time); void SeeLine(int line, float ang, int time); void SeeMarker(int marker, float dist, float ang, int time); void SeeMarker(int marker, float ang, int time); void SeeMarker(int marker, float dist, float ang, float distChng, float dirChng, int time); void SeeBall(float ang, int time); void SeeBall(float dist, float ang, int time); void SeeBall(float dist, float ang, float distChng, float dirChng, int time); void SeePlayer(char side, int num, float ang, int time); void SeePlayer(char side, int num, float dist, float ang, int time); void SeePlayer(char side, int num, float dist, float ang, float distChng, float dirChng, int time); void SeePlayer(float dist, float ang, float distChng, float dirChng, int time); void SeePlayer(char side, float dist, float ang, int time); void SeePlayer(char side, float ang, int time); void SeePlayer(float dist, float ang, int time); void SeePlayer(float ang, int time); void SeeExtraPlayer(char side, float dist, float ang, int time); void ClearExtraPlayer(); virtual void HearPlayer(char side, int num, float ang, char *msg, int time); inline void HearPlayerGlobalPosition(char side, int num, float x, float y, int time) { ((side == MySide) ? MyTeam[num] : TheirTeam[num])->set_globalxy(x,y,time); } inline void HearTeammateGlobalPosition(int num, float x, float y, int time) { HearPlayerGlobalPosition(MySide,num,x,y,time); } inline void HearOpponentGlobalPosition(int num, float x, float y, int time) { HearPlayerGlobalPosition(TheirSide,num,x,y,time); } inline void HearBallGlobalPosition(float x, float y, int time) { Ball->set_globalxy(x,y,time); } void UpdatePlayerGlobalPosition(char side, int num); void UpdateBallGlobalPosition(); void ClearBallGlobalPosition(); void Tick(int marker,int time); void UpdateMobileObjectPositions(int erase_data); void DisambiguateExtraPlayers(); void Reset(); void ClearAction(); void Dashing(float power); void Turning(float angle); float LastTurnAngle; void Kicking(float power,float angle); int Dashed; /* Did I dash in the last sensor interval? */ void Acting(int code); void Print(); int view_width; int view_quality; int GetViewAngle(); int GetViewAngle(int width); int TimePerSight(); inline float GetGlobalAngle(){return global_angle;} inline float GetGlobalX() {return global_x;} inline float GetGlobalY() {return global_y;} inline void GetGlobalXY(float *x, float *y) { *x = global_x; *y = global_y; } float AngleToPoint(float x, float y); // In degrees float DistanceToPoint(float x, float y); inline float polar_to_globalx(float r, float t) { return global_x + r * cos(global_angle - t); } inline float polar_to_globaly(float r, float t) { return global_y + r * sin(global_angle - t); } /* Uses the global position of the client to calculate global position of viewed objects. Could be stored, but risky */ /* Both global_angle and t should be in RADIANS */ inline void polar_to_globalxy(float r, float t, float *x, float *y) {*x = global_x + r*cos(global_angle - t); *y = global_y + r*sin(global_angle - t);} float globalxy_to_polar_r(float x, float y); float globalxy_to_polar_t(float x, float y); inline void globalxy_to_polar(float x, float y, float *r, float *t) {*r = globalxy_to_polar_r(x,y); *t = globalxy_to_polar_t(x,y);} inline void GetMobileGlobalXY(PositionMobile *MobileObject, float *x, float *y) { polar_to_globalxy( MobileObject->get_r(), MobileObject->get_t(), x, y ); } inline float GetMobileGlobalX(PositionMobile *MobileObject) { return polar_to_globalx( MobileObject->get_r(), MobileObject->get_t() ); } inline float GetMobileGlobalY(PositionMobile *MobileObject) { return polar_to_globaly( MobileObject->get_r(), MobileObject->get_t() ); } inline void GetMobileLastGlobalXY(PositionMobile *MobileObject, float *x, float *y) { MobileObject->get_globalxy(x,y); } inline int GetMobileGlobalSetTime(PositionMobile *MobileObject) { return MobileObject->get_global_set_time(); } inline void GetPlayerGlobalXY(char side, int num, float *x, float *y) { GetMobileGlobalXY( (side == MySide ? MyTeam[num] : TheirTeam[num]), x, y ); } inline float GetPlayerGlobalX(char side, int num) { return GetMobileGlobalX( (side == MySide ? MyTeam[num] : TheirTeam[num]) ); } inline float GetPlayerGlobalY(char side, int num) { return GetMobileGlobalY( (side == MySide ? MyTeam[num] : TheirTeam[num]) ); } inline void GetPlayerLastGlobalXY(char side, int num, float *x, float *y) { GetMobileLastGlobalXY( (side == MySide ? MyTeam[num] : TheirTeam[num]), x, y ); } inline int GetPlayerGlobalSetTime(char side, int num) { return GetMobileGlobalSetTime( (side == MySide ? MyTeam[num] : TheirTeam[num]) ); } inline void GetTeammateGlobalXY(int num, float *x, float *y) { GetPlayerGlobalXY( MySide, num, x, y ); } inline float GetTeammateGlobalX(int num) { return GetPlayerGlobalX( MySide, num); } inline float GetTeammateGlobalY(int num) { return GetPlayerGlobalY( MySide, num ); } inline void GetTeammateLastGlobalXY(int num, float *x, float *y) { GetPlayerLastGlobalXY( MySide, num, x, y ); } inline int GetTeammateGlobalSetTime(int num) { return GetPlayerGlobalSetTime( MySide, num ); } inline void GetOpponentGlobalXY(int num, float *x, float *y) { GetPlayerGlobalXY( TheirSide, num, x, y ); } inline float GetOpponentGlobalX(int num) { return GetPlayerGlobalX( TheirSide, num); } inline float GetOpponentGlobalY(int num) { return GetPlayerGlobalY( TheirSide, num ); } inline void GetOpponentLastGlobalXY(int num, float *x, float *y) { GetPlayerLastGlobalXY( TheirSide, num, x, y ); } inline int GetOpponentGlobalSetTime(int num) { return GetPlayerGlobalSetTime( TheirSide, num ); } inline void GetBallGlobalXY(float *x, float *y) { GetMobileGlobalXY( Ball, x, y ); } inline float GetBallGlobalX() { return GetMobileGlobalX( Ball ); } inline float GetBallGlobalY() { return GetMobileGlobalY( Ball ); } inline void GetTeammateHeardGlobalXY(int num, float *x, float *y) { MyTeam[num]->get_globalxy(x,y); } char MySide; // 'l' or 'r' char TheirSide; // 'l' or 'r' char *MyTeamName; // The name of my team char *TheirTeamName; // The name of my team int MyTeamNameLen; // strlen of MyTeamName int MyNumber; // uniform number int CurrentTime; // Most recently observed time int LastTime; // previous time Socket *sock; // default socket private: int ConvertMarker(int marker, float *x, float *y); /* get the x,y coords of marker */ inline int ConvertMarker(int marker) /* ignore the actual position of the marker */ { float x; return ConvertMarker(marker, &x, &x); } float overall_conf(); float triangulate(int m); // This is an array of all the objects, access to these objects // should be done through the more specific pointers below. // They point to the same objects. Position *objects[NUM_OBJECTS]; PositionStationary *Markers[NUM_MARKERS]; PositionMobile *Ball; PositionMobile *MyTeam[TEAM_SIZE + 1]; PositionMobile *TheirTeam[TEAM_SIZE + 1]; PositionMobile *ExtraPlayers[2*TEAM_SIZE]; /* The unidentified ones */ int NumExtraPlayers; int line; // This should be in the side-independent format float line_r, line_t; float global_angle, old_global_angle; // Zero is side-independent right float global_x, global_y; // (0,0) is center, (-X0,0) is my goal // (-X0,-Y0) is my right defensive flag float my_vel_x; /* relative to my heading*/ float my_vel_y; float my_vel_dir; float my_vel_mag; int turning; int dashing; /* float turning_angle;*/};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -