add better TestDoppler example

cleanup_build_scripts
Kirill Vainer 9 years ago
parent 9d094b222a
commit f5072cba4a
  1. 84
      jme3-examples/src/main/java/jme3test/audio/TestDoppler.java

@ -33,25 +33,22 @@
package jme3test.audio; package jme3test.audio;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode; import com.jme3.audio.AudioNode;
import com.jme3.audio.Environment;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import org.lwjgl.openal.AL10; import com.jme3.scene.Geometry;
import org.lwjgl.openal.AL11; import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Torus;
/** /**
* Test Doppler Effect * Test Doppler Effect
*/ */
public class TestDoppler extends SimpleApplication { public class TestDoppler extends SimpleApplication {
private AudioNode ufo; private float pos = -5;
private float vel = 5;
private float x = 20, z = 0; private AudioNode ufoNode;
private float rate = -0.05f;
private float xDist = 20;
private float zDist = 5;
private float angle = FastMath.TWO_PI;
public static void main(String[] args){ public static void main(String[] args){
TestDoppler test = new TestDoppler(); TestDoppler test = new TestDoppler();
@ -59,46 +56,39 @@ public class TestDoppler extends SimpleApplication {
} }
@Override @Override
public void simpleInitApp(){ public void simpleInitApp() {
audioRenderer.setEnvironment(Environment.Dungeon); flyCam.setMoveSpeed(10);
AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
Torus torus = new Torus(10, 6, 1, 3);
ufo = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false); Geometry g = new Geometry("Torus Geom", torus);
ufo.setPositional(true); g.rotate(-FastMath.HALF_PI, 0, 0);
ufo.setLooping(true); g.center();
ufo.setReverbEnabled(true);
ufo.setRefDistance(100000000); g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
ufo.setMaxDistance(100000000); // rootNode.attachChild(g);
ufo.play();
ufoNode = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", AudioData.DataType.Buffer);
ufoNode.setLooping(true);
ufoNode.setPitch(0.5f);
ufoNode.setRefDistance(1);
ufoNode.setMaxDistance(100000000);
ufoNode.setVelocityFromTranslation(true);
ufoNode.play();
Geometry ball = new Geometry("Beeper", new Sphere(10, 10, 0.1f));
ball.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
ufoNode.attachChild(ball);
rootNode.attachChild(ufoNode);
} }
@Override
public void simpleUpdate(float tpf){
//float x = (float) (Math.cos(angle) * xDist);
float dx = (float) Math.sin(angle) * xDist;
//float z = (float) (Math.sin(angle) * zDist);
float dz = (float)(-Math.cos(angle) * zDist);
x += dx * tpf * 0.05f;
z += dz * tpf * 0.05f;
angle += tpf * rate; @Override
public void simpleUpdate(float tpf) {
if (angle > FastMath.TWO_PI){ pos += tpf * vel;
angle = FastMath.TWO_PI; if (pos < -10 || pos > 10) {
rate = -rate; vel *= -1;
}else if (angle < -0){
angle = -0;
rate = -rate;
} }
ufoNode.setLocalTranslation(new Vector3f(pos, 0, 0));
ufo.setVelocity(new Vector3f(dx, 0, dz));
ufo.setLocalTranslation(x, 0, z);
ufo.updateGeometricState();
System.out.println("LOC: " + (int)x +", " + (int)z +
", VEL: " + (int)dx + ", " + (int)dz);
} }
} }

Loading…
Cancel
Save