# HG changeset patch # User Robert McIntyre # Date 1319564556 25200 # Node ID 9c4438349e88143e790963dcd88b44ee08d9adc0 added Hello sample programs. Will slowly move all the capture code to here diff -r 000000000000 -r 9c4438349e88 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Oct 25 10:42:36 2011 -0700 @@ -0,0 +1,7 @@ + +syntax: glob +.classpath +.project +.settings* +bin* + diff -r 000000000000 -r 9c4438349e88 src/com/aurellem/capture/hello/HelloAudio.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/hello/HelloAudio.java Tue Oct 25 10:42:36 2011 -0700 @@ -0,0 +1,144 @@ +package com.aurellem.capture.hello; + +import java.io.File; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.jme3.app.SimpleApplication; +import com.jme3.audio.AudioNode; +import com.jme3.audio.Listener; +import com.jme3.capture.MultiListener; +import com.jme3.capture.WaveFileWriter; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.MouseButtonTrigger; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; +import com.jme3.system.AppSettings; +import com.jme3.system.IsoTimer; + +/** Sample 11 - playing 3D audio. */ +public class HelloAudio extends SimpleApplication { + + private AudioNode audio_gun; + private AudioNode audio_nature; + private Geometry player; + private Listener auxListener = new Listener(); + public File data1 = new File("/home/r/tmp/data1.wav"); + public File data2 = new File("/home/r/tmp/data2.wav"); + public File data3 = new File("/home/r/tmp/data3.wav"); + + + + + private File makeTarget(int n){ + return new File("/home/r/tmp/assload-" + n + ".wav"); + } + + + public static void main(String[] args) { + + // Logger.getLogger("com.jme3").setLevel(Level.OFF); + + HelloAudio app = new HelloAudio(); + AppSettings settings = new AppSettings(true); + settings.setAudioRenderer("Send"); + app.setSettings(settings); + app.setShowSettings(false); + app.start(); + app.setPauseOnLostFocus(false); + } + + @Override + public void simpleInitApp() { + this.setTimer(new IsoTimer(60)); + + + if (this.audioRenderer instanceof MultiListener){ + MultiListener rf = (MultiListener)this.audioRenderer; + + for (int n = 0; n < 0; n++){ + Listener zzz = new Listener(); + rf.addListener(zzz); + rf.registerSoundProcessor( + zzz, new WaveFileWriter(makeTarget(n))); + } + Listener listener3 = new Listener(); + rf.addListener(auxListener); + rf.addListener(listener3); + rf.registerSoundProcessor(new WaveFileWriter(data1)); + rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); + rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); + } + flyCam.setMoveSpeed(40); + + /** just a blue box floating in space */ + Box box1 = new Box(Vector3f.ZERO, 1, 1, 1); + player = new Geometry("Player", box1); + Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + mat1.setColor("Color", ColorRGBA.Blue); + player.setMaterial(mat1); + rootNode.attachChild(player); + + /** custom init methods, see below */ + initKeys(); + initAudio(); + + this.audioRenderer.playSource(audio_gun); + + + + } + + /** We create two audio nodes. */ + private void initAudio() { + //audioRenderer.setEnvironment(Environment.Cavern); + /* gun shot sound is to be triggered by a mouse click. */ + //audio_gun = new AudioNode(audioRenderer, assetManager, "Sound/Effects/Gun.wav", false); + audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false); + audio_gun.setLooping(false); + audio_gun.setVolume(2); + audio_gun.setPositional(true); + + + /* nature sound - keeps playing in a loop. */ + audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false); + audio_nature.setLooping(true); + audio_nature.setPositional(true); + audio_nature.setLocalTranslation(Vector3f.ZERO.clone()); + audio_nature.setVolume(3); + audio_nature.updateGeometricState(); + } + + /** Declaring the "Shoot" action, and + * mapping it to a trigger (mouse click). */ + private void initKeys() { + inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); + inputManager.addListener(actionListener, "Shoot"); + } + + /** Defining the "Shoot" action: Play a gun sound. */ + private ActionListener actionListener = new ActionListener() { + @Override + public void onAction(String name, boolean keyPressed, float tpf) { + if (name.equals("Shoot") && !keyPressed) { + audioRenderer.playSource(audio_gun); // play once! + } + } + }; + + /** Move the listener with the camera - for 3D audio. */ + @Override + public void simpleUpdate(float tpf) { + Vector3f loc = cam.getLocation(); + Quaternion rot = cam.getRotation(); + listener.setLocation(loc); + listener.setRotation(rot); + auxListener.setLocation(loc); + auxListener.setRotation(rot); + } + +} diff -r 000000000000 -r 9c4438349e88 src/com/aurellem/capture/hello/HelloVideo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/hello/HelloVideo.java Tue Oct 25 10:42:36 2011 -0700 @@ -0,0 +1,77 @@ +package com.aurellem.capture.hello; + +import java.io.File; +import java.io.IOException; + +import com.jme3.app.SimpleApplication; +import com.jme3.capture.AVIVideoRecorder; +import com.jme3.capture.AbstractVideoRecorder; +import com.jme3.capture.Capture; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.renderer.ViewPort; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; +import com.jme3.system.IsoTimer; + +/** Recording Video from an application suitable for upload to youtube.*/ +public class HelloVideo extends SimpleApplication { + + /*File staticVideo = + new File("/home/r/bullshit.avi"); + */ + File movingVideo = + new File("/home/r/tmp/bullshit2.avi"); + + AbstractVideoRecorder movingRecorder ; + + public static void main(String[] args){ + HelloVideo app = new HelloVideo(); + app.start(); + } + + public void initVideo(){ + this.setTimer(new IsoTimer(60)); + /*try{ + // set the timer to 30fps lock-step + this.setTimer(new IsoTimer(30)); + + //ViewPort compositeViewPort = renderManager.createFinalView("composite", cam); + //compositeViewPort.attachScene(this.rootNode); + //compositeViewPort.attachScene(this.guiNode); + this.viewPort.setClearFlags(true, true, true); + this.viewPort.setBackgroundColor(ColorRGBA.Black); + movingRecorder = new AVIVideoRecorder(movingVideo); + this.stateManager.attach(movingRecorder); + this.viewPort.addFinalProcessor(movingRecorder); + this.viewPort.attachScene(this.guiNode); + + }catch (IOException e) { + e.printStackTrace();} + */ + try {Capture.SimpleCaptureVideo(this, movingVideo);} + catch (IOException e) {e.printStackTrace();} + + } + protected Geometry player; + + public void simpleInitApp() { + initVideo(); // begin recording! + /** this blue box is our player character */ + Box b = new Box(Vector3f.ZERO, 1, 1, 1); + player = new Geometry("blue cube", b); + Material mat = new Material(assetManager, + "Common/MatDefs/Misc/Unshaded.j3md"); + mat.setColor("Color", ColorRGBA.Blue); + player.setMaterial(mat); + rootNode.attachChild(player); + } + + /* Use the main event loop to trigger repeating actions. */ + public void simpleUpdate(float tpf) { + // make the player rotate: + player.rotate(0, 2*tpf, 0); + } + +} \ No newline at end of file