VisClient/org/hfbk/vis/visnode/VisBit.java

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 
00004 import org.dronus.graph.Node;
00005 import org.lwjgl.opengl.GL11;
00006 import org.lwjgl.util.vector.Vector3f;
00007 
00013 public class VisBit extends VisNode {
00014         
00015         
00016         class BitIdle extends VisObj{
00017                 public BitIdle() {
00018                         super("obj/great_stellated_dodecahedron.obj", new Vector3f());
00019                 }
00020                 
00021                 void renderSelf() {
00022                         if (dl==0){
00023                                 dl=GL11.glGenLists(1); 
00024                                 GL11.glNewList(dl, GL11.GL_COMPILE);
00025                                 
00026                                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00027                                 
00028                                 GL11.glPolygonOffset(1,1); //push back the surface in z buffer to allow clean wireframe drawing
00029                                 GL11.glColor4f(.2f,1f,1f,.85f);
00030                                 drawFaces();
00031                                 GL11.glPolygonOffset(0,0);
00032                                 
00033                                 GL11.glColor3f(0,0,0);
00034                                 drawWireframe();
00035                                 
00036                                 GL11.glEndList();
00037                         }
00038                         super.renderSelf();
00039                 }
00040         }
00041 
00042         class BitOff extends VisObj{
00043                 public BitOff() {
00044                         super("obj/great_stellated_dodecahedron.obj", new Vector3f());
00045                 }
00046                 
00047                 void renderSelf() {
00048                         if (dl==0){
00049                                 dl=GL11.glGenLists(1); 
00050                                 GL11.glNewList(dl, GL11.GL_COMPILE);
00051                                 
00052                                 GL11.glScalef(1.3f,1.3f,1.3f);
00053                                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00054                                 
00055                                 GL11.glPolygonOffset(1,1); //push back the surface in z buffer to allow clean wireframe drawing
00056                                 GL11.glColor3f(.9f,.1f,.1f);
00057                                 drawFaces();
00058                                 GL11.glPolygonOffset(0,0);
00059                                 
00060                                 GL11.glColor3f(1,1,1);
00061                                 drawWireframe();
00062                                 
00063                                 GL11.glEndList();
00064                         }
00065                         super.renderSelf();
00066                 }
00067         }
00068 
00069         class BitOn extends VisObj{
00070                 public BitOn() {
00071                         super("obj/icosaeder.obj", new Vector3f());
00072                 }
00073                 
00074                 void renderSelf() {
00075                         if (dl==0){
00076                                 dl=GL11.glGenLists(1); 
00077                                 GL11.glNewList(dl, GL11.GL_COMPILE);                                    
00078                                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00079                                 
00080                                 GL11.glScalef(2f,2f,2f);
00081                                 
00082                                 GL11.glPolygonOffset(1,1); //push back the surface in z buffer to allow clean wireframe drawing
00083                                 GL11.glColor3f(1f,.9f,0);
00084                                 drawFaces();
00085                                 GL11.glPolygonOffset(0,0);
00086                                 
00087                                 GL11.glColor3f(1,1,1);
00088                                 drawWireframe();
00089                                 
00090                                 GL11.glEndList();
00091                         }
00092                         super.renderSelf();
00093                 }
00094         }
00095         
00096         
00097         VisNode[]  shape=new VisNode[] {new BitIdle(), new BitOff(), new BitOn()};
00098         Sound[] sound=new Sound[]{null, new Sound("sound/nein.wav"),new Sound("sound/ja.wav")};
00099         
00100         int state;
00101         final int IDLE=0, NO=1, YES=2;
00102         
00103         float time,cycle=20;
00104         Vector3f velocity=new Vector3f(1,0,0);
00105         
00106         public VisBit(Node dummy, Vector3f pos) {
00107                 super(null, pos);
00108         
00109                 add(shape[IDLE]);
00110                 for(VisNode s: sound) if (s!=null) add(s);
00111         }
00112 
00113         Vector3f randomVector3f(){
00114                 return new Vector3f((float)Math.random()-.5f,(float)Math.random()-.5f,(float)Math.random()-.5f);
00115         }
00116         
00117         void state(int newState){
00118                 if (state!=newState){
00119                         remove(shape[state]);
00120                         state=newState;
00121                         add(shape[state]);
00122                         if(sound[state]!=null) sound[state].trigger();
00123                 }
00124         }
00125         
00126         @Override       
00127         void renderSelf() {
00128                 float dt=getRoot().client.dt;
00129                 
00130                 time+=dt;               
00131                 if (state==IDLE && time>cycle){         
00132                         time=0;
00133                         cycle=(float)Math.random()*80;
00134                         velocity=randomVector3f();
00135                         
00136                         state(Math.random()>.6 ? YES : NO );
00137                 }
00138                 if (time>.3) state(IDLE);
00139                 
00140                 
00141                 Vector3f dposition=new Vector3f(velocity);
00142                 dposition.scale(dt*4);
00143                 Vector3f.add(position, dposition, position);
00144                 
00145                 Vector3f dcenter=getRoot().traverse(this,getRoot().epicenter);
00146                 dcenter.scale(.0001f);
00147                 Vector3f.add(position, dcenter,   position);
00148                 
00149         }
00150 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1