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

Go to the documentation of this file.
00001 /*
00002  * Created on 07.05.2008
00003  */
00004 package org.hfbk.vis.visnode;
00005 
00006 
00007 import java.awt.event.MouseEvent;
00008 
00009 import org.dronus.gl.Buffers;
00010 import org.dronus.gl.GLUtil;
00011 import org.dronus.graph.Node;
00012 import org.hfbk.vid.VideoFetcher;
00013 import org.hfbk.vid.VideoTexture;
00014 import org.lwjgl.openal.AL10;
00015 import org.lwjgl.opengl.GL11;
00016 import org.lwjgl.util.vector.Vector3f;
00017 
00027 public class VisVideo extends VisNodeDraggable {
00028 
00029         final float SCALE=15f;
00030         
00031         VideoTexture tex=null;
00032         VideoFetcher fetcher;
00033         
00034         String url;
00035         
00039         boolean playing=true;
00040         
00044         public VisVideo(Node n, Vector3f position) {
00045                 super(n, position);
00046                 fetcher=new VideoFetcher(n.text);
00047         }
00048 
00052         public void add(VisNode node) {}
00053 
00057         void renderSelf() {
00058                 
00059                 if (tex!=null){ //we are ready to play
00060                         float dt=0;
00061                         if (playing) 
00062                                 dt=getRoot().client.dt;
00063                         tex.render(dt); // apply texture, maybe signalling end of clip.         
00064                         
00065                         //calculate fade away when viewer passes
00066                         Vector3f pos=new Vector3f(GLUtil.getPosition());
00067                         float alpha=Math.max(Math.min(-pos.z/20,1),0);
00068                         GL11.glColor4f(1,1,1,alpha);
00069                                 
00070                         GLUtil.renderQuad(-w/2,-h/2,w/2,h/2, tex.imagewidth, tex.imageheight);
00071                         
00072                         int audioSource=tex.streamer.getAudioSource();
00073                         if (audioSource>0) {
00074                                 Vector3f worldPosition=traverse(getRoot(), new Vector3f());
00075                                 AL10.alSource(audioSource, AL10.AL_POSITION, Buffers.buffer(worldPosition));
00076                         }
00077                 }else if (fetcher.streamer!=null){ //the media is opened
00078                         tex=new VideoTexture(fetcher.streamer);
00079                         
00080                         w=tex.width; h=tex.height;
00081                         float scale=Math.max(w,h); //some nice scaling
00082                         scale=SCALE/scale;
00083                         w*=scale; h*=scale;
00084                         radius=Math.max(w,h);   
00085                 }
00086         }
00087 
00091         void handleEvent(VisMouseEvent evt) {
00092                 super.handleEvent(evt);
00093                 if (evt.getID()==MouseEvent.MOUSE_CLICKED){
00094                         playing=!playing;
00095                         if (tex!=null) tex.streamer.setPlaying(playing);
00096                 }
00097         }
00098         
00100         void closeSelf() {
00101                 if (tex!=null) tex.close();
00102         }
00103 }

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