changeset 15:be5ac56826be

created part of the advanced documentation
author Robert McIntyre <rlm@mit.edu>
date Fri, 28 Oct 2011 06:52:46 -0700
parents e299cd89074d
children 87f818f58975
files src/com/aurellem/capture/examples/AdvancedAudio.java src/com/aurellem/capture/examples/Basic.java src/com/aurellem/capture/video/AVIVideoRecorder.java
diffstat 3 files changed, 158 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Thu Oct 27 21:55:51 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Fri Oct 28 06:52:46 2011 -0700
     1.3 @@ -8,14 +8,23 @@
     1.4  import com.jme3.app.SimpleApplication;
     1.5  import com.jme3.audio.AudioNode;
     1.6  import com.jme3.audio.Listener;
     1.7 +import com.jme3.cinematic.MotionPath;
     1.8 +import com.jme3.cinematic.events.MotionTrack;
     1.9 +import com.jme3.input.KeyInput;
    1.10  import com.jme3.input.controls.ActionListener;
    1.11 +import com.jme3.input.controls.KeyTrigger;
    1.12  import com.jme3.input.controls.MouseButtonTrigger;
    1.13 +import com.jme3.light.DirectionalLight;
    1.14  import com.jme3.material.Material;
    1.15  import com.jme3.math.ColorRGBA;
    1.16 +import com.jme3.math.FastMath;
    1.17  import com.jme3.math.Quaternion;
    1.18  import com.jme3.math.Vector3f;
    1.19  import com.jme3.scene.Geometry;
    1.20 +import com.jme3.scene.Node;
    1.21 +import com.jme3.scene.Spatial;
    1.22  import com.jme3.scene.shape.Box;
    1.23 +import com.jme3.scene.shape.Sphere;
    1.24  import com.jme3.system.AppSettings;
    1.25  
    1.26  
    1.27 @@ -39,18 +48,142 @@
    1.28   */
    1.29  
    1.30  public class AdvancedAudio extends SimpleApplication {
    1.31 -	    
    1.32 -  public static void main(String[] args) {
    1.33 -	  
    1.34 -	AdvancedAudio app = new AdvancedAudio();
    1.35 -	AppSettings settings = new AppSettings(true);
    1.36 +
    1.37 +	  public static void main(String[] args) {
    1.38 +		  
    1.39 +			AdvancedAudio app = new AdvancedAudio();
    1.40 +			AppSettings settings = new AppSettings(true);
    1.41 +			//settings.setAudioRenderer("Send");
    1.42 +			app.setSettings(settings);
    1.43 +			app.setShowSettings(false);
    1.44 +			app.setPauseOnLostFocus(false);
    1.45 +			org.lwjgl.input.Mouse.setGrabbed(false);
    1.46 +			app.start();
    1.47 +	  }
    1.48 +
    1.49  	
    1.50 -	settings.setAudioRenderer("Send");
    1.51 -	app.setSettings(settings);
    1.52 -	app.setShowSettings(false);
    1.53 -	app.start();
    1.54 -	app.setPauseOnLostFocus(false);
    1.55 -  }
    1.56 +	 private Spatial teapot;
    1.57 +	 private boolean active = true;
    1.58 +	 private boolean playing = false;
    1.59 +	 private MotionPath path;
    1.60 +	 private MotionTrack motionControl;
    1.61 +	
    1.62 +	 
    1.63 +	 private void makeEar(Node root, Vector3f position){
    1.64 +		 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    1.65 +		 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
    1.66 +		 ear.setLocalTranslation(position);
    1.67 +		 mat.setColor("Color", ColorRGBA.Green);
    1.68 +		 ear.setMaterial(mat);
    1.69 +		 root.attachChild(ear);
    1.70 +	 }
    1.71 +	 
    1.72 +	 
    1.73 +	 private void createScene() {
    1.74 +		 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    1.75 +		 Geometry bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
    1.76 +		 mat.setColor("Color", ColorRGBA.Blue);
    1.77 +		 bell.setMaterial(mat);
    1.78 +		 rootNode.attachChild(bell);
    1.79 +
    1.80 +		
    1.81 +		 
    1.82 +		 
    1.83 +		 DirectionalLight light = new DirectionalLight();
    1.84 +		 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    1.85 +		 light.setColor(ColorRGBA.White.mult(1.5f));
    1.86 +		 rootNode.addLight(light);
    1.87 +
    1.88 +		 makeEar(rootNode, new Vector3f(0, 0 ,20));
    1.89 +		 makeEar(rootNode, new Vector3f(0, 0 ,-20));
    1.90 +		 makeEar(rootNode, new Vector3f(20, 0 ,0));
    1.91 +		 makeEar(rootNode, new Vector3f(-20, 0 ,0));
    1.92 +
    1.93 +		 MotionPath path = new MotionPath();
    1.94 +		 
    1.95 +		 // loop 1
    1.96 +		 path.addWayPoint(new Vector3f(0, 0, 0));
    1.97 +		 path.addWayPoint(new Vector3f(0, 0, -10));
    1.98 +		 path.addWayPoint(new Vector3f(-2, 0, -14));
    1.99 +		 path.addWayPoint(new Vector3f(-6, 0, -20));
   1.100 +		 path.addWayPoint(new Vector3f(0, 0, -26));
   1.101 +		 path.addWayPoint(new Vector3f(6, 0, -20));
   1.102 +		 path.addWayPoint(new Vector3f(0, 0, -14));
   1.103 +		 path.addWayPoint(new Vector3f(-6, 0, -20));
   1.104 +		 path.addWayPoint(new Vector3f(0, 0, -26));
   1.105 +		 path.addWayPoint(new Vector3f(6, 0, -20));
   1.106 +		 	 
   1.107 +		 
   1.108 +		 // loop 2
   1.109 +		 path.addWayPoint(new Vector3f(5, 0, -5));
   1.110 +		 path.addWayPoint(new Vector3f(7, 0, 1.5f));
   1.111 +		 path.addWayPoint(new Vector3f(14, 0, 2));
   1.112 +		 path.addWayPoint(new Vector3f(20, 0, 6));
   1.113 +		 path.addWayPoint(new Vector3f(26, 0, 0));
   1.114 +		 path.addWayPoint(new Vector3f(20, 0, -6));
   1.115 +		 path.addWayPoint(new Vector3f(14, 0, 0));
   1.116 +		 path.addWayPoint(new Vector3f(20, 0, 6));
   1.117 +		 path.addWayPoint(new Vector3f(26, 0, 0));
   1.118 +		 path.addWayPoint(new Vector3f(20, 0, -6));
   1.119 +		 path.addWayPoint(new Vector3f(14, 0, 0));
   1.120 +		 
   1.121 +		 
   1.122 +		 
   1.123 +		 // loop 3
   1.124 +		 path.addWayPoint(new Vector3f(8, 0, 7.5f));
   1.125 +		 path.addWayPoint(new Vector3f(7, 0, 10.5f));
   1.126 +		 path.addWayPoint(new Vector3f(6, 0, 20));
   1.127 +		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.128 +		 path.addWayPoint(new Vector3f(-6, 0, 20));
   1.129 +		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.130 +		 path.addWayPoint(new Vector3f(6, 0, 20));
   1.131 +		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.132 +		 path.addWayPoint(new Vector3f(-6, 0, 20));
   1.133 +		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.134 +		 
   1.135 +		 
   1.136 +		 // begin elipse
   1.137 +
   1.138 +		 path.addWayPoint(new Vector3f(16, 5, 20));
   1.139 +		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.140 +		 path.addWayPoint(new Vector3f(-16, -10, 20));
   1.141 +		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.142 +		 path.addWayPoint(new Vector3f(16, 20, 20));
   1.143 +		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.144 +		 path.addWayPoint(new Vector3f(-10, -25, 10));
   1.145 +		 path.addWayPoint(new Vector3f(-10, 0, 0));
   1.146 +		 
   1.147 +		 // come at me bro!
   1.148 +		 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   1.149 +		 path.setCurveTension(0.80f);
   1.150 +
   1.151 +		 
   1.152 +		 motionControl = new MotionTrack(bell,path);
   1.153 +	     motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
   1.154 +	     motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
   1.155 +	     motionControl.setInitialDuration(10f);
   1.156 +	     motionControl.setSpeed(0.1f);
   1.157 +		 
   1.158 +		 
   1.159 +		 //path.enableDebugShape(assetManager, rootNode);
   1.160 +
   1.161 +
   1.162 +		 positionCamera();
   1.163 +		
   1.164 +	        
   1.165 +	    }
   1.166 +
   1.167 +	 
   1.168 +	 private void positionCamera(){
   1.169 +		this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   1.170 +		this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
   1.171 +		
   1.172 +
   1.173 +	 }
   1.174 +	 
   1.175 +	 
   1.176 +	
   1.177 +	
   1.178  
   1.179    private AudioNode audio_gun;
   1.180    private AudioNode audio_nature;
   1.181 @@ -60,15 +193,10 @@
   1.182    public File data2 = new File("/home/r/tmp/data2.wav");
   1.183    public File data3 = new File("/home/r/tmp/data3.wav");
   1.184     
   1.185 -  private File makeTarget(int n){
   1.186 -	  	return new File("/home/r/tmp/assload-" + n + ".wav");
   1.187 -  }
   1.188 -  
   1.189    
   1.190    @Override
   1.191    public void simpleInitApp() {
   1.192 -	this.setTimer(new IsoTimer(60));
   1.193 -	
   1.194 +	//this.setTimer(new IsoTimer(60));
   1.195  	
   1.196  	if (this.audioRenderer instanceof MultiListener){
   1.197  		MultiListener rf = (MultiListener)this.audioRenderer;
   1.198 @@ -76,8 +204,6 @@
   1.199  		for (int n = 0; n < 0; n++){
   1.200  			Listener zzz = new Listener();
   1.201  			rf.addListener(zzz);
   1.202 -			rf.registerSoundProcessor(
   1.203 -						zzz, new WaveFileWriter(makeTarget(n)));
   1.204  		}
   1.205  		Listener listener3 = new Listener();
   1.206  		rf.addListener(auxListener);
   1.207 @@ -86,19 +212,17 @@
   1.208  		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
   1.209  		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
   1.210  	}
   1.211 -    flyCam.setMoveSpeed(40);
   1.212      
   1.213 -    /** just a blue box floating in space */
   1.214 -    Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
   1.215 -    player = new Geometry("Player", box1);
   1.216 -    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   1.217 -    mat1.setColor("Color", ColorRGBA.Blue);
   1.218 -    player.setMaterial(mat1);
   1.219 -    rootNode.attachChild(player);
   1.220      
   1.221 -    /** custom init methods, see below */
   1.222 +    
   1.223 +        
   1.224 +    
   1.225      initKeys();
   1.226      initAudio();
   1.227 +	createScene();
   1.228 +	 
   1.229 +
   1.230 +    motionControl.play();
   1.231  	
   1.232  	this.audioRenderer.playSource(audio_gun);
   1.233  
   1.234 @@ -152,10 +276,7 @@
   1.235      listener.setRotation(rot);
   1.236      auxListener.setLocation(loc);
   1.237      auxListener.setRotation(rot);
   1.238 -    if (audio_gun.getStatus() == AudioNode.Status.Stopped){
   1.239 -    	System.out.println("I'm Stopped!");
   1.240 -    	this.requestClose(false);
   1.241 -    }
   1.242 +    
   1.243      	
   1.244      	
   1.245    }
     2.1 --- a/src/com/aurellem/capture/examples/Basic.java	Thu Oct 27 21:55:51 2011 -0700
     2.2 +++ b/src/com/aurellem/capture/examples/Basic.java	Fri Oct 28 06:52:46 2011 -0700
     2.3 @@ -25,44 +25,12 @@
     2.4  
     2.5  public class Basic {
     2.6  	
     2.7 -	public static void basicVideo() throws IOException{
     2.8 -		File video = File.createTempFile("HelloJME3", ".avi");
     2.9 -		System.out.println("Saving video to: " + video.getCanonicalPath());
    2.10 -		SimpleApplication app = new HelloJME3();
    2.11 -		app.setTimer(new IsoTimer(60));
    2.12 -		app.setShowSettings(false);
    2.13 +	public static void main(String[] ignore) throws IOException{
    2.14 +		File video = File.createTempFile("JME-water-video", ".avi");
    2.15 +		File audio = File.createTempFile("JME-water-audio", ".wav");
    2.16  		
    2.17 -		Capture.captureVideo(app, video);
    2.18 -		app.start();
    2.19 -	}
    2.20 -	
    2.21 -	public static void basicVideoGUI() throws IOException {
    2.22 -		File video = File.createTempFile("GUI", ".avi");
    2.23 -		System.out.println("Saving video to: " + video.getCanonicalPath());
    2.24 -		SimpleApplication app = new TestNiftyExamples();
    2.25 -		app.setTimer(new IsoTimer(60));
    2.26 -		app.setShowSettings(false);
    2.27 -		
    2.28 -		Capture.captureVideo(app, video);
    2.29 -		app.start();
    2.30 -	}
    2.31 -	
    2.32 -	public static void basicAudio() throws IOException{
    2.33 -		File audio = File.createTempFile("BasicAudio", ".wav");
    2.34 -		System.out.println("Saving audio to: " + audio.getCanonicalPath());
    2.35 -		SimpleApplication app = new HelloAudio();
    2.36 -		app.setTimer(new IsoTimer(60));
    2.37 -		app.setShowSettings(false);
    2.38 -		
    2.39 -		// you will not hear the audio while it is being captured.
    2.40 -		Capture.captureAudio(app, audio);
    2.41 -		
    2.42 -		app.start();
    2.43 -	}
    2.44 -	
    2.45 -	public static void basicAudioVideo() throws IOException{
    2.46 -		File video = new File("/home/r/tmp/basicVideo.avi");
    2.47 -		File audio = new File("/home/r/tmp/basicAudio.wav");
    2.48 +		System.out.println(video.getCanonicalPath());
    2.49 +		System.out.println(audio.getCanonicalPath());
    2.50  		
    2.51  		SimpleApplication app = new TestPostWater();
    2.52  		app.setTimer(new IsoTimer(60));
    2.53 @@ -73,12 +41,4 @@
    2.54  		
    2.55  		app.start();
    2.56  	}
    2.57 -	
    2.58 -	
    2.59 -	public static void main(String[] ignore) throws IOException{
    2.60 -		basicVideo();
    2.61 -		basicVideoGUI();
    2.62 -		basicAudio();
    2.63 -		basicAudioVideo();
    2.64 -	}
    2.65  }
     3.1 --- a/src/com/aurellem/capture/video/AVIVideoRecorder.java	Thu Oct 27 21:55:51 2011 -0700
     3.2 +++ b/src/com/aurellem/capture/video/AVIVideoRecorder.java	Fri Oct 28 06:52:46 2011 -0700
     3.3 @@ -38,7 +38,6 @@
     3.4  	}
     3.5  	
     3.6  	public void finish() {
     3.7 -		System.out.println("I'm finished! <3");
     3.8  		try {out.close();} 
     3.9  		catch (IOException e) {e.printStackTrace();}
    3.10  	}