add better TestDoppler example
This commit is contained in:
parent
9d094b222a
commit
f5072cba4a
@ -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();
|
||||||
@ -60,45 +57,38 @@ 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);
|
|
||||||
|
|
||||||
ufo = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
|
Torus torus = new Torus(10, 6, 1, 3);
|
||||||
ufo.setPositional(true);
|
Geometry g = new Geometry("Torus Geom", torus);
|
||||||
ufo.setLooping(true);
|
g.rotate(-FastMath.HALF_PI, 0, 0);
|
||||||
ufo.setReverbEnabled(true);
|
g.center();
|
||||||
ufo.setRefDistance(100000000);
|
|
||||||
ufo.setMaxDistance(100000000);
|
g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
|
||||||
ufo.play();
|
// rootNode.attachChild(g);
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
//float x = (float) (Math.cos(angle) * xDist);
|
pos += tpf * vel;
|
||||||
float dx = (float) Math.sin(angle) * xDist;
|
if (pos < -10 || pos > 10) {
|
||||||
|
vel *= -1;
|
||||||
//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;
|
|
||||||
|
|
||||||
if (angle > FastMath.TWO_PI){
|
|
||||||
angle = FastMath.TWO_PI;
|
|
||||||
rate = -rate;
|
|
||||||
}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…
x
Reference in New Issue
Block a user