Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduWorld.cc

Go to the documentation of this file.
00001 // INCLUDES
00002 // tekkodu
00003 #include "Kodu/KoduWorld.h"
00004 #include "Kodu/General/GeneralFncs.h"
00005 
00006 // tekkotsu Library
00007 #include "DualCoding/Point.h"
00008 #include "DualCoding/ShapeFuns.h"
00009 #include "DualCoding/VRmixin.h"
00010 using namespace DualCoding;
00011 
00012 namespace Kodu {
00013 
00014     ScoreKeeper KoduWorld::globalScoreKeeper;
00015 
00016     KoduWorld::KoduWorld()
00017       : thisAgent(),
00018         shapeToTagMap(),
00019         starConstellation(),
00020         worldBoundsPolygon(),
00021         worldSideLength(2000.0f)    // 2 meters (area = 2m sq)
00022     { }
00023 
00024     //! Destructor
00025     KoduWorld::~KoduWorld() {
00026         // reinitialize score board
00027         globalScoreKeeper.initialize();
00028     }
00029     
00030     void KoduWorld::applyGlobalScoreChanges(std::queue<ScoreChange>& queue) {
00031         while (!queue.empty()) {
00032             const ScoreChange& change = queue.front();
00033             // apply the appropriate operation
00034             switch(change.operationType) {
00035                 // add score operation
00036                 case KoduActionScore::ST_SCORE:
00037                     globalScoreKeeper.addScore(change.designator, change.value);
00038                     break;
00039 
00040                 // set score operation
00041                 case KoduActionScore::ST_SET_SCORE:
00042                     globalScoreKeeper.setScore(change.designator, change.value);
00043                     break;
00044 
00045                 // subtract score operation
00046                 case KoduActionScore::ST_SUBTRACT:
00047                     globalScoreKeeper.subtractScore(change.designator, change.value);
00048                     break;
00049             }
00050             // pop the top element off
00051             queue.pop();
00052         }
00053     }
00054 
00055     int KoduWorld::getScoreValue(const std::string& kDesignator) {
00056         return globalScoreKeeper.checkScoreValue(kDesignator);
00057     }
00058 
00059     int KoduWorld::getTagIdForShape(int worldShapeId) {
00060         if (shapeTagPairExists(worldShapeId))
00061             return shapeToTagMap[worldShapeId];
00062         else
00063             return (-1);
00064     }
00065 
00066     void KoduWorld::pairShapeWithTag(int worldShapeId, int aprilTagId) {
00067         if (!shapeTagPairExists(worldShapeId)) {
00068             shapeToTagMap.insert(std::pair<int, int>(worldShapeId, aprilTagId));
00069         }
00070     }
00071 
00072     bool KoduWorld::shapeTagPairExists(int worldShapeId) const {
00073         return static_cast<bool>(shapeToTagMap.count(worldShapeId));
00074     }
00075 
00076     const std::map<int, Point>& KoduWorld::getStarConstellation() const {
00077         return starConstellation;
00078     }
00079 
00080     const Shape<PolygonData>& KoduWorld::getWorldBoundsPolygon() const {
00081         return worldBoundsPolygon;
00082     }
00083 
00084     void KoduWorld::setStarConstellation(const std::vector<ShapeRoot>& kConstellation) {
00085         for (std::size_t i = 0; i < kConstellation.size(); i++) {
00086             const Shape<AprilTagData>& kTag = ShapeRootTypeConst(kConstellation[i], AprilTagData);
00087             starConstellation.insert(std::pair<int, Point>(kTag->getTagID(), kTag->getCentroid()));
00088             std::cout << "inserted pair: {" << kTag->getTagID() << ", "
00089                 << kTag->getCentroid() << "}\n";
00090         }
00091     }
00092 
00093     void KoduWorld::generateWorldBoundsPolygon() {
00094         // create world bounds
00095         std::vector<Point> worldBounds;
00096         const float kSideLength = 2000.0f;   // assumes the world is a square (all sides are equal)
00097         const float kHalfSideLength = kSideLength / 2.0f;
00098         // float minX = 0.0f;
00099         // float maxX = 0.0f;
00100         // float minY = 0.0f;
00101         // float maxY = 0.0f;
00102 
00103         // create the max and min coordinates of the world bounds
00104         // const float maxX = northStarLocation.coordX();
00105         // const float minX = maxX - kSideLength;
00106         // const float maxY = northStarLocation.coordY() + kHalfSideLength;
00107         // const float minY = northStarLocation.coordY() - kHalfSideLength; // minY = maxY - kSideLength
00108         const float maxX = 1500.0f;
00109         const float minX = maxX - kSideLength;
00110         const float maxY = kHalfSideLength;
00111         const float minY = -1.0f * kHalfSideLength; // minY = maxY - kSideLength
00112 
00113         // add the points of the square polygon to the vector
00114         worldBounds.push_back(Point(minX, maxY, 0, allocentric)); // bottom left
00115         worldBounds.push_back(Point(maxX, maxY, 0, allocentric)); // top left
00116         worldBounds.push_back(Point(maxX, minY, 0, allocentric)); // top right
00117         worldBounds.push_back(Point(minX, minY, 0, allocentric)); // bottom right
00118         worldBounds.push_back(worldBounds[0]);  // close the polygon
00119         
00120         // create a Shape<PolygonData> object and use it as the world bounds.
00121         NEW_SHAPE(wBoundPolygon, PolygonData, new PolygonData(VRmixin::worldShS, worldBounds, true));
00122         worldBoundsPolygon = wBoundPolygon;
00123         worldBoundsPolygon->setName("worldBoundsPolygon");
00124         worldBoundsPolygon->setObstacle(true);
00125     }
00126 
00127 }

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