00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef RCSC_PLAYER_BALL_OBJECT_H
00033 #define RCSC_PLAYER_BALL_OBJECT_H
00034
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/game_time.h>
00037 #include <rcsc/soccer_math.h>
00038 #include <rcsc/math_util.h>
00039
00040 #include <deque>
00041
00042 namespace rcsc {
00043
00044 class GameMode;
00045 class ActionEffector;
00046 class SelfObject;
00047
00059 class BallObject {
00060 private:
00062 static int S_pos_count_thr;
00064 static int S_rpos_count_thr;
00066 static int S_vel_count_thr;
00067
00069 double M_dist_from_self;
00071 AngleDeg M_angle_from_self;
00072
00074 Vector2D M_pos;
00076 Vector2D M_pos_error;
00078 int M_pos_count;
00079
00081 Vector2D M_rpos;
00083 Vector2D M_rpos_error;
00085 int M_rpos_count;
00087 Vector2D M_rpos_prev;
00088
00090 Vector2D M_seen_pos;
00092 int M_seen_pos_count;
00094 Vector2D M_seen_rpos;
00095
00097 Vector2D M_heard_pos;
00099 int M_heard_pos_count;
00100
00102 Vector2D M_vel;
00104 Vector2D M_vel_error;
00106 int M_vel_count;
00107
00109 Vector2D M_seen_vel;
00111 int M_seen_vel_count;
00112
00114 Vector2D M_heard_vel;
00116 int M_heard_vel_count;
00117
00119 int M_lost_count;
00120
00122 GameTime M_ghost_time;
00123
00124
00125
00126 public:
00130 BallObject();
00131
00138 static
00139 void set_count_thr( const int pos_thr,
00140 const int rpos_thr,
00141 const int vel_thr );
00142
00147 const
00148 double & distFromSelf() const
00149 {
00150 return M_dist_from_self;
00151 }
00156 const
00157 AngleDeg & angleFromSelf() const
00158 {
00159 return M_angle_from_self;
00160 }
00161
00166 const
00167 Vector2D & pos() const
00168 {
00169 return M_pos;
00170 }
00171
00176 const
00177 Vector2D & posError() const
00178 {
00179 return M_pos_error;
00180 }
00181
00186 const
00187 int posCount() const
00188 {
00189 return M_pos_count;
00190 }
00191
00196 const
00197 Vector2D & rpos() const
00198 {
00199 return M_rpos;
00200 }
00201
00206 const
00207 Vector2D & rposError() const
00208 {
00209 return M_rpos_error;
00210 }
00211
00216 const
00217 int rposCount() const
00218 {
00219 return M_rpos_count;
00220 }
00221
00226 const
00227 Vector2D & rposPrev() const
00228 {
00229 return M_rpos_prev;
00230 }
00231
00236 const
00237 Vector2D & seenPos() const
00238 {
00239 return M_seen_pos;
00240 }
00241
00246 int seenPosCount() const
00247 {
00248 return M_seen_pos_count;
00249 }
00250
00255 const
00256 Vector2D & seenRPos() const
00257 {
00258 return M_seen_rpos;
00259 }
00260
00265 const
00266 Vector2D & heardPos() const
00267 {
00268 return M_heard_pos;
00269 }
00270
00275 int heardPosCount() const
00276 {
00277 return M_heard_pos_count;
00278 }
00279
00284 const
00285 Vector2D & vel() const
00286 {
00287 return M_vel;
00288 }
00289
00294 const
00295 Vector2D & velError() const
00296 {
00297 return M_vel_error;
00298 }
00299
00304 int velCount() const
00305 {
00306 return M_vel_count;
00307 }
00312 const
00313 Vector2D & seenVel() const
00314 {
00315 return M_seen_vel;
00316 }
00317
00322 int seenVelCount() const
00323 {
00324 return M_seen_vel_count;
00325 }
00326
00331 int lostCount() const
00332 {
00333 return M_lost_count;
00334 }
00335
00340 const
00341 GameTime & ghostTime() const
00342 {
00343 return M_ghost_time;
00344 }
00345
00350 bool posValid() const
00351 {
00352 return M_pos_count < S_pos_count_thr;
00353 }
00354
00359 bool rposValid() const
00360 {
00361 return M_rpos_count < S_rpos_count_thr;
00362 }
00363
00368 bool velValid() const
00369 {
00370 return M_vel_count < S_vel_count_thr;
00371 }
00372
00377 void setGhost( const GameTime & current );
00378
00385 void update( const ActionEffector & act,
00386 const GameMode & game_mode,
00387 const GameTime & current );
00388
00395 void updateByFullstate( const Vector2D & pos,
00396 const Vector2D & vel,
00397 const Vector2D & self_pos );
00398 private:
00404 void updateWindEffect();
00405
00406 public:
00418 void updateByCollision( const Vector2D & pos,
00419 const int pos_count,
00420 const Vector2D & rpos,
00421 const int rpos_count,
00422 const Vector2D & vel,
00423 const int vel_count );
00424
00430 void updateOnlyRelativePos( const Vector2D & rpos,
00431 const Vector2D & rpos_err );
00432
00439 void updateOnlyVel( const Vector2D & vel,
00440 const Vector2D & vel_err,
00441 const int vel_count );
00442
00446 void setOpponentControlEffect();
00447
00457 void updatePos( const Vector2D & pos,
00458 const Vector2D & pos_err,
00459 const int pos_count,
00460 const Vector2D & rpos,
00461 const Vector2D & rpos_err );
00462
00475 void updateAll( const Vector2D & pos,
00476 const Vector2D & pos_err,
00477 const int pos_count,
00478 const Vector2D & rpos,
00479 const Vector2D & rpos_err,
00480 const Vector2D & vel,
00481 const Vector2D & vel_err,
00482 const int vel_count );
00483
00492 void updateByHear( const Vector2D & heard_pos,
00493 const Vector2D & heard_vel,
00494 const GameTime & current );
00495
00502 void updateSelfRelated( const SelfObject & self );
00503
00504
00505
00506
00512 template < typename REGION >
00513 bool isWithin( const REGION & region ) const
00514 {
00515 return region.contains( this->pos() );
00516 }
00517
00518
00519
00525 Vector2D inertiaTravel( const int cycle ) const;
00526
00532 Vector2D inertiaPoint( const int cycle ) const;
00533
00538 Vector2D inertiaFinalTravel() const;
00539
00544 Vector2D inertiaFinalPoint() const;
00545
00550 static
00551 double calc_travel_step( const double & distance,
00552 const double & first_speed );
00553
00554 };
00555
00557 typedef std::deque< BallObject > BallRecord;
00558
00559 }
00560
00561 #endif