This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KoduWorld.cc
127 lines (107 loc) · 4.66 KB
/
KoduWorld.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// INCLUDES
// tekkodu
#include "Kodu/KoduWorld.h"
#include "Kodu/General/GeneralFncs.h"
// tekkotsu Library
#include "DualCoding/Point.h"
#include "DualCoding/ShapeFuns.h"
#include "DualCoding/VRmixin.h"
using namespace DualCoding;
namespace Kodu {
ScoreKeeper KoduWorld::globalScoreKeeper;
KoduWorld::KoduWorld()
: thisAgent(),
shapeToTagMap(),
starConstellation(),
worldBoundsPolygon(),
worldSideLength(2000.0f) // 2 meters (area = 2m sq)
{ }
//! Destructor
KoduWorld::~KoduWorld() {
// reinitialize score board
globalScoreKeeper.initialize();
}
void KoduWorld::applyGlobalScoreChanges(std::queue<ScoreChange>& queue) {
while (!queue.empty()) {
const ScoreChange& change = queue.front();
// apply the appropriate operation
switch(change.operationType) {
// add score operation
case KoduActionScore::ST_SCORE:
globalScoreKeeper.addScore(change.designator, change.value);
break;
// set score operation
case KoduActionScore::ST_SET_SCORE:
globalScoreKeeper.setScore(change.designator, change.value);
break;
// subtract score operation
case KoduActionScore::ST_SUBTRACT:
globalScoreKeeper.subtractScore(change.designator, change.value);
break;
}
// pop the top element off
queue.pop();
}
}
int KoduWorld::getScoreValue(const std::string& kDesignator) {
return globalScoreKeeper.checkScoreValue(kDesignator);
}
int KoduWorld::getTagIdForShape(int worldShapeId) {
if (shapeTagPairExists(worldShapeId))
return shapeToTagMap[worldShapeId];
else
return (-1);
}
void KoduWorld::pairShapeWithTag(int worldShapeId, int aprilTagId) {
if (!shapeTagPairExists(worldShapeId)) {
shapeToTagMap.insert(std::pair<int, int>(worldShapeId, aprilTagId));
}
}
bool KoduWorld::shapeTagPairExists(int worldShapeId) const {
return static_cast<bool>(shapeToTagMap.count(worldShapeId));
}
const std::map<int, Point>& KoduWorld::getStarConstellation() const {
return starConstellation;
}
const Shape<PolygonData>& KoduWorld::getWorldBoundsPolygon() const {
return worldBoundsPolygon;
}
void KoduWorld::setStarConstellation(const std::vector<ShapeRoot>& kConstellation) {
for (std::size_t i = 0; i < kConstellation.size(); i++) {
const Shape<AprilTagData>& kTag = ShapeRootTypeConst(kConstellation[i], AprilTagData);
starConstellation.insert(std::pair<int, Point>(kTag->getTagID(), kTag->getCentroid()));
std::cout << "inserted pair: {" << kTag->getTagID() << ", "
<< kTag->getCentroid() << "}\n";
}
}
void KoduWorld::generateWorldBoundsPolygon() {
// create world bounds
std::vector<Point> worldBounds;
const float kSideLength = 2000.0f; // assumes the world is a square (all sides are equal)
const float kHalfSideLength = kSideLength / 2.0f;
// float minX = 0.0f;
// float maxX = 0.0f;
// float minY = 0.0f;
// float maxY = 0.0f;
// create the max and min coordinates of the world bounds
// const float maxX = northStarLocation.coordX();
// const float minX = maxX - kSideLength;
// const float maxY = northStarLocation.coordY() + kHalfSideLength;
// const float minY = northStarLocation.coordY() - kHalfSideLength; // minY = maxY - kSideLength
const float maxX = 1500.0f;
const float minX = maxX - kSideLength;
const float maxY = kHalfSideLength;
const float minY = -1.0f * kHalfSideLength; // minY = maxY - kSideLength
// add the points of the square polygon to the vector
worldBounds.push_back(Point(minX, maxY, 0, allocentric)); // bottom left
worldBounds.push_back(Point(maxX, maxY, 0, allocentric)); // top left
worldBounds.push_back(Point(maxX, minY, 0, allocentric)); // top right
worldBounds.push_back(Point(minX, minY, 0, allocentric)); // bottom right
worldBounds.push_back(worldBounds[0]); // close the polygon
// create a Shape<PolygonData> object and use it as the world bounds.
NEW_SHAPE(wBoundPolygon, PolygonData, new PolygonData(VRmixin::worldShS, worldBounds, true));
worldBoundsPolygon = wBoundPolygon;
worldBoundsPolygon->setName("worldBoundsPolygon");
worldBoundsPolygon->setObstacle(true);
}
}