00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TG_CONTROLLERPC_H
00019 #define TG_CONTROLLERPC_H
00020
00021 #include "Controller.h"
00022 #include "Util2D.h"
00023
00024 namespace tagGame
00025 {
00027 template<class T>
00028 class ControllerPC : public Controller
00029 {
00030 public:
00031 ControllerPC(PerceptionPtr perception);
00032 virtual ~ControllerPC();
00033
00034 bool init();
00035
00036 virtual void calcAction();
00037
00038 protected:
00039 private:
00040 T joystick;
00041 };
00042
00043 template<class T>
00044 ControllerPC<T>::ControllerPC(PerceptionPtr perception) :
00045 Controller(perception)
00046 {
00047 }
00048
00049 template<class T>
00050 ControllerPC<T>::~ControllerPC()
00051 {
00052 }
00053
00054 template<class T>
00055 bool ControllerPC<T>::init()
00056 {
00057 return joystick.init();
00058 }
00059
00060 template<class T>
00061 void ControllerPC<T>::calcAction()
00062 {
00063 RealVec v(Util2D::dim);
00064 v[0] = joystick.getX();
00065 v[1] = joystick.getY();
00066
00067 if (v.isAlmostZero())
00068 {
00069
00070 action.setDesiredSpeed(Real(0));
00071 }
00072 else
00073 {
00074 action.setDesiredSpeed(std::min(1.0, v.length()));
00075 v.normalize();
00076 action.setDesiredDirection(v);
00077 }
00078 }
00079 }
00080
00081 #endif