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

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 6.0 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.gui;
7
8import java.awt.event.MouseEvent;
9import java.util.Iterator;
10
11import javax.media.opengl.GL;
12import javax.media.opengl.GLAutoDrawable;
13import javax.media.opengl.glu.GLU;
14
15import com.sun.opengl.util.GLUT;
16
17import vnsim.applications.adaptiveTL.WirelessTrafficLight;
18import vnsim.applications.trafficview.SimulatedCarInfo;
19import vnsim.core.CarInfo;
20import vnsim.map.object.Globals;
21import vnsim.map.object.Point;
22import vnsim.map.utils.GPSutil;
23
24public class MapView extends MapViewPanel {
25        /**
26         *
27         */
28        private static final long serialVersionUID = 1L;
29
30        public MapView(Statistics s, int w, int h) {
31                super(s, w, h);
32        }
33
34        public void display(GLAutoDrawable glDrawable) {
35                GL myGL = glDrawable.getGL();
36                GLU myGLU = new GLU();
37                myGL.glClear(GL.GL_COLOR_BUFFER_BIT);
38                myGL.glMatrixMode(GL.GL_MODELVIEW);
39                myGL.glLoadIdentity();
40                // Camera se va uita din pozitia x,y,z in jos la planul xoy
41                myGLU.gluLookAt(xCamera, yCamera, zCamera, xCamera, yCamera, 0.0, 0.0, 1.0, 0.0);
42                myGL.glCallList(mapList); // displays the map
43                // depending on the camera position displays one level of text
44                if (zCamera < 800) {
45                        myGL.glCallList(mapLevel[4]);
46                }
47                if ((zCamera >= 800) && (zCamera < 1600)) {
48                        myGL.glCallList(mapLevel[3]);
49                }
50                if ((zCamera >= 1600) && (zCamera < 2800)) {
51                        myGL.glCallList(mapLevel[2]);
52                }
53                if ((zCamera >= 2800) && (zCamera < 3700)) {
54                        myGL.glCallList(mapLevel[1]);
55                }
56                if (zCamera > 3700) {
57                        myGL.glCallList(mapLevel[0]);
58                }
59                display_Semaphores(myGL);
60                display_Cars(myGL);
61                display_Arrows(myGL);
62                display_Legend(myGL);
63                // if (!Globals.engine.pauseFlag && Globals.engine.crtTime > 100)
64                synchronized (Globals.mutex) {
65                        // Globals.flag = 0;
66                        Globals.mutex.notify();
67                }
68        }
69
70        public void buildList(GLAutoDrawable glDrawable) {
71                // builds the map and 5 different levels of text for the map
72                GL myGL = glDrawable.getGL();
73                GLUT glut = new GLUT();
74                GLU myGLU = new GLU();
75                this.mapLevel = new int[5];
76                prioritySign = myGL.glGenLists(12);
77                ListBuilder.buildList_PrioritySign(myGL, myGLU, glut, prioritySign);
78                noPrioritySign = prioritySign + 1;
79                ListBuilder.buildList_NoPrioritySign(myGL, myGLU, glut, noPrioritySign);
80                stopSign = noPrioritySign + 1;
81                ListBuilder.buildList_StopSign(myGL, myGLU, glut, stopSign);
82                mapList = stopSign + 1;
83                ListBuilder.buildList_MapList(myGL, myGLU, glut, mapList, prioritySign, stopSign, noPrioritySign,
84                                Globals.minPoint, Globals.maxPoint);
85                carList = mapList + 1;
86                ListBuilder.buildList_CarList(myGL, myGLU, glut, carList);
87                accCar = carList + 1;
88                ListBuilder.buildList_AccCar(myGL, myGLU, glut, accCar);
89                hAccCar = accCar + 1;
90                ListBuilder.buildList_HAccCar(myGL, myGLU, glut, hDecCar);
91                stoppedCar = hAccCar + 1;
92                ListBuilder.buildList_StoppedCar(myGL, myGLU, glut, stoppedCar);
93                decCar = stoppedCar + 1;
94                ListBuilder.buildList_DecCar(myGL, myGLU, glut, decCar);
95                hDecCar = decCar + 1;
96                ListBuilder.buildList_HDecCar(myGL, myGLU, glut, hDecCar);
97                signalCar = hDecCar + 1;
98                ListBuilder.buildList_SignalCar(myGL, myGLU, glut, signalCar);
99                whiteCar = signalCar + 1;
100                ListBuilder.buildList_WhiteCar(myGL, myGLU, glut, whiteCar);
101                pinkCar = whiteCar + 1;
102                ListBuilder.buildList_PinkCar(myGL, myGLU, glut, pinkCar);
103                traceCar = pinkCar + 1;
104                ListBuilder.buildList_TraceCar(myGL, myGLU, glut, traceCar);
105                carListOut = traceCar + 1;
106                ListBuilder.buildList_CarListOut(myGL, myGLU, glut, carListOut);
107                neighbor = carListOut + 1;
108                ListBuilder.buildList_Neighbor(myGL, myGLU, glut, neighbor);
109                endOfQueue = neighbor + 1;
110                ListBuilder.buildList_EndOfQueue(myGL, myGLU, glut, endOfQueue);
111                arrows = endOfQueue + 1;
112                ListBuilder.buildList_Arrows(myGL, myGLU, glut, arrows, this.getSize().getWidth(), this.getSize().getHeight(),
113                                25);
114                float y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, Globals.maxPoint);
115                float x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, Globals.maxPoint);
116                xCamera = x2 / 2;
117                yCamera = y2 / 2;
118                zCamera = (float) ((x2 * high) / this.getSize().getWidth());
119                mapLevel[0] = arrows + 1;
120                ListBuilder.buildList_MapLevels(myGL, myGLU, glut, mapLevel, Globals.minPoint);
121                DSRCapp = mapLevel[4] + 1;
122                ListBuilder.buildList_DSRCapp(myGL, myGLU, glut, DSRCapp);
123        }
124
125        public void selection(MouseEvent e) {
126                float winX = e.getX();
127                float winY = (float) this.getSize().height - (float) e.getY();
128                float w = (float) (this.getSize().width * zCamera) / high;
129                float h = (float) (this.getSize().height * zCamera) / high;
130                float worldX = xCamera - (float) (w / 2) + (winX * zCamera) / high;
131                float worldY = yCamera - (float) (h / 2) + (winY * zCamera) / high;
132                MyPoint clickPoint = new MyPoint(worldX, worldY);
133                // get's here only when is a selection, not a movement
134                if (carPositions != null) {
135                        currentCar = null;
136                        currentIntersection = null;
137                        if (carPositions.containsValue(clickPoint)) {
138                                Iterator<CarInfo> i = carPositions.keySet().iterator();
139                                if (i == null) {
140                                        return;
141                                }
142                                while (i.hasNext()) {
143                                        CarInfo ci = i.next();
144                                        if (carPositions.get(ci).equals(clickPoint)) {
145                                                currentCar = (SimulatedCarInfo) ci;
146                                                Globals.demo.st.setSelection("Selection: car " + currentCar.getVehicleId());
147                                                Globals.demo.st.resetLabels();
148                                                return;
149                                        }
150                                }
151                        }
152                }
153                Point myPoint = recoverRoad(worldX, worldY);
154                for (int i = 0; i < Globals.map.allIntersections.size(); i++) {
155                        if (Globals.map.allIntersections.get(i).getMapPoint().distanceTo(myPoint) < 0.01) {
156                                Globals.demo.st.setSelection("Selection: intersection " + i);
157                                currentIntersection = (WirelessTrafficLight) Globals.map.allIntersections.get(i);
158                                return;
159                        }
160                }
161        }
162
163
164}
Note: See TracBrowser for help on using the repository browser.