view_area.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_VIEW_AREA_H
00033 #define RCSC_PLAYER_VIEW_AREA_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/geom/angle_deg.h>
00037 #include <rcsc/game_time.h>
00038 
00039 #include <deque>
00040 #include <cmath>
00041 
00042 namespace rcsc {
00043 
00048 class ViewArea {
00049 private:
00050     double M_view_width; 
00051     Vector2D M_origin; 
00052     AngleDeg M_angle; 
00053     GameTime M_time; 
00054 
00055 public:
00056 
00060     ViewArea()
00061         : M_view_width( -1.0 )
00062         , M_origin( Vector2D::INVALIDATED )
00063         , M_angle()
00064         , M_time( -1, 0 )
00065       { }
00066 
00071     explicit
00072     ViewArea( const GameTime & t )
00073         : M_view_width( -1.0 )
00074         , M_origin( Vector2D::INVALIDATED )
00075         , M_angle()
00076         , M_time( t )
00077       { }
00078 
00079 
00087     ViewArea( const double & view_width,
00088               const Vector2D & origin,
00089               const AngleDeg & angle,
00090               const GameTime & t )
00091         : M_view_width( view_width )
00092         , M_origin( origin )
00093         , M_angle( angle )
00094         , M_time( t )
00095       { }
00096 
00101     const
00102     double & viewWidth() const
00103       {
00104           return M_view_width;
00105       }
00106 
00111     const
00112     Vector2D & origin() const
00113       {
00114           return M_origin;
00115       }
00116 
00121     const
00122     AngleDeg & angle() const
00123       {
00124           return M_angle;
00125       }
00126 
00131     const
00132     GameTime & time() const
00133       {
00134           return M_time;
00135       }
00136 
00141     bool isValid() const
00142       {
00143           return M_view_width > 0.0;
00144       }
00145 
00146     /*
00147       \brief check if point is contained by this view area or not
00148       \param point checked point
00149       \param dir_thr angle threshold value
00150       \param visible_dist2 squared visible distance value
00151      */
00152     bool contains( const Vector2D & point,
00153                    const double & dir_thr,
00154                    const double & visible_dist2 ) const
00155       {
00156           if ( ! isValid() )
00157           {
00158               return false;
00159           }
00160 
00161           Vector2D rpos( point - origin() );
00162           if ( rpos.r2() < visible_dist2 )
00163           {
00164               return true;
00165           }
00166 
00167           return ( rpos.th() - M_angle ).abs() < M_view_width*0.5 - dir_thr;
00168       }
00169 };
00170 
00172 typedef std::deque< ViewArea > ViewAreaCont;
00173 
00174 }
00175 
00176 #endif

librcscに対してThu May 1 15:41:21 2008に生成されました。  doxygen 1.5.0