Skip to content

Commit 374d9ed

Browse files
committed
Added manager parameters to constants.hpp and more.
1 parent 34c0f88 commit 374d9ed

29 files changed

+75
-82
lines changed

bezier.md

+22-20
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ When the user calls the executable, he/she is at Path 1.
66
Each path consists of control points given as input by user, which are converted to an approximated smooth curve. The interpolation is done using nth-order Bezier-curve parameterization. The parameterization of the path is updated and rendered on screen at every input.
77

88
### Controls:
9-
* ##### Left-click -
10-
Takes the location of left click by user as the input of control points.
11-
* ##### Right-click -
12-
Stops the input of control points until 'R' is pressed.
13-
* ##### 'R' -
14-
Resumes the input of control points.
15-
* ##### 'N' -
16-
Moves to next path. Input of control stops until 'R' is pressed.
17-
* ##### 'P' -
18-
Moves to previous path. Input of control stops until 'R' is pressed.
19-
* ##### 'D' -
20-
Deletes the last control point in the current path.
21-
* ##### 'S' -
22-
The control points and interpolated points are stored in two raw files, with extension '.min.raw' and '.raw' respectively in models/Bezier-Curve.
23-
* ##### 'L' -
24-
The control points stored in the '.min.raw' are loaded and the paths are rendered with the screen displaying from Path 1.
25-
To start editing the paths, the user must press 'R' to resume.
26-
* ##### 'ESC' -
27-
The window is closed and all unsaved work is lost.
9+
* #### Keyboard:
10+
* ##### 'R' -
11+
Resumes the input of control points.
12+
* ##### 'N' -
13+
Moves to next path. Input of control stops until 'R' is pressed.
14+
* ##### 'P' -
15+
Moves to previous path. Input of control stops until 'R' is pressed.
16+
* ##### 'D' -
17+
Deletes the last control point in the current path.
18+
* ##### 'S' -
19+
The control points and interpolated points are stored in two raw files, with extension '.min.raw' and '.raw' respectively in models/Bezier-Curve.
20+
* ##### 'L' -
21+
The control points stored in the '.min.raw' are loaded and the paths are rendered with the screen displaying from Path 1.
22+
To start editing the paths, the user must press 'R' to resume.
23+
* ##### 'ESC' -
24+
The window is closed and all unsaved work is lost.
25+
* #### Mouse:
26+
* ##### Left-click -
27+
Takes the location of left click by user as the input of control points.
28+
* ##### Right-click -
29+
Stops the input of control points until 'R' is pressed.
2830

2931
### Code:
30-
Source directory - /src/Bezier-Curve
32+
Source directory - /src/Bezier-Curve
3133
Include directory - /include/road-network/Bezier-Curve

bin/input

-95.2 KB
Binary file not shown.

bin/output

-266 KB
Binary file not shown.

include/road_network/Bezier-Curve/path.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
#include <glm/vec2.hpp>
1515

1616
#include "road_network/shader_util.hpp"
17+
#include "road_network/constants.hpp"
1718

1819
#ifdef _WIN32
1920
#include <Windows.h>
2021
#else
2122
#include <unistd.h>
2223
#endif
2324

24-
// Average Interpolation Distance
25-
#define AIPD (1.0 / 30.0)
26-
2725
namespace soc {
2826

2927
std::vector<glm::vec2> bezier_curve_point(std::vector<glm::vec2> &pos,

include/road_network/Bezier-Curve/start_end.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <glm/vec2.hpp>
1515

1616
#include "road_network/shader_util.hpp"
17+
#include "road_network/constants.hpp"
1718

1819
#include "road_network/Bezier-Curve/path.hpp"
1920

@@ -23,8 +24,6 @@
2324
#include <unistd.h>
2425
#endif
2526

26-
#define PI 3.14159
27-
2827
namespace soc {
2928

3029
class Pairs {

include/road_network/Models/car_model.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <glm/vec3.hpp>
1515
#include <glm/vec4.hpp>
1616

17-
#include "road_network/output_gl_framework.hpp"
1817
#include "road_network/shader_util.hpp"
18+
#include "road_network/constants.hpp"
1919

2020
#include "road_network/Road-Model/road.hpp"
2121

include/road_network/Models/traffic_light_model.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <glm/vec3.hpp>
1414
#include <glm/vec4.hpp>
1515

16-
#include "road_network/output_gl_framework.hpp"
16+
#include "road_network/constants.hpp"
1717
#include "road_network/shader_util.hpp"
1818

1919
#include "road_network/Road-Model/road.hpp"

include/road_network/Road-Graph/graph.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <math.h>
99
#include <algorithm>
1010

11+
#include "road_network/constants.hpp"
12+
1113
namespace soc {
1214

1315
struct Edge{

include/road_network/Road-Model/intersection.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
#include <glm/vec4.hpp>
1616

1717
#include "road_network/shader_util.hpp"
18+
#include "road_network/constants.hpp"
1819

1920
#include "road_network/Road-Model/road.hpp"
2021

21-
#define BZC_COUNT 20
22-
2322
namespace soc {
2423

2524
class Intersection{

include/road_network/Road-Model/road.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <glm/vec3.hpp>
1414
#include <glm/vec4.hpp>
1515

16-
#include "road_network/output_gl_framework.hpp"
1716
#include "road_network/shader_util.hpp"
17+
#include "road_network/constants.hpp"
1818

1919
#include "road_network/Road-Model/texture.hpp"
2020

include/road_network/Road-Model/road_collection.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <glm/vec4.hpp>
1717

1818
#include "road_network/Road-Graph/graph.hpp"
19+
#include "road_network/constants.hpp"
1920

2021
#include "road_network/Road-Model/road.hpp"
2122
#include "road_network/Road-Model/road_sep.hpp"

include/road_network/Road-Model/road_sep.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <glm/vec3.hpp>
1414
#include <glm/vec4.hpp>
1515

16-
#include "road_network/output_gl_framework.hpp"
1716
#include "road_network/shader_util.hpp"
17+
#include "road_network/constants.hpp"
1818

1919
#include "road_network/Road-Model/road.hpp"
2020

include/road_network/Traffic-Manager/car_node.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "road_network/Road-Graph/graph.hpp"
1111
#include "road_network/Models/car_model.hpp"
1212

13-
#define PI_MATH 3.14159265
13+
#include "road_network/constants.hpp"
1414

1515
namespace soc {
1616

include/road_network/Traffic-Manager/intersection_lights.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "road_network/Road-Graph/graph.hpp"
1111
#include "road_network/Models/traffic_light_model.hpp"
1212

13-
#define PI_MATH 3.14159265
13+
#include "road_network/constants.hpp"
1414

1515
namespace soc {
1616

include/road_network/Traffic-Manager/manager.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
#include <math.h>
99

1010
#include "road_network/Road-Graph/graph.hpp"
11+
#include "road_network/constants.hpp"
1112

1213
#include "road_network/Traffic-Manager/car_node.hpp"
1314
#include "road_network/Traffic-Manager/intersection_lights.hpp"
1415

15-
#define LC 5
16-
1716
namespace soc {
1817

1918
class Manager {

include/road_network/constants.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
#define BZC_COUNT 20
1313

14-
// Least count
15-
#define LC 5
16-
1714
#define SCR_WIDTH 1440
1815

1916
#define SCR_HEIGHT 900
@@ -22,4 +19,14 @@
2219

2320
#define ROAD_WIDTH 0.05
2421

22+
#define INTER_CYLINDER_DISTANCE 0.027
23+
24+
#define FRAMES_PER_CHANGE 40
25+
26+
#define GREEN_LIGHT_TIMEOUT 10
27+
28+
#define YELLOW_LIGHT_TIMEOUT 5
29+
30+
#define CAR_SPAWN_GAP 2
31+
2532
#endif /* constants_hpp */

include/road_network/output_gl_framework.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
#include <iostream>
88

9-
#define BUFFER_OFFSET(offset) ((GLvoid *)(offset))
10-
11-
#define PI_MATH 3.14159265
12-
139
namespace soc {
1410

1511
// Initialize GL State

models/Bezier-Model/1.min.raw

-24 Bytes
Binary file not shown.

models/Bezier-Model/1.raw

-296 Bytes
Binary file not shown.

models/Bezier-Model/points.raw

-16 Bytes
Binary file not shown.
-224 Bytes
Binary file not shown.

obj/shader_util.o

-65 KB
Binary file not shown.

output.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Very close intersections are merged into one and after this, road-network graph
3131
* ##### Mouse cursor movement -
3232
Direction of the front and consequently right vector of the camera is changed preserving its position.
3333
Can be used to look-around the model from one-place. At the start of the program the cursor is snapped to the center of the screen.
34-
35-
34+
35+
3636
### Code:
37-
Source directory - /src/Road-Model and /src/Road-Graph.
38-
Include directory - /include/road-network/Road-Model and /include/road-network/Road-Graph.
37+
Source directory - /src/Road-Model and /src/Road-Graph
38+
Include directory - /include/road-network/Road-Model and /include/road-network/Road-Graph.

src/Road-Model/road.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "road_network/Road-Model/road.hpp"
22

33
extern std::vector<glm::mat4> matrixStack;
4-
#define INTER_CYLINDER_DISTANCE 0.027
54

65
namespace soc {
76
// Constructor that takes coordinates of the four points and depth and dist from
@@ -324,7 +323,7 @@ void Road::fill_border(int a, int b, int c, int d, glm::vec4 *positions) {
324323
void Road::cylinders(float d) {
325324
float r = calc_dist(x1, y1, x2, y2) / 50;
326325
float div = depth / 5;
327-
float sec = PI_MATH / 5;
326+
float sec = PI / 5;
328327

329328
// Cylinders on the bottom part of the road
330329
float mpx1 = (x1 + k1[0]) / 2, mpy1 = (y1 + k1[1]) / 2;
@@ -335,7 +334,7 @@ void Road::cylinders(float d) {
335334
glm::vec2 v = int_div(mpx1, mpy1, mpx2, mpy2, distance / (dist - distance));
336335

337336
for (float i = -depth / 4; i <= 5 * depth / 4; i += div) {
338-
for (float j = 0; j <= 2 * PI_MATH; j += sec) {
337+
for (float j = 0; j <= 2 * PI; j += sec) {
339338
v_positions_border[tri_idx] =
340339
glm::vec4(v[0] + r * sin(j), v[1] + r * cos(j), i, 1.0f);
341340
v_colors_border[tri_idx] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
@@ -369,7 +368,7 @@ void Road::cylinders(float d) {
369368
for (distance = start_spacing_a; distance < dist; distance += d) {
370369
glm::vec2 v = int_div(mpx1, mpy1, mpx2, mpy2, distance / (dist - distance));
371370
for (float i = -depth / 4; i <= 5 * depth / 4; i += div) {
372-
for (float j = 0; j <= 2 * PI_MATH; j += sec) {
371+
for (float j = 0; j <= 2 * PI; j += sec) {
373372
v_positions_border[tri_idx] =
374373
glm::vec4(v[0] + r * sin(j), v[1] + r * cos(j), i, 1.0f);
375374
v_colors_border[tri_idx] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);

src/Road-Model/road_collection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void RoadNetwork::initRoadSeps() {
135135
RoadSep rs_temp(glm::vec3(0, 0, 0), (d/15));
136136
rs_temp.change_parameters(bezier_positions[i][j][0],
137137
bezier_positions[i][j][1], road_depth / 2, 0, 0,
138-
180 / PI_MATH * atan(tangent_directions[i][j][1] /
138+
180 / PI * atan(tangent_directions[i][j][1] /
139139
tangent_directions[i][j][0]));
140140
rs[i].push_back(rs_temp);
141141
}

src/Road-Model/road_sep.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ void RoadSep::build_handle() {
186186
float r = 0.15 * s;
187187
float R = 1.5 * s - r;
188188
float div = 4 * s / 20;
189-
float sec = PI_MATH / 5;
189+
float sec = PI / 5;
190190

191191
// create the cylindrical handle using parameteric equation of the cylinders
192192
for (float i = s; i <= 5 * s; i += div) {
193-
for (float j = 0; j <= 2 * PI_MATH; j += sec) {
193+
for (float j = 0; j <= 2 * PI; j += sec) {
194194
v_positions_handle[tri_idx] =
195195
glm::vec4(r * sin(j), R - r * cos(j), i, 1.0f);
196196
v_colors_handle[tri_idx] = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
@@ -209,18 +209,18 @@ void RoadSep::build_handle() {
209209
}
210210

211211
// generate the other handle of the separator
212-
float slice = PI_MATH / 50;
213-
for (float i = 0.0; i <= PI_MATH; i += slice) {
214-
for (float j = 0.0; j <= 2 * PI_MATH; j += sec) {
212+
float slice = PI / 50;
213+
for (float i = 0.0; i <= PI; i += slice) {
214+
for (float j = 0.0; j <= 2 * PI; j += sec) {
215215
float x = r * sin(j);
216216
float y = (R - r * cos(j)) * cos(i);
217217
float z = (R - r * cos(j)) * sin(i) + 5 * s;
218218
v_colors_handle[tri_idx] = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
219219
v_positions_handle[tri_idx] = glm::vec4(x, y, z, 1.0f);
220220
tri_idx++;
221221
float next;
222-
if (i + slice > PI_MATH)
223-
next = PI_MATH;
222+
if (i + slice > PI)
223+
next = PI;
224224
else
225225
next = i + slice;
226226
x = r * sin(j);
@@ -235,7 +235,7 @@ void RoadSep::build_handle() {
235235

236236
// generate the middle semicircular disc part
237237
for (float i = s; i <= 5 * s; i += div) {
238-
for (float j = 0; j <= 2 * PI_MATH; j += sec) {
238+
for (float j = 0; j <= 2 * PI; j += sec) {
239239
v_positions_handle[tri_idx] =
240240
glm::vec4(r * sin(j), -R + r * cos(j), i, 1.0f);
241241
v_colors_handle[tri_idx] = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);

src/Traffic-Manager/car_node.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace soc {
55

66
CarNode::CarNode(Graph* graph, std::vector<int> in) {
7-
road_depth = 0.02;
8-
lane_width = 0.05;
97
start_vertex_no = in[0];
108

119
path_centered.clear(); // Stores the path
@@ -51,7 +49,7 @@ CarNode::CarNode(Graph* graph, std::vector<int> in) {
5149

5250
current = -1;
5351

54-
mod = new CarModel(0.020);
52+
mod = new CarModel(ROAD_WIDTH * 0.25);
5553
updateCar();
5654
}
5755

@@ -70,16 +68,16 @@ bool CarNode::updateCar() {
7068

7169
float rz;
7270
if (tangent[0] > 0.0) {
73-
rz = atan(tangent[1]/tangent[0])*180.0/PI_MATH;
71+
rz = atan(tangent[1]/tangent[0])*180.0/PI;
7472
}
7573
else if (tangent[0] == 0.0) {
7674
rz = 90.0;
7775
}
7876
else {
79-
rz = 180.0 + (atan(tangent[1]/tangent[0])*180.0/PI_MATH);
77+
rz = 180.0 + (atan(tangent[1]/tangent[0])*180.0/PI);
8078
}
8179

82-
mod->change_parameters(path[current][0], path[current][1], road_depth, 0, 0, rz);
80+
mod->change_parameters(path[current][0], path[current][1], ROAD_DEPTH / 2, 0, 0, rz);
8381

8482
return true;
8583
}
@@ -127,7 +125,7 @@ void CarNode::assignLane() {
127125
glm::vec2 normal;
128126
for (unsigned int i = 0; i < path_centered.size(); i++) {
129127
if (i + 1 == path_centered.size()) {
130-
path[i] = path_centered[i] - normal*(lane_width/2);
128+
path[i] = path_centered[i] - normal * float(ROAD_WIDTH / 4);
131129
continue;
132130
}
133131

@@ -140,10 +138,10 @@ void CarNode::assignLane() {
140138

141139
for (unsigned int j = 0; j < check_loc_centered.size(); j++) {
142140
if (check_loc_centered[j] == path_centered[i])
143-
check_loc[j] = check_loc_centered[j] - normal*(lane_width/2);
141+
check_loc[j] = check_loc_centered[j] - normal * float(ROAD_WIDTH / 4);
144142
}
145143

146-
path[i] = path_centered[i] - normal*(lane_width/2);
144+
path[i] = path_centered[i] - normal * float(ROAD_WIDTH / 4);
147145
}
148146
}
149147

0 commit comments

Comments
 (0)