00001 package org.hfbk.vis.visnode;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileNotFoundException;
00006 import java.io.FileReader;
00007 import java.io.IOException;
00008 import java.util.LinkedList;
00009 import java.util.List;
00010
00011 import org.dronus.graph.Node;
00012 import org.lwjgl.opengl.GL11;
00013 import org.lwjgl.util.vector.Vector3f;
00014
00015 public class VisMap extends VisNode{
00016
00017 int dl;
00018 float tx,ty,tz,maxx,maxz,minx,minz;
00019
00020 List<List<Vector3f>> walls=new LinkedList<List<Vector3f>>();
00021 List<Vector3f> markers=new LinkedList<Vector3f>();
00022
00023 String mapfile="salon.coord";
00024
00025 public VisMap(Node node, Vector3f position) {
00026
00027 super(node,position);
00028
00029 if (node.text.length()>0)
00030 mapfile=node.text;
00031
00032 loadWalls();
00033
00034 radius=2000;
00035
00036
00037
00038
00039
00040
00041
00042 }
00043
00044
00045 private void loadWalls() {
00046
00047 try {
00048 BufferedReader r=new BufferedReader(new FileReader(new File(mapfile)));
00049 String l;
00050 maxx=-100000;maxz=-100000;
00051 minx=100000;minz=100000;
00052 do{
00053
00054 List<Vector3f> currentWall=new LinkedList<Vector3f>();
00055
00056 walls.add(currentWall);
00057
00058 while ((l=r.readLine())!=null){
00059 if (l.equals(""))
00060 break;
00061 else{
00062 String[] coords=l.split(" ");
00063
00064 if (coords[0].equals("M"))
00065 {
00066 markers.add(new Vector3f(Float.parseFloat(coords[1]),
00067 Float.parseFloat(coords[2]),
00068 Float.parseFloat(coords[3])
00069 ));
00070 }
00071 else
00072 {
00073 tx=Float.parseFloat(coords[0]);
00074 ty=Float.parseFloat(coords[1]);
00075 tz=Float.parseFloat(coords[2]);
00076
00077
00078 minx=Math.min(tx,minx);
00079
00080 maxx=Math.max(tx,maxx);
00081
00082
00083 minz=Math.min(tz,minz);
00084 maxz=Math.max(tz,maxz);
00085
00086 currentWall.add( new Vector3f(tx,ty,tz
00087 ));
00088
00089
00090 }
00091 }
00092 }
00093 }while(l!=null);
00094 System.out.println(minz+" "+maxz+" "+minx+" "+maxx);
00095 add(new VisInteractive(null, new Vector3f(-(maxx-minx)/2, 0,-(maxz-minz)/2), new Vector3f((maxx-minx),0,(maxz-minz))));
00096
00097 } catch (FileNotFoundException e) {
00098 e.printStackTrace();
00099 } catch (NumberFormatException e) {
00100
00101 e.printStackTrace();
00102 } catch (IOException e) {
00103
00104 e.printStackTrace();
00105 }
00106
00107
00108 }
00109
00110 @Override
00111 void transform() {
00112 super.transform();
00113
00114 GL11.glTranslatef(0,-5,0);
00115 }
00116
00117 @Override
00118 void renderSelf() {
00119
00120 if (dl==0){
00121 dl=GL11.glGenLists(1);
00122 GL11.glNewList(dl, GL11.GL_COMPILE);
00123 GL11.glDisable(GL11.GL_TEXTURE_2D);
00124
00125 GL11.glColor4f(1,1,1,.5f);
00126 for (List<Vector3f>wall : walls){
00127 GL11.glBegin(GL11.GL_LINE_STRIP);
00128 for (Vector3f segment: wall)
00129 GL11.glVertex3f(segment.x, 0,segment.z);
00130 GL11.glEnd();
00131 GL11.glBegin(GL11.GL_LINE_STRIP);
00132 for (Vector3f segment: wall)
00133 GL11.glVertex3f(segment.x, segment.y,segment.z);
00134 GL11.glEnd();
00135 GL11.glBegin(GL11.GL_LINES);
00136 for (Vector3f segment: wall){
00137 GL11.glVertex3f(segment.x, 0,segment.z);
00138 GL11.glVertex3f(segment.x, segment.y,segment.z);
00139 }
00140 GL11.glEnd();
00141 }
00142
00143 GL11.glBegin(GL11.GL_LINES);
00144 for (Vector3f segment: markers){
00145 GL11.glVertex3f(segment.x, segment.y,segment.z);
00146 GL11.glVertex3f(segment.x, segment.y+50,segment.z);
00147 }
00148 GL11.glEnd();
00149
00150
00151
00152
00153 GL11.glDisable(GL11.GL_LIGHTING);
00154 GL11.glEndList();
00155 }
00156 GL11.glCallList(dl);
00157 }
00158 }