Repository navigation
Expand file tree
/
Copy pathdrawElements.pde
More file actions
242 lines (172 loc) · 4.67 KB
/
Copy pathdrawElements.pde
File metadata and controls
242 lines (172 loc) · 4.67 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/********************************************************
ROBOT STATUS
********************************************************/
void drawRobotStatus() {
pushMatrix();
translate(240, 510);
text ("Robot data:", 0, -140);
text ("x = " + RobotOne.x, 0, -120);
text ("y = " + RobotOne.y, 0, -100);
text ("vl = " + RobotOne.vl, 0, -80);
text ("vr = " + RobotOne.vr, 0, -60);
text ("v = " + RobotOne.v, 0, -40);
text ("w = " + RobotOne.w, 0, -20);
text ("motorValLeft = " + motorValLeft, 0, 0);
text ("motorValRight = " + motorValRight, 0, 20);
//println(" ------------------------- "+motorValLeft+" "+motorValRight);
popMatrix();
}
/*********************************
CAMERA DATA TEXT
**********************************/
int cameraDataYPos = -260;
void drawCameraData()
{
fill(50, 255, 50, 100);
pushMatrix();
translate(25, 860);
text("camera keys:", 0, cameraDataYPos);
text("t,g rotateX: "+rX, 5, cameraDataYPos+20);
text("f,h rotateY: "+rY, 5, cameraDataYPos+40);
text("v,b rotateZ: "+rZ, 5, cameraDataYPos+60);
text("a,d xpos: "+xpos, 5, cameraDataYPos+80);
text("w,s ypos: "+ypos, 5, cameraDataYPos+100);
text("z,x zpos: "+zpos, 5, cameraDataYPos+120);
popMatrix();
}
/*********************************
GRID
**********************************/
int _WIDTH = 2000;
int _HEIGHT = 2000;
int squareSizeX = 100;
int squareSizeY = 100;
int squareW = _WIDTH/squareSizeX;
int squareH = _HEIGHT/squareSizeY;
int gridCounter;
void drawGrid() {
pushMatrix();
translate(0, 0, -20);
// outline
noFill();
stroke(255, 25);
strokeWeight(1);
rect(0, 0, _WIDTH, _HEIGHT);
for (int i = 0; i < _WIDTH; i += squareSizeX) {
for (int j = 0; j < _HEIGHT; j += squareSizeY) {
noFill();
strokeWeight(2);
stroke(255, 25);
rect(i, j, squareSizeX, squareSizeY);
text(i+" "+j, i, j);
gridCounter++;
}
}
popMatrix();
}
/*********************************
AXES
**********************************/
void drawAxles()
{
stroke(0, 255, 0, 100);
line(0, 0, 0, 200, 0, 0);
text("x", 200, 0, 0);
line(0, 0, 0, 0, 200, 0);
text("y", 0, 200, 0);
line(0, 0, 0, 0, 0, 200);
text("z", 0, 0, 200);
}
/*********************************
DRAW HELP TEXT
**********************************/
void drawHelpText()
{
fill(255, 50, 50, 175);
text("press '0' to reset", checkXpos, checkYpos-120);
text("press '9' to switch between autonomous / manual mode", checkXpos, checkYpos-105);
fill(75, 150, 255, 175);
text("press '1' to show / hide buttons", checkXpos, checkYpos-60);
text("press '2' to draw camera info", checkXpos, checkYpos-40);
text("press '3' to add trace points", checkXpos, checkYpos-20);
text("press '4' to switch to 3D view", checkXpos, checkYpos);
text("press '5' to show / hide grid", checkXpos, checkYpos+20);
text("press '6' to show / hide motors", checkXpos, checkYpos+40);
text("press '7' to show / hide robot", checkXpos, checkYpos+60);
text("Points IDs: "+RobotOne.id, checkXpos, checkYpos+80);
}
/*********************************
DRAW WHEEL
**********************************/
void drawWheel()
{
if (hidef)
cylinder(2*R, 5, 15);
else
wheel(2*R);
}
void wheel(float r)
{
pushMatrix();
rotateX(radians(90));
ellipse(0, 0, 2*r, 2*r);
line(0, 0, 0, r);
popMatrix();
}
/*********************************
DRAW CHASSIS
**********************************/
void drawChassis()
{
if (hidef)
box(L, L, 10);
else
rect(0, 0, L, L);
}
/*********************************
DRAW SENSOR
**********************************/
void drawSensor()
{
if (hidef)
box(20, 10, 5);
else
rect(0, 0, 20, 10);
}
/*********************************
CYLINDER FUNCTION
http://wiki.processing.org/w/Cylinder
**********************************/
void cylinder(float w, float h, int sides)
{
float angle;
float[] x = new float[sides+1];
float[] z = new float[sides+1];
//get the x and z position on a circle for all the sides
for (int i=0; i < x.length; i++) {
angle = TWO_PI / (sides) * i;
x[i] = sin(angle) * w;
z[i] = cos(angle) * w;
}
//draw the top of the cylinder
beginShape(TRIANGLE_FAN);
vertex(0, -h/2, 0);
for (int i=0; i < x.length; i++) {
vertex(x[i], -h/2, z[i]);
}
endShape();
//draw the center of the cylinder
beginShape(QUAD_STRIP);
for (int i=0; i < x.length; i++) {
vertex(x[i], -h/2, z[i]);
vertex(x[i], h/2, z[i]);
}
endShape();
//draw the bottom of the cylinder
beginShape(TRIANGLE_FAN);
vertex(0, h/2, 0);
for (int i=0; i < x.length; i++) {
vertex(x[i], h/2, z[i]);
}
endShape();
}