?? action.h
字號:
/***************************************************************************************** * SEU-3D * ------------------------------------------------- * Copyright (c) 2005, Yuan XU<xychn15@yahoo.com.cn>,Chang'e SHI<evelinesce@yahoo.com.cn> * Copyright (c) 2006, Yuan XU<xuyuan.cn@gmail.com>,Chunlu JIANG<JamAceWatermelon@gmail.com> * Southeast University ,China * All rights reserved. * * Additionally,this program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************************************//** * @flie Action.h * * @brief 對agent基本動作的封裝/the wrapper of agent's basic actions * *LastModify: * $Id: Action.h,v 1.1.1.1 2006/09/15 02:03:05 Administrator Exp $ */ #ifndef _ACTION_H#define _ACTION_H#ifdef __cplusplusextern "C"{#endif#ifdef __cplusplus}#endif#include "Settings.h"#include <set>#include <map>#include "Geometry.h"using namespace salt;/** 枚舉基本動作/enum all the basic actions */enum BasicActionType{ BAT_ILLEGAL = 0,/**< 非法動作 */ BAT_DRIVE = 1,/**< 跑/drive */ BAT_KICK = 2,/**< 踢/kick */ BAT_BEAM = 4,/**< 傳送/beam */ BAT_PANTILT = 5,/**< 轉頭/pantilt */ BAT_SAY = 6,/**< 說/say */ BAT_CATCH = 7 /**< 抓球(守門員[1號])/catch the ball(only the goalie[num 1]) */};struct BasicActionData{ Vector3f _vec; //string _msg; BasicActionData(){}; BasicActionData( const Vector3f& vec ):_vec(vec){}; //BasicActionData( const string& msg ):_msg(msg){};};/*************************************************************//********************* ACTION ********************************//*************************************************************/class Action{public: typedef std::map<BasicActionType, BasicActionData> ActionMap; /*===========================*/ /* 公有函數/Public Functions */ /*===========================*/ /** 缺省構造函數/default Constructor */ explicit Action():_time(0){}; /** 析構函數/Destructors */ ~Action(){} /** @name 設置動作/set the action */ /** 設置動作執行的時間/set the action execution time */ void setTime( Time time ){ _time = time; } /** 設置為drive動作 */ void setDriveForce( const Vector3f& driveForce ) { _action[BAT_DRIVE] = BasicActionData(driveForce); } /** 設置為kick動作 */ void setKick( AngDeg kickAngle, float kickForce ) { _action[BAT_KICK] = BasicActionData(Vector3f(kickAngle,kickForce,0.0f)); } /** 設置kick力量,如果該動作存在的話 */ bool setKickForce( float kickForce ) { ActionMap::iterator iter = _action.find(BAT_KICK); if ( iter == _action.end() ) return false; iter->second._vec.y() = kickForce; return true;} /** 設置kick豎直角度,如果該動作存在的話 */ bool setKickAng ( AngDeg kickAngle ) { ActionMap::iterator iter = _action.find(BAT_KICK); if ( iter == _action.end() ) return false; iter->second._vec.x() = kickAngle; return true;} /** 設置為beam動作 */ void setBeam( const Vector3f& driveForce ) { _action[BAT_BEAM] = BasicActionData(driveForce); } /** 設置為pantilt動作 */ void setPanTiltDelta( AngDeg panDelta, AngDeg tiltDelta ) { _action[BAT_PANTILT] = BasicActionData(Vector3f(panDelta,tiltDelta,0.0f)); } /** 設置pantilt水平角度改變,如果該動作存在的話 */ bool setPanDelta( AngDeg panDelta ) { ActionMap::iterator iter = _action.find(BAT_PANTILT); if ( iter == _action.end() ) return false; iter->second._vec.x() = panDelta; return true;} /** 設置pantilt水平角度改變,如果該動作存在的話 */ bool setTiltDelta( AngDeg tiltDelta ) { ActionMap::iterator iter = _action.find(BAT_PANTILT); if ( iter == _action.end() ) return false; iter->second._vec.y() = tiltDelta; return true;} /** 設置為say動作 */ void setSay() { _action[BAT_SAY] = BasicActionData(); } /** 設置為catch動作 */ void setCatch() { _action[BAT_CATCH] = BasicActionData(); } /** @name 獲取動作相關信息/get the info of the action */ /** 獲取動作執行時間/get the action execution time */ Time getTime()const { return _time; } /** 獲取drive力量 */ const Vector3f& getDriveForce() const { ActionMap::const_iterator iter = _action.find(BAT_DRIVE); if ( iter == _action.end() ) return vector3f_illegal; return iter->second._vec; } /** 獲取kick豎直角度 */ AngDeg getKickAngle()const { ActionMap::const_iterator iter = _action.find(BAT_KICK); if ( iter == _action.end() ) return max_kick_angle; return iter->second._vec.x(); } /** 獲取kick力量 */ float getKickForce()const { ActionMap::const_iterator iter = _action.find(BAT_KICK); if ( iter == _action.end() ) return max_kick_force; return iter->second._vec.y(); } /** test if execute the kick action * @param[in] t the test time * @return boolen indicates if kicking */ bool isKicking()const { return _action.find(BAT_KICK)!=_action.end(); } //AngDeg getPanDelta() const { return _panDelta; } //AngDeg getTiltDelta() const { return _tiltDelta; } /** 獲取動作map的首迭代器/get the begin const_iterator of the action map */ ActionMap::const_iterator begin()const{ return _action.begin(); } /** 獲取動作map的尾迭代器/get the end const_iterator of the action map */ ActionMap::const_iterator end()const{ return _action.end(); } /** @name 重載操作符/overload operators */ Action operator+ ( const Action &anotherAction ) const; Action& operator+= ( const Action &anotherAction); Action& operator-= ( const BasicActionType type); /** 下面這些函數不推薦使用,只是為了兼容舊的代碼 */ //void setActionType ( ActionT type ) const{;} private: /*===========================*/ /* 私有成員/Private Attributes */ /*===========================*/ /** 動作執行的時間/the action execution time */ Time _time; /** 動作所需要的數據 */ ActionMap _action;};/*************************************************************//********************* ACTION DEQUE **************************//*************************************************************/class ActionDeque{private: deque<Action> _actions;public: ActionDeque(){}; ActionDeque(const Action& act){ pushAction(act); } void pushAction( const ActionDeque &actions); void pushAction( const Action &a ); const Action& getAction( Time time )const; set<Time> getActionDequeTime()const; bool popAction( Time time, Action& action ); Action popAction(); bool isIncludeTime( Time time)const; bool isEmpty() const; const deque<Action>& get() const { return _actions; } ActionDeque& operator= ( const ActionDeque &another ); template < class T > ActionDeque& operator+= ( const T &newAction ) { pushAction(newAction); return *this; } /** 移除所有該類型的動作/remove all the type of aciton */ ActionDeque& operator-= ( BasicActionType type ); /** remove the action before the given time */ ActionDeque& operator-= ( Time t ); bool removeNoNeedAction(bool isKickable); /** test if execute the kick action * @param[in] t the test time * @return boolen indicates if kicking */ bool isKicking(Time t)const;};typedef ActionDeque Actions;#endif /* _ACTION_H */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -