LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
view_area.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_PLAYER_VIEW_AREA_H
33#define RCSC_PLAYER_VIEW_AREA_H
34
35#include <rcsc/geom/vector_2d.h>
36#include <rcsc/geom/angle_deg.h>
37#include <rcsc/game_time.h>
38
39#include <deque>
40#include <cmath>
41
42namespace rcsc {
43
48class ViewArea {
49private:
50 double M_view_width;
51 Vector2D M_origin;
52 AngleDeg M_angle;
53 GameTime M_time;
54
55public:
56
61 : M_view_width( -1.0 )
62 , M_origin( Vector2D::INVALIDATED )
63 , M_angle()
64 , M_time( -1, 0 )
65 { }
66
71 explicit
72 ViewArea( const GameTime & t )
73 : M_view_width( -1.0 )
74 , M_origin( Vector2D::INVALIDATED )
75 , M_angle()
76 , M_time( t )
77 { }
78
79
87 ViewArea( const double & view_width,
88 const Vector2D & origin,
89 const AngleDeg & angle,
90 const GameTime & t )
91 : M_view_width( view_width )
92 , M_origin( origin )
93 , M_angle( angle )
94 , M_time( t )
95 { }
96
101 const
102 double & viewWidth() const
103 {
104 return M_view_width;
105 }
106
111 const
112 Vector2D & origin() const
113 {
114 return M_origin;
115 }
116
121 const
122 AngleDeg & angle() const
123 {
124 return M_angle;
125 }
126
131 const
132 GameTime & time() const
133 {
134 return M_time;
135 }
136
141 bool isValid() const
142 {
143 return M_view_width > 0.0;
144 }
145
152 bool contains( const Vector2D & point,
153 const double & dir_thr,
154 const double & visible_dist2 ) const
155 {
156 if ( ! isValid() )
157 {
158 return false;
159 }
160
161 Vector2D rpos( point - origin() );
162 if ( rpos.r2() < visible_dist2 )
163 {
164 return true;
165 }
166
167 return ( rpos.th() - M_angle ).abs() < M_view_width*0.5 - dir_thr;
168 }
169};
170
172typedef std::deque< ViewArea > ViewAreaCont;
173
174}
175
176#endif
degree wrapper class Header File.
degree wrapper class
Definition: angle_deg.h:45
game time object
Definition: game_time.h:43
2D point vector class
Definition: vector_2d.h:46
AngleDeg th() const
get the angle of vector.
Definition: vector_2d.h:192
double r2() const
get the squared length of vector.
Definition: vector_2d.h:137
player's view area.
Definition: view_area.h:48
bool contains(const Vector2D &point, const double &dir_thr, const double &visible_dist2) const
check if point is contained by this view area or not
Definition: view_area.h:152
const GameTime & time() const
get the game time when this information is generated
Definition: view_area.h:132
ViewArea(const GameTime &t)
construct invalid object
Definition: view_area.h:72
const Vector2D & origin() const
get player's global position when see message is received.
Definition: view_area.h:112
ViewArea()
construct invalid object
Definition: view_area.h:60
const AngleDeg & angle() const
get player's head angle when see message is received.
Definition: view_area.h:122
ViewArea(const double &view_width, const Vector2D &origin, const AngleDeg &angle, const GameTime &t)
construct with all variables
Definition: view_area.h:87
const double & viewWidth() const
get the width of view area
Definition: view_area.h:102
bool isValid() const
check if this object is valid or not
Definition: view_area.h:141
game time depending on RCSSServer2D Header File
2d vector class Header File.
std::deque< ViewArea > ViewAreaCont
typedef of the ViewArea container
Definition: view_area.h:172