source: proiecte/ptvs/src/vnsim/gui/ListBuilder.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 30.0 KB
Line 
1package vnsim.gui;
2
3import javax.media.opengl.GL;
4import javax.media.opengl.glu.GLU;
5import javax.media.opengl.glu.GLUquadric;
6
7import com.sun.opengl.util.GLUT;
8
9import vnsim.map.object.Globals;
10import vnsim.map.object.Point;
11import vnsim.map.object.Road;
12import vnsim.map.utils.GPSutil;
13import vnsim.vehicular.simulator.intersections.DirectedRoadSegment;
14import vnsim.vehicular.simulator.intersections.Intersection;
15import vnsim.vehicular.simulator.intersections.IntersectionWithoutTrafficLights;
16
17public class ListBuilder {
18
19        public static void buildList_PrioritySign(GL myGL, GLU myGLU, GLUT glut, int prioritySign) {
20                myGL.glNewList(prioritySign, GL.GL_COMPILE);
21                {
22                        myGL.glPushMatrix();
23                        myGL.glColor3f(1.0f, 1.0f, 1.0f);
24                        myGL.glBegin(GL.GL_POLYGON);
25                        {
26                                myGL.glVertex3f(0.0f, 4.0f, 0.0f);
27                                myGL.glVertex3f(3.0f, 0.0f, 0.0f);
28                                myGL.glVertex3f(0.0f, -4.0f, 0.0f);
29                                myGL.glVertex3f(-3.0f, 0.0f, 0.0f);
30                        }
31                        myGL.glEnd();
32                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
33                        myGL.glLineWidth(0.25f);
34                        myGL.glBegin(GL.GL_LINE_LOOP);
35                        {
36                                myGL.glVertex3f(0.0f, 4.0f, 0.0f);
37                                myGL.glVertex3f(3.0f, 0.0f, 0.0f);
38                                myGL.glVertex3f(0.0f, -4.0f, 0.0f);
39                                myGL.glVertex3f(-3.0f, 0.0f, 0.0f);
40                        }
41                        myGL.glEnd();
42                        myGL.glColor3f(0.9f, 0.9f, 0.4f);
43                        myGL.glBegin(GL.GL_POLYGON);
44                        {
45                                myGL.glVertex3f(0.0f, 3.0f, 0.0f);
46                                myGL.glVertex3f(2.0f, 0.0f, 0.0f);
47                                myGL.glVertex3f(0.0f, -3.0f, 0.0f);
48                                myGL.glVertex3f(-2.0f, 0.0f, 0.0f);
49                        }
50                        myGL.glEnd();
51                        myGL.glPopMatrix();
52                }
53                myGL.glEndList();
54        }
55
56        /**
57         *
58         * @param myGL
59         */
60        public static void buildList_NoPrioritySign(GL myGL, GLU myGLU, GLUT glut, int noPrioritySign) {
61                myGL.glNewList(noPrioritySign, GL.GL_COMPILE);
62                {
63                        myGL.glPushMatrix();
64                        myGL.glColor3f(1.0f, 1.0f, 1.0f);
65                        myGL.glBegin(GL.GL_TRIANGLES);
66                        {
67                                myGL.glVertex3f(3.5f, 3.5f, 0.0f);
68                                myGL.glVertex3f(-3.5f, 3.5f, 0.0f);
69                                myGL.glVertex3f(0.0f, -3.5f, 0.0f);
70                        }
71                        myGL.glEnd();
72                        myGL.glLineWidth(0.25f);
73                        myGL.glColor3f(1.0f, 0.0f, 0.0f);
74                        myGL.glBegin(GL.GL_LINE_LOOP);
75                        {
76                                myGL.glVertex3f(3.5f, 3.5f, 0.0f);
77                                myGL.glVertex3f(-3.5f, 3.5f, 0.0f);
78                                myGL.glVertex3f(0.0f, -3.5f, 0.0f);
79                        }
80                        myGL.glEnd();
81                        myGL.glColor3f(1.0f, 0.0f, 0.0f);
82                        myGL.glBegin(GL.GL_TRIANGLES);
83                        {
84                                myGL.glVertex3f(2.0f, 2.5f, 0.0f);
85                                myGL.glVertex3f(-2.0f, 2.5f, 0.0f);
86                                myGL.glVertex3f(0.0f, -2.0f, 0.0f);
87                        }
88                        myGL.glEnd();
89                        myGL.glPopMatrix();
90                }
91                myGL.glEndList();
92        }
93
94        /**
95         *
96         * @param myGL
97         * @param glut
98         */
99        public static void buildList_StopSign(GL myGL, GLU myGLU, GLUT glut, int stopSign) {
100                myGL.glNewList(stopSign, GL.GL_COMPILE);
101                {
102                        float x2, y2;
103                        myGL.glPushMatrix();
104                        myGL.glRotatef(22.5f, 0.0f, 0.0f, 1.0f);
105                        myGL.glColor3f(1.0f, 0.0f, 0.0f);
106                        myGL.glBegin(GL.GL_POLYGON);
107                        {
108                                for (int ll = 0; ll < 8; ll++) {
109                                        x2 = (float) (4 * (Math.cos((double) (ll * 45 * Math.PI / 180))));
110                                        y2 = (float) (4 * (Math.sin((double) (ll * 45 * Math.PI / 180))));
111                                        System.out.println("ll=" + ll + "; x=" + x2 + "; y=" + y2);
112                                        myGL.glVertex3f(x2, y2, 0.0f);
113                                }
114                        }
115                        myGL.glEnd();
116                        myGL.glColor3f(1.0f, 1.0f, 1.0f);
117                        myGL.glBegin(GL.GL_POLYGON);
118                        {
119                                for (int ll = 0; ll < 8; ll++) {
120                                        x2 = (float) (3.8 * (Math.cos((double) (ll * 45 * Math.PI / 180))));
121                                        y2 = (float) (3.8 * (Math.sin((double) (ll * 45 * Math.PI / 180))));
122                                        myGL.glVertex3f(x2, y2, 0.0f);
123                                }
124                        }
125                        myGL.glEnd();
126                        myGL.glColor3f(1.0f, 0.0f, 0.0f);
127                        myGL.glBegin(GL.GL_POLYGON);
128                        {
129                                for (int ll = 0; ll < 8; ll++) {
130                                        x2 = (float) (3.4 * (Math.cos((double) (ll * 45 * Math.PI / 180))));
131                                        y2 = (float) (3.4 * (Math.sin((double) (ll * 45 * Math.PI / 180))));
132                                        myGL.glVertex3f(x2, y2, 0.0f);
133                                }
134                        }
135                        myGL.glEnd();
136                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
137                        myGL.glPopMatrix();
138                        myGL.glPushMatrix();
139                        myGL.glTranslatef(-3.4f, -1.0f, 0.0f);
140                        myGL.glScalef(0.02f, 0.02f, 0.02f);
141                        glut.glutStrokeString(GLUT.STROKE_ROMAN, "STOP");
142                        myGL.glPopMatrix();
143                }
144                myGL.glEndList();
145        }
146
147        /**
148         *
149         * @param myGL
150         */
151        public static void buildList_MapList(GL myGL, GLU myGLU, GLUT glut, int mapList, int prioritySign, int stopSign,
152                        int noPrioritySign, Point minPoint, Point maxPoint) {
153                Road currentRoad;
154                Point currentPoint;
155                int i, j;
156                float x, y;
157                byte[] ri;
158                myGL.glNewList(mapList, GL.GL_COMPILE);
159                {
160                        float x2, y2;
161                        // gets the distance between the maximal and minimal point on Ox and
162                        // OY and draws a
163                        // bigger green rectangle
164                        y2 = (float) GPSutil.getMetersLatitude(minPoint, maxPoint);
165                        x2 = (float) GPSutil.getMetersLongitude(minPoint, maxPoint);
166                        myGL.glColor3f(0.4f, 0.7f, 0.2f);
167                        myGL.glBegin(GL.GL_QUADS);
168                        {
169                                myGL.glVertex3f(-10000.0f, -10000.0f, 0.0f);
170                                myGL.glVertex3f((x2 + 10000.f), -10000.0f, 0.0f);
171                                myGL.glVertex3f((x2 + 10000.f), (y2 + 10000.f), 0.0f);
172                                myGL.glVertex3f(-10000.0f, (y2 + 10000.f), 0.0f);
173                        }
174                        myGL.glEnd();
175                        // Sets the initial position of the cammera in the middle of the map
176                        i = 0;
177                        int laneNr;
178                        while (i < Globals.map.roads.size()) {// for every road
179                                currentRoad = (Road) Globals.map.roads.get(i);
180                                ri = currentRoad.getRoadinfo();
181                                // depending on the road type i select a color and a line width
182                                MyColor roadColor = MyColor.chooseRoadColor(ri[1]);
183                                laneNr = currentRoad.laneNo;
184                                y = 0.0f;
185                                x = 0.0f;
186                                j = 0;
187                                double sinAlfa, cosAlfa;
188                                if ((currentRoad.points.size() > 0) && (j == 0)) {
189                                        currentPoint = (Point) currentRoad.points.get(0);
190                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
191                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
192                                }
193                                float dx, dy;
194                                while (j < currentRoad.points.size() - 1) {
195                                        y2 = y;
196                                        x2 = x;
197                                        currentPoint = (Point) currentRoad.points.get(j + 1);
198                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
199                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
200                                        currentPoint = (Point) currentRoad.points.get(j);
201                                        y2 = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
202                                        x2 = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
203                                        sinAlfa = (y2 - y) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)));
204                                        cosAlfa = (x2 - x) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)));
205                                        dx = (float) (laneNr * 2 * sinAlfa);
206                                        dy = (float) (laneNr * 2 * cosAlfa);
207                                        myGL.glPushMatrix();
208                                        {
209                //                              double laneWidth = 1;
210                                                myGL.glColor3f(roadColor.getRed(), roadColor.getGreen(), roadColor.getBlue());
211                                                switch (currentRoad.oneWay) {
212                                                case 0:
213                                                        myGL.glTranslatef(x, y, 0.0f);
214                //                                      laneWidth = 2;
215                                                        break;
216                                                case 1:
217                                                        myGL.glTranslatef(x - (dx / 2), y + (dy / 2), 0.0f);
218                                                        break;
219                                                case 2:
220                                                        myGL.glTranslatef(x + (dx / 2), y - (dy / 2), 0.0f);
221                                                        break;
222                                                }
223                                                myGL.glBegin(GL.GL_POLYGON);
224                                                {
225                                                        for (int ll = 0; ll < 8; ll++) {
226                                                                x2 = (float) (2 * laneNr * (Math.cos((double) (45 * ll * Math.PI / 180))));
227                                                                y2 = (float) (2 * laneNr * (Math.sin((double) (45 * ll * Math.PI / 180))));
228                                                                myGL.glVertex3f(x2, y2, 0.0f);
229                                                        }
230                                                }
231                                                myGL.glEnd();
232                                        }
233                                        myGL.glPopMatrix();
234                                        j++;
235                                }
236                                i++;
237                        }
238                        i = 0;
239                        while (i < Globals.map.roads.size()) {// for every road
240                                currentRoad = (Road) Globals.map.roads.get(i);
241                                ri = currentRoad.getRoadinfo();
242                                // depending on the road type i select a color and a line width
243                                MyColor roadColor = MyColor.chooseRoadColor(ri[1]);
244                                laneNr = currentRoad.laneNo;
245                                j = 0;
246                                double sinAlfa, cosAlfa;
247                                if ((currentRoad.points.size() > 0) && (j == 0)) {
248                                        currentPoint = (Point) currentRoad.points.get(0);
249                                        y2 = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
250                                        x2 = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
251                                }
252                                float dx, dy;
253                                while (j < currentRoad.points.size() - 1) {
254                                        y = y2;
255                                        x = x2;
256                                        currentPoint = (Point) currentRoad.points.get(j + 1);
257                                        y2 = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
258                                        x2 = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
259                                        if ((x2 != x) || (y2 != y)) {
260                                                sinAlfa = (y2 - y) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)));
261                                                cosAlfa = (x2 - x) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)));
262                                                myGL.glPushMatrix();
263                                                {
264                                                        myGL.glTranslatef(x, y, 0);
265                                                        myGL.glColor3f(roadColor.getRed(), roadColor.getGreen(), roadColor.getBlue());
266                                                        myGL.glBegin(GL.GL_QUADS);
267                                                        {
268                                                                dx = (float) (laneNr * 2 * sinAlfa);
269                                                                dy = (float) (laneNr * 2 * cosAlfa);
270                                                                switch (currentRoad.oneWay) {
271                                                                case 0:
272                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
273                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
274                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
275                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
276                                                                        break;
277                                                                case 1:
278                                                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
279                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
280                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
281                                                                        myGL.glVertex3f(x2 - x, y2 - y, 0.0f);
282                                                                        break;
283                                                                case 2:
284                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
285                                                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
286                                                                        myGL.glVertex3f(x2 - x, y2 - y, 0.0f);
287                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
288                                                                        break;
289                                                                }
290                                                        }
291                                                        myGL.glEnd();
292
293                                                        myGL.glLineWidth(0.25f);
294                                                        myGL.glColor3f(0.3f, 0.3f, 0.3f);
295                                                        myGL.glBegin(GL.GL_LINES);
296                                                        {
297                                                                myGL.glVertex3f(0.0f, 0.0f, 0.0f);
298                                                                myGL.glVertex3f(x2 - x, y2 - y, 0.0f);
299                                                                for (int ln = 1; ln < laneNr; ln++) {
300                                                                        dx = (float) (ln * 2 * sinAlfa);
301                                                                        dy = (float) (ln * 2 * cosAlfa);
302                                                                        if (j % 4 != 0) {
303                                                                                myGL.glLineWidth(0.15f);
304                                                                                switch (currentRoad.oneWay) {
305                                                                                case 0:
306                                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
307                                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
308                                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
309                                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
310                                                                                        break;
311
312                                                                                case 1:
313                                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
314                                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
315                                                                                        break;
316
317                                                                                case 2:
318                                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
319                                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
320                                                                                        break;
321                                                                                }
322                                                                        }
323                                                                }
324                                                                dx = (float) (laneNr * 2 * sinAlfa);
325                                                                dy = (float) (laneNr * 2 * cosAlfa);
326                                                                myGL.glLineWidth(0.25f);
327                                                                switch (currentRoad.oneWay) {
328                                                                case 0:
329                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
330                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
331                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
332                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
333                                                                        break;
334
335                                                                case 1:
336                                                                        myGL.glVertex3f(dx, 0.0f - dy, 0.0f);
337                                                                        myGL.glVertex3f(x2 - x + dx, y2 - y - dy, 0.0f);
338                                                                        break;
339
340                                                                case 2:
341                                                                        myGL.glVertex3f(0.0f - dx, dy, 0.0f);
342                                                                        myGL.glVertex3f(x2 - x - dx, y2 - y + dy, 0.0f);
343                                                                        break;
344                                                                }
345                                                        }
346                                                        myGL.glEnd();
347
348                                                }
349                                                myGL.glPopMatrix();
350                                        }
351                                        j++;
352                                }
353                                i++;
354                        }
355                        Intersection currentInt;
356                        DirectedRoadSegment dr;
357                        int tempPointIdx;
358                        for (i = 0; i < Globals.map.allIntersections.size(); i++) {
359                                currentInt = Globals.map.allIntersections.get(i);
360                                if (!currentInt.hasTrafficLights()) {
361                                        for (j = 0; j < ((IntersectionWithoutTrafficLights) currentInt).segments.size(); j++) {
362                                                dr = ((IntersectionWithoutTrafficLights) currentInt).segments.get(j);
363                                                currentRoad = (Road) Globals.map.roads.get(dr.roadIndex);
364                                                tempPointIdx = dr.pointIndex;
365                                                if (dr.direction) {
366                                                        tempPointIdx = tempPointIdx + 2;
367                                                        while (currentRoad.points.size() <= tempPointIdx) {
368                                                                tempPointIdx--;
369                                                        }
370                                                        currentPoint = (Point) currentRoad.points.get(tempPointIdx);
371                                                } else {
372                                                        tempPointIdx = tempPointIdx - 2;
373                                                        while (tempPointIdx < 0) {
374                                                                tempPointIdx++;
375                                                        }
376                                                        currentPoint = (Point) currentRoad.points.get(tempPointIdx);
377                                                }
378                                                y2 = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
379                                                x2 = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
380                                                if (j < 2) {
381                                                        // priority road
382                                                        myGL.glPushMatrix();
383                                                        myGL.glTranslatef(x2, y2, 0.0f);
384                                                        myGL.glCallList(prioritySign);
385                                                        myGL.glPopMatrix();
386                                                } else {
387                                                        // no priority
388                                                        myGL.glPushMatrix();
389                                                        myGL.glTranslatef(x2, y2, 0.0f);
390                                                        if (((IntersectionWithoutTrafficLights) currentInt).mustStop.get(j)) {
391                                                                myGL.glCallList(stopSign);
392                                                        } else {
393                                                                myGL.glCallList(noPrioritySign);
394                                                        }
395                                                        myGL.glPopMatrix();
396                                                }
397                                        }
398                                }
399                        }
400                }
401                myGL.glEndList();
402        }
403
404        /**
405         *
406         * @param myGL
407         * @param myGLU
408         * @param glut
409         */
410        public static void buildList_CarList(GL myGL, GLU myGLU, GLUT glut, int carList) {
411                myGL.glNewList(carList, GL.GL_COMPILE);
412                {
413                        myGL.glColor3f(0.2f, 0.2f, 1.0f);
414                        // glut.glutSolidSphere(myGLU, 15, 40, 40);
415                        GLUquadric quadric = myGLU.gluNewQuadric();
416                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
417                }
418                myGL.glEndList();
419        }
420
421        /**
422         *
423         * @param myGL
424         * @param myGLU
425         * @param glut
426         */
427        public static void buildList_AccCar(GL myGL, GLU myGLU, GLUT glut, int accCar) {
428                myGL.glNewList(accCar, GL.GL_COMPILE);
429                {
430                        myGL.glColor3f(0f, 1f, 0f);
431                        GLUquadric quadric = myGLU.gluNewQuadric();
432                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
433                }
434                myGL.glEndList();
435        }
436
437        /**
438         *
439         * @param myGL
440         * @param myGLU
441         * @param glut
442         */
443        public static void buildList_HAccCar(GL myGL, GLU myGLU, GLUT glut, int hAccCar) {
444                myGL.glNewList(hAccCar, GL.GL_COMPILE);
445                {
446                        myGL.glColor3f(0f, 0.7f, 0f);
447                        GLUquadric quadric = myGLU.gluNewQuadric();
448                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
449                }
450                myGL.glEndList();
451        }
452
453        /**
454         *
455         * @param myGL
456         * @param myGLU
457         * @param glut
458         */
459        public static void buildList_StoppedCar(GL myGL, GLU myGLU, GLUT glut, int stoppedCar) {
460                myGL.glNewList(stoppedCar, GL.GL_COMPILE);
461                {
462                        myGL.glColor3f(0.7f, 0f, 0f);
463                        GLUquadric quadric = myGLU.gluNewQuadric();
464                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
465                }
466                myGL.glEndList();
467        }
468
469        /**
470         *
471         * @param myGL
472         * @param myGLU
473         * @param glut
474         */
475        public static void buildList_DecCar(GL myGL, GLU myGLU, GLUT glut, int decCar) {
476                myGL.glNewList(decCar, GL.GL_COMPILE);
477                {
478                        myGL.glColor3f(1.0f, 1.0f, 0.0f);
479                        GLUquadric quadric = myGLU.gluNewQuadric();
480                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
481                }
482                myGL.glEndList();
483        }
484
485        /**
486         *
487         * @param myGL
488         * @param myGLU
489         * @param glut
490         */
491        public static void buildList_HDecCar(GL myGL, GLU myGLU, GLUT glut, int hDecCar) {
492                myGL.glNewList(hDecCar, GL.GL_COMPILE);
493                {
494                        myGL.glColor3f(0.75f, 0.75f, 0.0f);
495                        GLUquadric quadric = myGLU.gluNewQuadric();
496                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
497                }
498                myGL.glEndList();
499        }
500
501        /**
502         *
503         * @param myGL
504         * @param myGLU
505         * @param glut
506         */
507        public static void buildList_SignalCar(GL myGL, GLU myGLU, GLUT glut, int signalCar) {
508                myGL.glNewList(signalCar, GL.GL_COMPILE);
509                {
510                        myGL.glColor3f(0.9f, 0.9f, 0.05f);
511                        GLUquadric quadric = myGLU.gluNewQuadric();
512                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
513                }
514                myGL.glEndList();
515        }
516
517        /**
518         *
519         * @param myGL
520         * @param myGLU
521         * @param glut
522         */
523        public static void buildList_WhiteCar(GL myGL, GLU myGLU, GLUT glut, int whiteCar) {
524                myGL.glNewList(whiteCar, GL.GL_COMPILE);
525                {
526                        myGL.glColor3f(1.0f, 1.0f, 1.0f);
527                        GLUquadric quadric = myGLU.gluNewQuadric();
528                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
529                }
530                myGL.glEndList();
531        }
532
533        /**
534         *
535         * @param myGL
536         * @param myGLU
537         * @param glut
538         */
539        public static void buildList_PinkCar(GL myGL, GLU myGLU, GLUT glut, int pinkCar) {
540                myGL.glNewList(pinkCar, GL.GL_COMPILE);
541                {
542                        myGL.glColor3f(0.7f, 1.0f, 1.0f);
543                        GLUquadric quadric = myGLU.gluNewQuadric();
544                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
545                }
546                myGL.glEndList();
547        }
548
549        /**
550         *
551         * @param myGL
552         * @param myGLU
553         * @param glut
554         */
555        public static void buildList_TraceCar(GL myGL, GLU myGLU, GLUT glut, int traceCar) {
556                myGL.glNewList(traceCar, GL.GL_COMPILE);
557                {
558                        myGL.glColor3f(0.8f, 1.0f, 1.0f);
559                        GLUquadric quadric = myGLU.gluNewQuadric();
560                        myGLU.gluDisk(quadric, 0, 15, 10, 5);
561
562                }
563                myGL.glEndList();
564        }
565
566        /**
567         *
568         * @param myGL
569         * @param myGLU
570         * @param glut
571         */
572        public static void buildList_CarListOut(GL myGL, GLU myGLU, GLUT glut, int carListOut) {
573                myGL.glNewList(carListOut, GL.GL_COMPILE);
574                {
575                        myGL.glColor3f(1.0f, 0.0f, 0.0f);
576                        GLUquadric quadric = myGLU.gluNewQuadric();
577                        myGLU.gluDisk(quadric, 0, 10, 10, 5);
578                }
579                myGL.glEndList();
580        }
581
582        /**
583         *
584         * @param myGL
585         * @param myGLU
586         * @param glut
587         */
588        public static void buildList_Neighbor(GL myGL, GLU myGLU, GLUT glut, int neighbor) {
589                myGL.glNewList(neighbor, GL.GL_COMPILE);
590                {
591                        myGL.glColor3f(1.0f, 0.0f, 1.0f);
592                        GLUquadric quadric = myGLU.gluNewQuadric();
593                        myGLU.gluDisk(quadric, 0, 7, 10, 5);
594
595                }
596                myGL.glEndList();
597        }
598
599        /**
600         *
601         * @param myGL
602         * @param myGLU
603         * @param glut
604         */
605        public static void buildList_EndOfQueue(GL myGL, GLU myGLU, GLUT glut, int endOfQueue) {
606                myGL.glNewList(endOfQueue, GL.GL_COMPILE);
607                {
608                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
609                        // glut.glutSolidSphere(myGLU, 7, 40, 40);
610                        GLUquadric quadric = myGLU.gluNewQuadric();
611                        myGLU.gluDisk(quadric, 0, 7, 10, 5);
612
613                }
614                myGL.glEndList();
615        }
616
617        /**
618         * Creeaza sagetile de orientare pe harta.
619         *
620         * @param myGL
621         */
622        public static void buildList_Arrows(GL myGL, GLU myGLU, GLUT glut, int arrows, double width, double height, double dx) {
623                myGL.glNewList(arrows, GL.GL_COMPILE);
624                {
625                        myGL.glLineWidth(3.0f);
626                        // UP arrow
627                        myGL.glPushMatrix();
628                        {
629                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
630                                myGL.glTranslatef(0.0f, (float) (height / 2 - dx), 0.0f);
631                                myGL.glBegin(GL.GL_QUADS);
632                                {
633                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
634                                        myGL.glVertex3f(-20.0f, -20.0f, 0.0f);
635                                        myGL.glVertex3f(0.0f, -15.0f, 0.0f);
636                                        myGL.glVertex3f(20.0f, -20.0f, 0.0f);
637                                }
638                                myGL.glEnd();
639                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
640                                myGL.glBegin(GL.GL_LINE_LOOP);
641                                {
642                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
643                                        myGL.glVertex3f(-20.0f, -20.0f, 0.0f);
644                                        myGL.glVertex3f(0.0f, -15.0f, 0.0f);
645                                        myGL.glVertex3f(20.0f, -20.0f, 0.0f);
646                                }
647                                myGL.glEnd();
648                        }
649                        myGL.glPopMatrix();
650                        // DOWN arrow
651                        myGL.glPushMatrix();
652                        {
653                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
654                                myGL.glTranslatef(0.0f, (float) (0 - (height / 2 - dx)), 0.0f);
655                                myGL.glBegin(GL.GL_QUADS);
656                                {
657                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
658                                        myGL.glVertex3f(20.0f, 20.0f, 0.0f);
659                                        myGL.glVertex3f(0.0f, 15.0f, 0.0f);
660                                        myGL.glVertex3f(-20.0f, 20.0f, 0.0f);
661                                }
662                                myGL.glEnd();
663                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
664                                myGL.glBegin(GL.GL_LINE_LOOP);
665                                {
666                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
667                                        myGL.glVertex3f(20.0f, 20.0f, 0.0f);
668                                        myGL.glVertex3f(0.0f, 15.0f, 0.0f);
669                                        myGL.glVertex3f(-20.0f, 20.0f, 0.0f);
670                                }
671                                myGL.glEnd();
672                        }
673                        myGL.glPopMatrix();
674                        // LEFT arrow
675                        myGL.glPushMatrix();
676                        {
677                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
678                                myGL.glTranslatef((float) (width / 2 - dx), 0.0f, 0.0f);
679                                myGL.glBegin(GL.GL_QUADS);
680                                {
681                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
682                                        myGL.glVertex3f(-20.0f, 20.0f, 0.0f);
683                                        myGL.glVertex3f(-15.0f, 0.0f, 0.0f);
684                                        myGL.glVertex3f(-20.0f, -20.0f, 0.0f);
685                                }
686                                myGL.glEnd();
687                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
688                                myGL.glBegin(GL.GL_LINE_LOOP);
689                                {
690                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
691                                        myGL.glVertex3f(-20.0f, 20.0f, 0.0f);
692                                        myGL.glVertex3f(-15.0f, 0.0f, 0.0f);
693                                        myGL.glVertex3f(-20.0f, -20.0f, 0.0f);
694                                }
695                                myGL.glEnd();
696                        }
697                        myGL.glPopMatrix();
698                        // RIGHT arrow
699                        myGL.glPushMatrix();
700                        {
701                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
702                                myGL.glTranslatef((float) (0 - (width / 2 - dx)), 0.0f, 0.0f);
703                                myGL.glBegin(GL.GL_QUADS);
704                                {
705                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
706                                        myGL.glVertex3f(20.0f, 20.0f, 0.0f);
707                                        myGL.glVertex3f(15.0f, 0.0f, 0.0f);
708                                        myGL.glVertex3f(20.0f, -20.0f, 0.0f);
709                                }
710                                myGL.glEnd();
711                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
712                                myGL.glBegin(GL.GL_LINE_LOOP);
713                                {
714                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
715                                        myGL.glVertex3f(20.0f, 20.0f, 0.0f);
716                                        myGL.glVertex3f(15.0f, 0.0f, 0.0f);
717                                        myGL.glVertex3f(20.0f, -20.0f, 0.0f);
718                                }
719                                myGL.glEnd();
720                        }
721                        myGL.glPopMatrix();
722                        myGL.glLineWidth(2.0f);
723                        // UpLeft arrow
724                        myGL.glPushMatrix();
725                        {
726                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
727                                myGL.glTranslatef((float) (0 - (width / 2 - dx)), (float) (height / 2 - dx), 0.0f);
728                                myGL.glBegin(GL.GL_QUADS);
729                                {
730                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
731                                        myGL.glVertex3f(5.0f, -20.0f, 0.0f);
732                                        myGL.glVertex3f(8.0f, -8.0f, 0.0f);
733                                        myGL.glVertex3f(20.0f, -5.0f, 0.0f);
734                                }
735                                myGL.glEnd();
736                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
737                                myGL.glBegin(GL.GL_LINE_LOOP);
738                                {
739                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
740                                        myGL.glVertex3f(5.0f, -20.0f, 0.0f);
741                                        myGL.glVertex3f(8.0f, -8.0f, 0.0f);
742                                        myGL.glVertex3f(20.0f, -5.0f, 0.0f);
743                                }
744                                myGL.glEnd();
745                        }
746                        myGL.glPopMatrix();
747                        // UpRight
748                        myGL.glPushMatrix();
749                        {
750                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
751                                myGL.glTranslatef((float) (width / 2 - dx), (float) (height / 2 - dx), 0.0f);
752                                myGL.glBegin(GL.GL_QUADS);
753                                {
754                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
755                                        myGL.glVertex3f(-5.0f, -20.0f, 0.0f);
756                                        myGL.glVertex3f(-8.0f, -8.0f, 0.0f);
757                                        myGL.glVertex3f(-20.0f, -5.0f, 0.0f);
758                                }
759                                myGL.glEnd();
760                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
761                                myGL.glBegin(GL.GL_LINE_LOOP);
762                                {
763                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
764                                        myGL.glVertex3f(-5.0f, -20.0f, 0.0f);
765                                        myGL.glVertex3f(-8.0f, -8.0f, 0.0f);
766                                        myGL.glVertex3f(-20.0f, -5.0f, 0.0f);
767                                }
768                                myGL.glEnd();
769                        }
770                        myGL.glPopMatrix();
771                        // DownLeft
772                        myGL.glPushMatrix();
773                        {
774                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
775                                myGL.glTranslatef((float) (0 - (width / 2 - dx)), (float) (0 - (height / 2 - dx)), 0.0f);
776                                myGL.glBegin(GL.GL_QUADS);
777                                {
778                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
779                                        myGL.glVertex3f(5.0f, 20.0f, 0.0f);
780                                        myGL.glVertex3f(8.0f, 8.0f, 0.0f);
781                                        myGL.glVertex3f(20.0f, 5.0f, 0.0f);
782                                }
783                                myGL.glEnd();
784                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
785                                myGL.glBegin(GL.GL_LINE_LOOP);
786                                {
787                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
788                                        myGL.glVertex3f(5.0f, 20.0f, 0.0f);
789                                        myGL.glVertex3f(8.0f, 8.0f, 0.0f);
790                                        myGL.glVertex3f(20.0f, 5.0f, 0.0f);
791                                }
792                                myGL.glEnd();
793                        }
794                        myGL.glPopMatrix();
795                        // DownRight
796                        myGL.glPushMatrix();
797                        {
798                                myGL.glColor3f(0.7f, 0.7f, 0.9f);
799                                myGL.glTranslatef((float) (width / 2 - dx), (float) (0 - (height / 2 - dx)), 0.0f);
800                                myGL.glBegin(GL.GL_QUADS);
801                                {
802                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
803                                        myGL.glVertex3f(-5.0f, 20.0f, 0.0f);
804                                        myGL.glVertex3f(-8.0f, 8.0f, 0.0f);
805                                        myGL.glVertex3f(-20.0f, 5.0f, 0.0f);
806                                }
807                                myGL.glEnd();
808                                myGL.glColor3f(0.8f, 0.8f, 0.9f);
809                                myGL.glBegin(GL.GL_LINE_LOOP);
810                                {
811                                        myGL.glVertex3f(0.0f, 0.0f, 0.0f);
812                                        myGL.glVertex3f(-5.0f, 20.0f, 0.0f);
813                                        myGL.glVertex3f(-8.0f, 8.0f, 0.0f);
814                                        myGL.glVertex3f(-20.0f, 5.0f, 0.0f);
815                                }
816                                myGL.glEnd();
817                        }
818                        myGL.glPopMatrix();
819                }
820                myGL.glEndList();
821        }
822
823        /**
824         * Creeaza 5 nivele de text.
825         *
826         * @param myGL
827         * @param myGLU
828         * @param glut
829         */
830        public static void buildList_MapLevels(GL myGL, GLU myGLU, GLUT glut, int[] mapLevel, Point minPoint) {
831                Road currentRoad;
832                Point currentPoint;
833                int i, j;
834                float x, y, s;
835                byte[] ri;
836                // creates 5 different levels of text
837                // Firs level has only one name for highways, placed in the middle of
838                // the road
839                myGL.glNewList(mapLevel[0], GL.GL_COMPILE);
840                {
841                        i = 0;
842                        while (i < Globals.map.roads.size()) {
843                                // for every road
844                                currentRoad = (Road) Globals.map.roads.get(i);
845                                ri = currentRoad.getRoadinfo();
846                                if ((ri[1] >= 49) && (ri[1] < 51)) {// if it is a big road
847                                        // (highway or primary road)
848                                        // i put
849                                        // the road name in the middle of it
850                                        currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 1) / 2));
851                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
852                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
853                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
854                                        myGL.glPushMatrix();
855                                        {
856                                                myGL.glTranslatef(x - 10, y - 10, 0.0f);
857                                                myGL.glScalef(2.0f, 2.0f, 2.0f);
858                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
859                                        }
860                                        myGL.glPopMatrix();
861                                }
862                                i++;
863                        }
864                }
865                myGL.glEndList();
866                // the rest of text levels
867                for (j = 1; j < 5; j++) {
868                        mapLevel[j] = mapLevel[j - 1] + 1;
869                        myGL.glNewList(mapLevel[j], GL.GL_COMPILE);
870                        {
871                                i = 0;
872                                while (i < Globals.map.roads.size()) {// for every road
873                                        currentRoad = (Road) Globals.map.roads.get(i);
874                                        ri = currentRoad.getRoadinfo();
875                                        if (j == 1) {
876                                                // for the second level of text big roads (highways and
877                                                // primary roads)
878                                                // will have their name written 3 times: at start, in
879                                                // the middle and
880                                                // in the end, with a smaller font than the previous
881                                                // level
882                                                if ((ri[1] >= 49) && (ri[1] < 51)) {
883                                                        s = 1.0f;
884                                                        currentPoint = (Point) currentRoad.points.get(1);
885                                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
886                                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
887                                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
888                                                        myGL.glPushMatrix();
889                                                        {
890                                                                myGL.glTranslatef(x - 5, y - 5, 0.0f);
891                                                                myGL.glScalef(s, s, s);
892                                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
893                                                        }
894                                                        myGL.glPopMatrix();
895                                                        currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 1) / 2));
896                                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
897                                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
898                                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
899                                                        myGL.glPushMatrix();
900                                                        {
901                                                                myGL.glTranslatef(x - 5, y - 5, 0.0f);
902                                                                myGL.glScalef(s, s, s);
903                                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
904                                                        }
905                                                        myGL.glPopMatrix();
906                                                        currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 2)));
907                                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
908                                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
909                                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
910                                                        myGL.glPushMatrix();
911                                                        {
912                                                                myGL.glTranslatef(x - 5, y - 5, 0.0f);
913                                                                myGL.glScalef(s, s, s);
914                                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
915                                                        }
916                                                        myGL.glPopMatrix();
917                                                }
918                                        }
919                                        if (j == 2) {// the third level
920                                                // for big roads the text is written 3 times, smaller
921                                                // than the previous level
922                                                // for secondary roads the name will be written once in
923                                                // the middle
924                                                if ((ri[1] <= 51) && (ri[1] >= 49)) {
925                                                        s = 0.4f;
926                                                        if (ri[1] > 51) {
927                                                                currentPoint = (Point) currentRoad.points.get(1);
928                                                                y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
929                                                                x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
930                                                                myGL.glColor3f(0.0f, 0.0f, 0.0f);
931                                                                myGL.glPushMatrix();
932                                                                {
933                                                                        myGL.glTranslatef(x - 5, y - 5, 0.0f);
934                                                                        myGL.glScalef(s, s, s);
935                                                                        glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
936                                                                }
937                                                                myGL.glPopMatrix();
938                                                                currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 2)));
939                                                                y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
940                                                                x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
941                                                                myGL.glColor3f(0.0f, 0.0f, 0.0f);
942                                                                myGL.glPushMatrix();
943                                                                {
944                                                                        myGL.glTranslatef(x - 5, y - 5, 0.0f);
945                                                                        myGL.glScalef(s, s, s);
946                                                                        glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
947                                                                }
948                                                                myGL.glPopMatrix();
949                                                        }
950                                                        currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 1) / 2));
951                                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
952                                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
953                                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
954                                                        myGL.glPushMatrix();
955                                                        {
956                                                                myGL.glTranslatef(x - 5, y - 5, 0.0f);
957                                                                myGL.glScalef(s, s, s);
958                                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
959                                                        }
960                                                        myGL.glPopMatrix();
961                                                }
962                                        }
963                                        if ((j == 3) || (j == 4)) {// for the last two levels the
964                                                // small roads have their name
965                                                // written in the middle with 2 sizes of fonts
966                                                if (ri[1] >= 52) {
967                                                        if (j == 4) {
968                                                                s = 0.1f;
969                                                        } else {
970                                                                s = 0.2f;
971                                                        }
972                                                        currentPoint = (Point) currentRoad.points.get((int) ((currentRoad.points.size() - 1) / 2));
973                                                        y = (float) GPSutil.getMetersLatitude(minPoint, currentPoint);
974                                                        x = (float) GPSutil.getMetersLongitude(minPoint, currentPoint);
975                                                        myGL.glColor3f(0.0f, 0.0f, 0.0f);
976                                                        myGL.glPushMatrix();
977                                                        {
978                                                                myGL.glTranslatef(x - 5, y - 5, 0.0f);
979                                                                myGL.glScalef(s, s, s);
980                                                                glut.glutStrokeString(GLUT.STROKE_ROMAN, currentRoad.getName());
981                                                        }
982                                                        myGL.glPopMatrix();
983                                                }
984                                        }
985                                        i++;
986                                }
987                        }
988                        myGL.glEndList();
989                }
990        }
991
992        /**
993         * Petroaca - the FV,NFV,LAV,RAV display
994         *
995         * @param myGL
996         * @param myGLU
997         * @param glut
998         */
999        public static void buildList_DSRCapp(GL myGL, GLU myGLU, GLUT glut, int DSRCapp) {
1000                myGL.glNewList(DSRCapp, GL.GL_COMPILE);
1001                {
1002                        myGL.glColor3f(1.0f, 1.0f, 1.0f);
1003                        glut.glutSolidSphere(10, 40, 40);
1004                }
1005                myGL.glEndList();
1006        }
1007
1008}
Note: See TracBrowser for help on using the repository browser.