📄 objects.cpp
字号:
/*Copyright (c) 2000-2003, Jelle Kok, University of AmsterdamAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the University of Amsterdam nor the names of itscontributors may be used to endorse or promote products derived from thissoftware without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//*! \file Objects.cpp<pre><b>File:</b> Objects.cpp<b>Project:</b> Robocup Soccer Simulation Team: UvA Trilearn<b>Authors:</b> Jelle Kok<b>Created:</b> 1/12/2000<b>Last Revision:</b> $ID$<b>Contents:</b> class declarations Object, DynamicObject, FixedObject, PlayerObject, BallObject and Stamina<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>1/12/2001 Jelle Kok Initial version created</pre>*/#include"Objects.h"#include<stdlib.h> // needed for free#include<iostream> // needed for cout#ifdef Solaris #include <strings.h> // needed for strdup#else #include <string.h> // needed for strdup#endif/*****************************************************************************//********************* CLASS OBJECT ******************************************//*****************************************************************************//*! This constructor creates an object, all variables are initialized by default (illegal) values */Object::Object( ){ objectType = OBJECT_ILLEGAL;}/*! This method returns the relative angle of this object to the agent. This equals the angle of the relative position vector. \return relative angle to this object */AngDeg Object::getRelativeAngle( ){ return VecPosition::normalizeAngle(posRelative.getDirection());}/*! This method returns the relative distance to this object. This equals the magnitude of the relative position vector. \return relative distance to this object */double Object::getRelativeDistance( ){ return posRelative.getMagnitude();}/*! This method returns the confidence of the information of this object. The confidence is related to the last time this object was seen and the specified time (normally the time of the last received message). \param time current time to compare with time object was last seen \return confidence factor of this object */double Object::getConfidence( Time time ){ if( timeLastSeen.getTime() == -1 ) return 0.0; double dConf = max( 0.0, 1.0-(double)(time.getTimeDifference(timeLastSeen))/100.0); if( dConf > 1.0 ) return 0.0; return dConf;}/*! This method sets the type of this object (i.e. OBJECT_BALL, FLAG_L_R_T). \param o ObjectT representing the type of this object \return bool indicating whether value was set. */bool Object::setType( ObjectT o ){ objectType = o; return true;}/*! This method returns the type of this object. \return type of this object */ObjectT Object::getType() const{ return objectType;}/*! This method sets the relative position and the time this information was received. The relative position is calculated using the given distance and the given (relative) angle. \param dDist relative distance to object \param ang relative angle to object \param time time relative position was received \return bool indicating whether the values were set */bool Object::setRelativePosition( double dDist, AngDeg ang, Time time ){ posRelative.setVecPosition( dDist, ang, POLAR ); setTimeRelativePosition( time ); return true;}/*! This method sets the relative position and the time this information was received using a vecPosition. \param p new relative position \param time time relative position was received \return bool indicating whether the values were set */bool Object::setRelativePosition( VecPosition v, Time time ){ posRelative = v; setTimeRelativePosition( time ); return true;}/*! This method returns the relative position of this object. The time of this information is related to the time returned by getTimeRelativePosition(), but is not checked. So if you want to know the relevance of this position use this method. \return relative position of this object */VecPosition Object::getRelativePosition() const{ return posRelative;}/*! This method sets the time the relative position was received. \param time time relative position was received \return bool indicating whether the value was set */bool Object::setTimeRelativePosition( Time time ){ timeRelativePosition = time; return true;}/*! This method returns the time that corresponds to the relative position of this object. \return time of the relative position of this object */Time Object::getTimeRelativePosition() const{ return timeRelativePosition;}/*! This method sets the global position and the time this information was calculated. \param p new global position \param time time global position was received \return bool indicating whether the values were set */bool Object::setGlobalPosition( VecPosition p, Time time ){ posGlobal = p; setTimeGlobalPosition( time ); return true;}/*! This method returns the global position of this object. The time of this information is related to the time returned by getTimeGlobalPosition(), but is not checked. So if you want to know the relevance of this position use this method. \return global position of this object */VecPosition Object::getGlobalPosition() const{ return posGlobal;}/*! This method sets the time the global position was calculated \param time time global position was calculated \return bool indicating whether the value was set */bool Object::setTimeGlobalPosition( Time time ){ timeGlobalPosition = time; return true;}/*! This method returns the time that corresponds to the global position of this object. \return time of the global position of this object */Time Object::getTimeGlobalPosition() const{ return timeGlobalPosition;}/*! This method sets the global position calculated using the last see message and the time of this see message. This opposed to the "normal" global position that is also updated when no see message has arrived in a new cycle. \param p new global position \param time time global position was received \return bool indicating whether the values were set */bool Object::setGlobalPositionLastSee( VecPosition p, Time time ){ posGlobalLastSee = p; setTimeGlobalPosDerivedFromSee( time ); return true;}/*! This method returns the global position of this object at the time of the last see message. The time of this information is related to the time returned by getTimeGlobalPosDerivedFromSee(). \return global position of this object */VecPosition Object::getGlobalPositionLastSee() const{ return posGlobalLastSee;}/*! This method sets the time the global position was calculated using a see message. \param time time global position was calculated with see message \return bool indicating whether the value was set */bool Object::setTimeGlobalPosDerivedFromSee( Time time ){ timeGlobalPosDerivedFromSee = time; return true;}/*! This method returns the time that the global position was calculated using a see message. \return time of the global position of this object during the last see*/Time Object::getTimeGlobalPosDerivedFromSee() const{ return timeGlobalPosDerivedFromSee;}/*! This method sets the time of the last see message in which this object was seen. \param time time this object was last seen \return bool indicating whether the value was set */bool Object::setTimeLastSeen( Time time){ timeLastSeen = time; return true;}/*! This method returns the time that corresponds to the time this object was located in the last see message. \return time of the last see message that was used to update this object */Time Object::getTimeLastSeen() const{ return timeLastSeen;}/*****************************************************************************//********************** CLASS FIXEDOBJECT ************************************//*****************************************************************************//*! This method prints all the information about this FixedObject to the specified output stream \param os output stream to print all relevant information to. */void FixedObject::show( ostream & os ){ char buf[MAX_TEAM_NAME_LENGTH]; // DEFAULT_TEAM_NAME is used since it is not a player, name does not matter SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME ); os << buf << " rel(" << posRelative << " r:" << posRelative.getMagnitude() << " phi:" << posRelative.getDirection() << " t:" << timeRelativePosition << ")" << " seen:" << timeLastSeen << "\n";}/*! This method returns the global position of this fixed object. Only works when the object type equals a flag or a goal. Furthermore the side of the agent has to be passed since the global positions differ for the left and the right side. For some flags the size of the goal is important. So this value can be passed also. Otherwise the default value is 14.02. \param s side of agent (global position differs for left and right side) \param dGoalWidth width of a goal, needed for pole objects next to goal \return global position of this fixed object. */VecPosition FixedObject::getGlobalPosition( SideT s, double dGoalWidth )const{ return SoccerTypes::getGlobalPositionFlag( getType(), s, dGoalWidth );}/*! This methods returns the global angle of this fixed object in the world. Only works when the fixed object is a line. The angle for the left team rises clockwise, i.e. left=0, bottom=90, etc. For the right team this is counterclockwise: right=0, top=90, etc) \param s side of agent (angles differ for left and right side) \return global angle of this line in the world. */AngDeg FixedObject::getGlobalAngle( SideT s ){ return SoccerTypes::getGlobalAngleLine( getType(), s );}/*****************************************************************************//********************* CLASS DYNAMICOBJECT ***********************************//*****************************************************************************//*! This is the constructor for DynamicObject. A DynamicObject is created with all the variables initialized by (illegal) default values */DynamicObject::DynamicObject( ):Object( ){ dRelativeDistanceChange = UnknownDoubleValue; dRelativeAngleChange = UnknownDoubleValue;}/*! This method sets the global velocity of this object and the time of this information \param v new global velocity \param time time global velocity was received \return bool indicating whether the values were set */bool DynamicObject::setGlobalVelocity( VecPosition v, Time time){ if( v.getMagnitude() < EPSILON ) vecGlobalVelocity.setVecPosition( 0.0, 0.0 ); else vecGlobalVelocity = v; setTimeGlobalVelocity( time ); return true;}/*! This method returns the global velocity of this object. The time of this information is related to the time returned by getTimeGlobalVelocity(). \return global position of this object */VecPosition DynamicObject::getGlobalVelocity( ) const{ return vecGlobalVelocity;}/*! This method returns the speed of this object. The speed is the magnitude of the global velocity of the object \return speed of this object (zero for non-moving objects) */double DynamicObject::getSpeed( ) const{ return vecGlobalVelocity.getMagnitude();}/*! This method sets the time that corresponds to the last update of the global velocity of this object. \param time time corresponding to current value of global velocity \return bool indicating whether the value was set */bool DynamicObject::setTimeGlobalVelocity( Time time ){ timeGlobalVelocity = time; return true;}/*! This method returns the time that belongs to the global velocity of this object. \return time of the global velocity of this object */Time DynamicObject::getTimeGlobalVelocity() const{ return timeGlobalVelocity;}/*! This method sets the relative distance change and the time this information was calculated. \param d new relative distance change \param time time relative distance change was calculated \return bool indicating whether the values were set */bool DynamicObject::setRelativeDistanceChange( double d, Time time ){ dRelativeDistanceChange = d; setTimeChangeInformation( time ); return true;}/*! This method returns the relative distance change of this object. Note that this value is zero when object is at the same distance, but at a complete different angle. This occurs when an object has moved a lot in one cycle. This information belongs to the server time that is returned by getTimeChangeInformation(). \return relative distance change of object in the last cycle */double DynamicObject::getRelativeDistanceChange() const{ return dRelativeDistanceChange;}/*! This method sets the relative angle change and the server time this information belongs to. \param d new relative angle change \param time time relative angle change was received \return bool indicating whether the values were set */bool DynamicObject::setRelativeAngleChange( double d, Time time ){ dRelativeAngleChange = d; setTimeChangeInformation( time ); return true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -