/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.gui; import java.awt.event.MouseEvent; import java.util.Iterator; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.glu.GLU; import com.sun.opengl.util.GLUT; import vnsim.applications.adaptiveTL.WirelessTrafficLight; import vnsim.applications.trafficview.SimulatedCarInfo; import vnsim.core.CarInfo; import vnsim.map.object.Globals; import vnsim.map.object.Point; import vnsim.map.utils.GPSutil; public class MapView extends MapViewPanel { /** * */ private static final long serialVersionUID = 1L; public MapView(Statistics s, int w, int h) { super(s, w, h); } public void display(GLAutoDrawable glDrawable) { GL myGL = glDrawable.getGL(); GLU myGLU = new GLU(); myGL.glClear(GL.GL_COLOR_BUFFER_BIT); myGL.glMatrixMode(GL.GL_MODELVIEW); myGL.glLoadIdentity(); // Camera se va uita din pozitia x,y,z in jos la planul xoy myGLU.gluLookAt(xCamera, yCamera, zCamera, xCamera, yCamera, 0.0, 0.0, 1.0, 0.0); myGL.glCallList(mapList); // displays the map // depending on the camera position displays one level of text if (zCamera < 800) { myGL.glCallList(mapLevel[4]); } if ((zCamera >= 800) && (zCamera < 1600)) { myGL.glCallList(mapLevel[3]); } if ((zCamera >= 1600) && (zCamera < 2800)) { myGL.glCallList(mapLevel[2]); } if ((zCamera >= 2800) && (zCamera < 3700)) { myGL.glCallList(mapLevel[1]); } if (zCamera > 3700) { myGL.glCallList(mapLevel[0]); } display_Semaphores(myGL); display_Cars(myGL); display_Arrows(myGL); display_Legend(myGL); // if (!Globals.engine.pauseFlag && Globals.engine.crtTime > 100) synchronized (Globals.mutex) { // Globals.flag = 0; Globals.mutex.notify(); } } public void buildList(GLAutoDrawable glDrawable) { // builds the map and 5 different levels of text for the map GL myGL = glDrawable.getGL(); GLUT glut = new GLUT(); GLU myGLU = new GLU(); this.mapLevel = new int[5]; prioritySign = myGL.glGenLists(12); ListBuilder.buildList_PrioritySign(myGL, myGLU, glut, prioritySign); noPrioritySign = prioritySign + 1; ListBuilder.buildList_NoPrioritySign(myGL, myGLU, glut, noPrioritySign); stopSign = noPrioritySign + 1; ListBuilder.buildList_StopSign(myGL, myGLU, glut, stopSign); mapList = stopSign + 1; ListBuilder.buildList_MapList(myGL, myGLU, glut, mapList, prioritySign, stopSign, noPrioritySign, Globals.minPoint, Globals.maxPoint); carList = mapList + 1; ListBuilder.buildList_CarList(myGL, myGLU, glut, carList); accCar = carList + 1; ListBuilder.buildList_AccCar(myGL, myGLU, glut, accCar); hAccCar = accCar + 1; ListBuilder.buildList_HAccCar(myGL, myGLU, glut, hDecCar); stoppedCar = hAccCar + 1; ListBuilder.buildList_StoppedCar(myGL, myGLU, glut, stoppedCar); decCar = stoppedCar + 1; ListBuilder.buildList_DecCar(myGL, myGLU, glut, decCar); hDecCar = decCar + 1; ListBuilder.buildList_HDecCar(myGL, myGLU, glut, hDecCar); signalCar = hDecCar + 1; ListBuilder.buildList_SignalCar(myGL, myGLU, glut, signalCar); whiteCar = signalCar + 1; ListBuilder.buildList_WhiteCar(myGL, myGLU, glut, whiteCar); pinkCar = whiteCar + 1; ListBuilder.buildList_PinkCar(myGL, myGLU, glut, pinkCar); traceCar = pinkCar + 1; ListBuilder.buildList_TraceCar(myGL, myGLU, glut, traceCar); carListOut = traceCar + 1; ListBuilder.buildList_CarListOut(myGL, myGLU, glut, carListOut); neighbor = carListOut + 1; ListBuilder.buildList_Neighbor(myGL, myGLU, glut, neighbor); endOfQueue = neighbor + 1; ListBuilder.buildList_EndOfQueue(myGL, myGLU, glut, endOfQueue); arrows = endOfQueue + 1; ListBuilder.buildList_Arrows(myGL, myGLU, glut, arrows, this.getSize().getWidth(), this.getSize().getHeight(), 25); float y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, Globals.maxPoint); float x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, Globals.maxPoint); xCamera = x2 / 2; yCamera = y2 / 2; zCamera = (float) ((x2 * high) / this.getSize().getWidth()); mapLevel[0] = arrows + 1; ListBuilder.buildList_MapLevels(myGL, myGLU, glut, mapLevel, Globals.minPoint); DSRCapp = mapLevel[4] + 1; ListBuilder.buildList_DSRCapp(myGL, myGLU, glut, DSRCapp); } public void selection(MouseEvent e) { float winX = e.getX(); float winY = (float) this.getSize().height - (float) e.getY(); float w = (float) (this.getSize().width * zCamera) / high; float h = (float) (this.getSize().height * zCamera) / high; float worldX = xCamera - (float) (w / 2) + (winX * zCamera) / high; float worldY = yCamera - (float) (h / 2) + (winY * zCamera) / high; MyPoint clickPoint = new MyPoint(worldX, worldY); // get's here only when is a selection, not a movement if (carPositions != null) { currentCar = null; currentIntersection = null; if (carPositions.containsValue(clickPoint)) { Iterator i = carPositions.keySet().iterator(); if (i == null) { return; } while (i.hasNext()) { CarInfo ci = i.next(); if (carPositions.get(ci).equals(clickPoint)) { currentCar = (SimulatedCarInfo) ci; Globals.demo.st.setSelection("Selection: car " + currentCar.getVehicleId()); Globals.demo.st.resetLabels(); return; } } } } Point myPoint = recoverRoad(worldX, worldY); for (int i = 0; i < Globals.map.allIntersections.size(); i++) { if (Globals.map.allIntersections.get(i).getMapPoint().distanceTo(myPoint) < 0.01) { Globals.demo.st.setSelection("Selection: intersection " + i); currentIntersection = (WirelessTrafficLight) Globals.map.allIntersections.get(i); return; } } } }