@@ -34,14 +34,16 @@ void LidarView::construct_instance() {
34
34
// Create a line of points for the wall
35
35
for (int i = 0 ; i < sim_config::n; ++i) {
36
36
double x = i * sim_config::scale;
37
- double y = sim_config::slope * x + sim_config::intercept + dis (gen);
37
+ double y = ((std::sin (i / 10.0 ) + 1 ) * sim_config::scale * 100 )
38
+ + sim_config::intercept + dis (gen); // now this is ugly fix
38
39
wall[i] = {x, y};
39
40
}
40
41
41
42
// Sample the first 3/4th and the last 3/4th as our LiDAR scans
42
43
source.assign (wall.begin (), wall.begin () + sim_config::n * 3 / 4 );
43
44
destination.assign (wall.begin () + sim_config::n - (sim_config::n * 3 / 4 ),
44
45
wall.end ());
46
+ double shift_because_scans_same_start = destination[0 ].x - source[0 ].x ;
45
47
46
48
// Separate the scans to simulate robot movement
47
49
for (icp::Point & point: source) {
@@ -51,6 +53,11 @@ void LidarView::construct_instance() {
51
53
- y_unshift;
52
54
}
53
55
56
+ double dest_move_x = sim_config::window_width / 2
57
+ + sim_config::x_displace / 2 - x_unshift;
58
+ double dest_move_y = sim_config::window_height / 2
59
+ + sim_config::y_displace / 2 - y_unshift;
60
+
54
61
// TODO: make less scuffed way to do this
55
62
icp->iterate(source, source);
56
63
double cx = icp->transform ().cx ;
@@ -62,15 +69,10 @@ void LidarView::construct_instance() {
62
69
for (icp::Point & point: source) {
63
70
double new_x = com_rot.transform_x (point.x , point.y );
64
71
double new_y = com_rot.transform_y (point.x , point.y );
65
- point.x = new_x + sim_config::x_delta;
72
+ point.x = new_x + sim_config::x_delta + shift_because_scans_same_start ;
66
73
point.y = new_y;
67
74
}
68
75
69
- double dest_move_x = sim_config::window_width / 2
70
- + sim_config::x_displace / 2 - x_unshift;
71
- double dest_move_y = sim_config::window_height / 2
72
- + sim_config::y_displace / 2 - y_unshift;
73
-
74
76
for (icp::Point & point: destination) {
75
77
point.x += dest_move_x + sim_config::x_delta;
76
78
point.y += dest_move_y;
@@ -83,6 +85,7 @@ void LidarView::construct_instance() {
83
85
// where you should be. if it works it works but should clean
84
86
point.x += dest_move_x + sim_config::x_delta;
85
87
point.y += dest_move_y;
88
+ std::cout << point.x << ' ,' << point.y << ' \n ' ;
86
89
}
87
90
}
88
91
@@ -101,22 +104,22 @@ void LidarView::draw(SDL_Renderer* renderer, const SDL_Rect* frame,
101
104
SDL_SetRenderDrawColor (renderer, 0 , 0 , 0 , 0 );
102
105
SDL_RenderClear (renderer);
103
106
104
- SDL_SetRenderDrawColor (renderer, 0 , 255 , 0 , SDL_ALPHA_OPAQUE);
105
- for (const icp::Point & point: source) {
106
- SDL_DrawCircle (renderer, point.x , point.y , CIRCLE_RADIUS);
107
- }
107
+ // SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);
108
+ // for (const icp::Point& point: source) {
109
+ // SDL_DrawCircle(renderer, point.x, point.y, CIRCLE_RADIUS);
110
+ // }
108
111
109
- SDL_SetRenderDrawColor (renderer, 128 , 128 , 128 , SDL_ALPHA_OPAQUE);
110
- for (const icp::Point & point: wall) {
111
- SDL_DrawCircle (renderer, point.x , point.y , CIRCLE_RADIUS);
112
- }
112
+ // SDL_SetRenderDrawColor(renderer, 128, 128, 128, SDL_ALPHA_OPAQUE);
113
+ // for (const icp::Point& point: wall) {
114
+ // SDL_DrawCircle(renderer, point.x, point.y, CIRCLE_RADIUS);
115
+ // }
113
116
114
117
SDL_SetRenderDrawColor (renderer, 0 , 0 , 255 , SDL_ALPHA_OPAQUE);
115
118
for (const icp::Point & point: destination) {
116
119
SDL_DrawCircle (renderer, point.x , point.y , CIRCLE_RADIUS);
117
120
}
118
121
119
- SDL_SetRenderDrawColor (renderer, 0 , 255 , 255 , 100 );
122
+ SDL_SetRenderDrawColor (renderer, 255 , 0 , 0 , 100 );
120
123
for (const icp::Point & point: source) {
121
124
SDL_DrawCircle (renderer, icp->transform ().transform_x (point.x , point.y ),
122
125
icp->transform ().transform_y (point.x , point.y ), CIRCLE_RADIUS);
0 commit comments