changeset 0:9c4438349e88

added Hello sample programs. Will slowly move all the capture code to here
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 10:42:36 -0700
parents
children ada15b78104c
files .hgignore src/com/aurellem/capture/hello/HelloAudio.java src/com/aurellem/capture/hello/HelloVideo.java
diffstat 3 files changed, 228 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Tue Oct 25 10:42:36 2011 -0700
     1.3 @@ -0,0 +1,7 @@
     1.4 +
     1.5 +syntax: glob
     1.6 +.classpath
     1.7 +.project
     1.8 +.settings*
     1.9 +bin*
    1.10 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/com/aurellem/capture/hello/HelloAudio.java	Tue Oct 25 10:42:36 2011 -0700
     2.3 @@ -0,0 +1,144 @@
     2.4 +package com.aurellem.capture.hello;
     2.5 +
     2.6 +import java.io.File;
     2.7 +import java.util.logging.Level;
     2.8 +import java.util.logging.Logger;
     2.9 +
    2.10 +import com.jme3.app.SimpleApplication;
    2.11 +import com.jme3.audio.AudioNode;
    2.12 +import com.jme3.audio.Listener;
    2.13 +import com.jme3.capture.MultiListener;
    2.14 +import com.jme3.capture.WaveFileWriter;
    2.15 +import com.jme3.input.controls.ActionListener;
    2.16 +import com.jme3.input.controls.MouseButtonTrigger;
    2.17 +import com.jme3.material.Material;
    2.18 +import com.jme3.math.ColorRGBA;
    2.19 +import com.jme3.math.Quaternion;
    2.20 +import com.jme3.math.Vector3f;
    2.21 +import com.jme3.scene.Geometry;
    2.22 +import com.jme3.scene.shape.Box;
    2.23 +import com.jme3.system.AppSettings;
    2.24 +import com.jme3.system.IsoTimer;
    2.25 +
    2.26 +/** Sample 11 - playing 3D audio. */
    2.27 +public class HelloAudio extends SimpleApplication {
    2.28 +	  
    2.29 +  private AudioNode audio_gun;
    2.30 +  private AudioNode audio_nature;
    2.31 +  private Geometry player;
    2.32 +  private Listener auxListener = new Listener(); 
    2.33 +  public File data1 = new File("/home/r/tmp/data1.wav");
    2.34 +  public File data2 = new File("/home/r/tmp/data2.wav");
    2.35 +  public File data3 = new File("/home/r/tmp/data3.wav");
    2.36 +  
    2.37 + 
    2.38 +  
    2.39 +  
    2.40 +  private File makeTarget(int n){
    2.41 +	  	return new File("/home/r/tmp/assload-" + n + ".wav");
    2.42 +  }
    2.43 +  
    2.44 +  
    2.45 +  public static void main(String[] args) {
    2.46 +
    2.47 +	 // Logger.getLogger("com.jme3").setLevel(Level.OFF);
    2.48 +	  
    2.49 +	HelloAudio app = new HelloAudio();
    2.50 +	AppSettings settings = new AppSettings(true);
    2.51 +	settings.setAudioRenderer("Send");
    2.52 +	app.setSettings(settings);
    2.53 +	app.setShowSettings(false);
    2.54 +	app.start();
    2.55 +	app.setPauseOnLostFocus(false);
    2.56 +  }
    2.57 +
    2.58 +  @Override
    2.59 +  public void simpleInitApp() {
    2.60 +	this.setTimer(new IsoTimer(60));
    2.61 +	
    2.62 +	
    2.63 +	if (this.audioRenderer instanceof MultiListener){
    2.64 +		MultiListener rf = (MultiListener)this.audioRenderer;
    2.65 +		
    2.66 +		for (int n = 0; n < 0; n++){
    2.67 +			Listener zzz = new Listener();
    2.68 +			rf.addListener(zzz);
    2.69 +			rf.registerSoundProcessor(
    2.70 +						zzz, new WaveFileWriter(makeTarget(n)));
    2.71 +		}
    2.72 +		Listener listener3 = new Listener();
    2.73 +		rf.addListener(auxListener);
    2.74 +		rf.addListener(listener3);
    2.75 +		rf.registerSoundProcessor(new WaveFileWriter(data1));
    2.76 +		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
    2.77 +		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
    2.78 +	}
    2.79 +    flyCam.setMoveSpeed(40);
    2.80 +    
    2.81 +    /** just a blue box floating in space */
    2.82 +    Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
    2.83 +    player = new Geometry("Player", box1);
    2.84 +    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    2.85 +    mat1.setColor("Color", ColorRGBA.Blue);
    2.86 +    player.setMaterial(mat1);
    2.87 +    rootNode.attachChild(player);
    2.88 +    
    2.89 +    /** custom init methods, see below */
    2.90 +    initKeys();
    2.91 +    initAudio();
    2.92 +	
    2.93 +	this.audioRenderer.playSource(audio_gun);
    2.94 +
    2.95 +	
    2.96 +
    2.97 +  }
    2.98 +
    2.99 +  /** We create two audio nodes. */ 
   2.100 +  private void initAudio() {
   2.101 +	//audioRenderer.setEnvironment(Environment.Cavern);
   2.102 +    /* gun shot sound is to be triggered by a mouse click. */
   2.103 +	//audio_gun = new AudioNode(audioRenderer, assetManager, "Sound/Effects/Gun.wav", false);
   2.104 +	audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
   2.105 +    audio_gun.setLooping(false);
   2.106 +    audio_gun.setVolume(2);
   2.107 +    audio_gun.setPositional(true);
   2.108 +
   2.109 +
   2.110 +    /* nature sound - keeps playing in a loop. */
   2.111 +    audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false);
   2.112 +    audio_nature.setLooping(true);
   2.113 +    audio_nature.setPositional(true);
   2.114 +    audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
   2.115 +    audio_nature.setVolume(3);
   2.116 +    audio_nature.updateGeometricState();
   2.117 +  }
   2.118 +
   2.119 +  /** Declaring the "Shoot" action, and
   2.120 +   *  mapping it to a trigger (mouse click). */
   2.121 +  private void initKeys() {
   2.122 +    inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
   2.123 +    inputManager.addListener(actionListener, "Shoot");
   2.124 +  }
   2.125 +
   2.126 +  /** Defining the "Shoot" action: Play a gun sound. */
   2.127 +  private ActionListener actionListener = new ActionListener() {
   2.128 +    @Override
   2.129 +    public void onAction(String name, boolean keyPressed, float tpf) {
   2.130 +      if (name.equals("Shoot") && !keyPressed) {
   2.131 +        audioRenderer.playSource(audio_gun); // play once!
   2.132 +      }
   2.133 +    }
   2.134 +  };
   2.135 +
   2.136 +  /** Move the listener with the camera - for 3D audio. */
   2.137 +  @Override
   2.138 +  public void simpleUpdate(float tpf) {
   2.139 +	Vector3f loc = cam.getLocation();
   2.140 +	Quaternion rot = cam.getRotation();
   2.141 +    listener.setLocation(loc);
   2.142 +    listener.setRotation(rot);
   2.143 +    auxListener.setLocation(loc);
   2.144 +    auxListener.setRotation(rot);
   2.145 +  }
   2.146 +
   2.147 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/com/aurellem/capture/hello/HelloVideo.java	Tue Oct 25 10:42:36 2011 -0700
     3.3 @@ -0,0 +1,77 @@
     3.4 +package com.aurellem.capture.hello;
     3.5 +
     3.6 +import java.io.File;
     3.7 +import java.io.IOException;
     3.8 +
     3.9 +import com.jme3.app.SimpleApplication;
    3.10 +import com.jme3.capture.AVIVideoRecorder;
    3.11 +import com.jme3.capture.AbstractVideoRecorder;
    3.12 +import com.jme3.capture.Capture;
    3.13 +import com.jme3.material.Material;
    3.14 +import com.jme3.math.ColorRGBA;
    3.15 +import com.jme3.math.Vector3f;
    3.16 +import com.jme3.renderer.ViewPort;
    3.17 +import com.jme3.scene.Geometry;
    3.18 +import com.jme3.scene.shape.Box;
    3.19 +import com.jme3.system.IsoTimer;
    3.20 +
    3.21 +/** Recording Video from an application suitable for upload to youtube.*/
    3.22 +public class HelloVideo extends SimpleApplication {
    3.23 +
    3.24 +	/*File staticVideo = 
    3.25 +		new File("/home/r/bullshit.avi");
    3.26 +		*/
    3.27 +	File movingVideo = 
    3.28 +		new File("/home/r/tmp/bullshit2.avi");
    3.29 +
    3.30 +	AbstractVideoRecorder movingRecorder ;
    3.31 +	
    3.32 +    public static void main(String[] args){
    3.33 +        HelloVideo app = new HelloVideo();
    3.34 +        app.start();
    3.35 +    }
    3.36 +
    3.37 +    public void initVideo(){ 
    3.38 +    	this.setTimer(new IsoTimer(60));
    3.39 +    	/*try{
    3.40 +    		// set the timer to 30fps lock-step
    3.41 +    		this.setTimer(new IsoTimer(30)); 
    3.42 +    		
    3.43 +    		//ViewPort compositeViewPort = renderManager.createFinalView("composite", cam);
    3.44 +    		//compositeViewPort.attachScene(this.rootNode);
    3.45 +    		//compositeViewPort.attachScene(this.guiNode);
    3.46 +    		this.viewPort.setClearFlags(true, true, true);
    3.47 +    		this.viewPort.setBackgroundColor(ColorRGBA.Black);
    3.48 +    		movingRecorder = new AVIVideoRecorder(movingVideo); 
    3.49 +    		this.stateManager.attach(movingRecorder);
    3.50 +    		this.viewPort.addFinalProcessor(movingRecorder);
    3.51 +    		this.viewPort.attachScene(this.guiNode);
    3.52 +    		
    3.53 +    	}catch (IOException e) {
    3.54 +    		e.printStackTrace();}
    3.55 +    		*/
    3.56 +    	try {Capture.SimpleCaptureVideo(this, movingVideo);} 
    3.57 +    	catch (IOException e) {e.printStackTrace();}
    3.58 +		
    3.59 +    }
    3.60 +    protected Geometry player;
    3.61 +    
    3.62 +    public void simpleInitApp() {
    3.63 +    	initVideo(); // begin recording!
    3.64 +    	/** this blue box is our player character */
    3.65 +    	Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    3.66 +    	player = new Geometry("blue cube", b);
    3.67 +    	Material mat = new Material(assetManager,
    3.68 +    		"Common/MatDefs/Misc/Unshaded.j3md");
    3.69 +    	mat.setColor("Color", ColorRGBA.Blue);
    3.70 +    	player.setMaterial(mat);
    3.71 +    	rootNode.attachChild(player);
    3.72 +    }
    3.73 +
    3.74 +    /* Use the main event loop to trigger repeating actions. */
    3.75 +    public void simpleUpdate(float tpf) {
    3.76 +        // make the player rotate:
    3.77 +        player.rotate(0, 2*tpf, 0); 
    3.78 +    }
    3.79 +    
    3.80 +} 
    3.81 \ No newline at end of file