Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WaypointList.cc

Go to the documentation of this file.
00001 #include "WaypointList.h"
00002 #include "Shared/mathutils.h"
00003 
00004 const float WaypointList::defaultTurnSpeed = float(M_PI/30);
00005 
00006 void Waypoint::apply(const Waypoint& next, float eps[]) {
00007   float origx=x;
00008   float origy=y;
00009   switch(next.posType) {
00010     case Waypoint::POSTYPE_EGOCENTRIC: {
00011       x+=next.x*std::cos(angle)-next.y*std::sin(angle);
00012       y+=next.x*std::sin(angle)+next.y*std::cos(angle);
00013       break;
00014     }
00015     case Waypoint::POSTYPE_OFFSET:
00016       x+=next.x;
00017       y+=next.y;
00018       break;
00019     case Waypoint::POSTYPE_ABSOLUTE:
00020       x=next.x;
00021       y=next.y;
00022       break;
00023   }
00024   float dx=x-origx;
00025   float dy=y-origy;
00026   if(fabs(dx)<eps[0] && fabs(dy)<eps[1]) { //turn in place
00027     if(next.angleIsRelative)
00028       angle+=next.angle;
00029     else
00030       angle=next.angle;
00031   } else { //move at heading
00032     angle=next.angle;
00033     if(next.angleIsRelative)
00034       angle+=std::atan2(dy,dx);
00035   }
00036   angle+=next.arc/2;
00037   angle=mathutils::normalizeAngle(angle);
00038 }
00039 
00040 /*! This is replicated from WaypointEngine, so any modifications here should be replicated there... */
00041 Waypoint WaypointList::calcAbsoluteCoords(const_iterator it) {
00042   float eps[] = { 5, 5, 0.0175f };
00043   Waypoint cur(0,0,Waypoint::POSTYPE_ABSOLUTE,0,false,0,false,defaultTurnSpeed);
00044   for(const_iterator c=begin(); c!=end(); c++ ) {
00045     cur.apply(*c,eps);
00046     if(c==it)
00047       break;
00048   }
00049   return cur;
00050 }
00051 
00052 /*! This is adapted from WaypointEngine::fixArc(), so any modifications here should be replicated there... */
00053 void WaypointList::fixArc(float arc) {
00054   Waypoint& center=back();
00055   float cdx=center.x; //center delta
00056   float cdy=center.y; //center delta
00057   if(center.posType==Waypoint::POSTYPE_ABSOLUTE) {
00058     //have to find location of waypoint before last one
00059     if(size()<=1) {
00060       // no-op
00061     } else {
00062       Waypoint start=calcAbsoluteCoords(end()-2);
00063       cdx-=start.x;
00064       cdy-=start.y;
00065     }
00066   }
00067   float r=std::sqrt(cdx*cdx+cdy*cdy); //radius of circle
00068   float ca=std::atan2(cdy,cdx); //angle to center of circle
00069   center.x-=r*std::cos(ca-arc); //now x is the endpoint
00070   center.y-=r*std::sin(ca-arc); //now y is the endpoint
00071   center.arc=arc;
00072 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3