-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
81 lines (72 loc) · 2.78 KB
/
main.cpp
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
#include "Control/controller.hpp"
#include "Objects/car.hpp"
#include "Scene/scene.hpp"
#include "View/camera.hpp"
#include <pcl/visualization/pcl_visualizer.h>
#include <unordered_map>
int main() {
pcl::visualization::PCLVisualizer::Ptr viewer(
new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer->getRenderWindow()->GlobalWarningDisplayOff();
viewer->setBackgroundColor(0, 0, 0);
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
int *screenSize = viewer->getRenderWindow()->GetScreenSize();
viewer->setSize(1280, 780);
viewer->setCameraPosition(50, 50, 50, // Camera position
0, 0, 0, // Focal point (origin)
0, 0, 1, // View up direction
0); // Set camera viewpoint to (0, 0, 0)
viewer->setCameraFieldOfView(0.8);
viewer->setCameraClipDistances(0.01, 500);
Vect3 position(-2, -3, 0);
Vect3 dimensions(4.0, 2.0, 2.0);
Color color(0.0, 1.0, 0.0);
float angle = -180.0;
float front_center_distance = 1.0;
std::string car_name = "egoCar";
Car car =
Car(position, dimensions, color, angle, front_center_distance, car_name);
EgoCarController carController(viewer, car);
carController.registerKeyboardCallbacks();
float boundary_margin = 100.0;
float x_min = -boundary_margin, x_max = boundary_margin;
float y_min = -boundary_margin, y_max = boundary_margin;
const int interval_us = 100000;
float dt = interval_us * 1e-6;
Scene scene(viewer);
while (!viewer->wasStopped()) {
viewer->removeAllPointClouds();
viewer->removeAllShapes();
carController.handleKeyboardInput();
carController.update(dt, scene);
viewer->spinOnce(1);
Vect3 car_position = car.getPosition();
if (car_position.x < x_min || car_position.x > x_max ||
car_position.y < y_min || car_position.y > y_max) {
viewer->setCameraPosition(car_position.x - 10, car_position.y - 10,
car_position.z + 10, car_position.x,
car_position.y, car_position.z, 0, 0, 1);
viewer->setCameraClipDistances(0.01, 500);
x_min = car_position.x - boundary_margin;
x_max = car_position.x + boundary_margin;
y_min = car_position.y - boundary_margin;
y_max = car_position.y + boundary_margin;
}
if (scene.checkTrafficCollision(car)) {
carController.stop();
}
if (scene.win) {
int textWidth = 50;
int textHeight = 50;
int xpos = (screenSize[0] - textWidth) / 2;
int ypos = (screenSize[1] - textHeight);
int fontSize = 40;
double r = 1.0, g = 1.0, b = 1.0;
viewer->addText("You've won the game!", xpos, ypos, fontSize, r, g, b,
"winning text");
viewer->spinOnce(3000);
break;
}
}
}