-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.cpp
More file actions
98 lines (79 loc) · 2.61 KB
/
simulator.cpp
File metadata and controls
98 lines (79 loc) · 2.61 KB
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
#include "simulator.h"
#include <qtimer.h>
#include <qobject.h>
#include <qtimeline.h>
#include <qbasictimer.h>
#include <QTimerEvent>
#include "async.h"
#include <iostream>
#include "messages_robocup_ssl_wrapper.pb.h"
#include "messages_robocup_ssl_detection.pb.h"
#include "messages_robocup_ssl_geometry.pb.h"
Simulator::Simulator(QGraphicsScene *scene, QObject *parent): QObject(parent), timerId(0), scene(scene){
// Define the gravity vector.
b2Vec2 gravity(0.0f,-0.0f);
world = new b2World(gravity,true);
b2BodyDef bodyDef;
b2PolygonShape shapeDef;
b2FixtureDef fixtureDef;
bodyDef.position.Set(0,-2.7);
shapeDef.SetAsBox(3.7,0.01f);
fixtureDef.shape = &shapeDef;
groundBody = world->CreateBody(&bodyDef);
groundBody->CreateFixture(&fixtureDef);
// bodyDef.position.Set(0,0);
// shapeDef.SetAsBox(3.7,0.01f);
// fixtureDef.shape = &shapeDef;
// groundBody = world->CreateBody(&bodyDef);
// groundBody->CreateFixture(&fixtureDef);
//
// Async hello;
// hello.Receive("127.0.0.1",30011);
// hello.show();
// hello.hide();
// bodyDef.position.Set(0,0);
// shapeDef.SetAsBox(0.01f,2.7f);
// fixtureDef.shape = &shapeDef;
// groundBody = world->CreateBody(&bodyDef);
// groundBody->CreateFixture(&fixtureDef);
// bodyDef.position.Set(3.7f,0);
// shapeDef.SetAsBox(3.7f,2.7f);
// fixtureDef.shape = &shapeDef;
// groundBody = world->CreateBody(&bodyDef);
// groundBody->CreateFixture(&fixtureDef);
SSL_WrapperPacket packet;
std::cout << packet.ParseFromString(data) << std::endl;
std::cout << packet.detection().robots_blue(0).x() << std::endl;
// Create lots of little colored triangles, random pos, rotation, color.
for (int i = 0; i < BODYCOUNT; ++i) {
//poly << QPointF(0, -10) << QPointF(-5, 0) << QPointF(5, 0);
Bot* polygon = bodyItems[i] = new Bot(world);
polygon->_init();
//polygon->_setPos(QPointF(qrand()%20, qrand()%20));
polygon->_setPos(QPointF(200, 0));
polygon->setRotation(qrand() % 360);
polygon->setBrush(QColor(128 + qrand() % 128, 128 + qrand() % 128, 128 + qrand() % 128));
scene->addItem(polygon);
}
}
Simulator::Simulator(){
}
Simulator::~Simulator(){
delete world;
}
void Simulator::timerEvent(QTimerEvent *event){
if (event->timerId() == timerId) {
world->Step(B2_TIMESTEP, B2_ITERATIONS, 0);
for (int i = 0; i < BODYCOUNT; ++i)
bodyItems[i]->_update();
}
QObject::timerEvent(event);
}
void Simulator::start(){
if (!timerId)
timerId = startTimer(1000 / 60.0);
}
void Simulator::update(std::string message)
{
data = message;
}