Skip to content

Commit f5072cb

Browse files
committed
add better TestDoppler example
1 parent 9d094b2 commit f5072cb

1 file changed

Lines changed: 37 additions & 47 deletions

File tree

jme3-examples/src/main/java/jme3test/audio/TestDoppler.java

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,72 +33,62 @@
3333
package jme3test.audio;
3434

3535
import com.jme3.app.SimpleApplication;
36+
import com.jme3.audio.AudioData;
3637
import com.jme3.audio.AudioNode;
37-
import com.jme3.audio.Environment;
3838
import com.jme3.math.FastMath;
3939
import com.jme3.math.Vector3f;
40-
import org.lwjgl.openal.AL10;
41-
import org.lwjgl.openal.AL11;
40+
import com.jme3.scene.Geometry;
41+
import com.jme3.scene.shape.Sphere;
42+
import com.jme3.scene.shape.Torus;
4243

4344
/**
4445
* Test Doppler Effect
4546
*/
4647
public class TestDoppler extends SimpleApplication {
4748

48-
private AudioNode ufo;
49+
private float pos = -5;
50+
private float vel = 5;
51+
private AudioNode ufoNode;
4952

50-
private float x = 20, z = 0;
51-
private float rate = -0.05f;
52-
private float xDist = 20;
53-
private float zDist = 5;
54-
private float angle = FastMath.TWO_PI;
55-
5653
public static void main(String[] args){
5754
TestDoppler test = new TestDoppler();
5855
test.start();
5956
}
6057

6158
@Override
62-
public void simpleInitApp(){
63-
audioRenderer.setEnvironment(Environment.Dungeon);
64-
AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
65-
66-
ufo = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
67-
ufo.setPositional(true);
68-
ufo.setLooping(true);
69-
ufo.setReverbEnabled(true);
70-
ufo.setRefDistance(100000000);
71-
ufo.setMaxDistance(100000000);
72-
ufo.play();
59+
public void simpleInitApp() {
60+
flyCam.setMoveSpeed(10);
61+
62+
Torus torus = new Torus(10, 6, 1, 3);
63+
Geometry g = new Geometry("Torus Geom", torus);
64+
g.rotate(-FastMath.HALF_PI, 0, 0);
65+
g.center();
66+
67+
g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
68+
// rootNode.attachChild(g);
69+
70+
ufoNode = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", AudioData.DataType.Buffer);
71+
ufoNode.setLooping(true);
72+
ufoNode.setPitch(0.5f);
73+
ufoNode.setRefDistance(1);
74+
ufoNode.setMaxDistance(100000000);
75+
ufoNode.setVelocityFromTranslation(true);
76+
ufoNode.play();
77+
78+
Geometry ball = new Geometry("Beeper", new Sphere(10, 10, 0.1f));
79+
ball.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
80+
ufoNode.attachChild(ball);
81+
82+
rootNode.attachChild(ufoNode);
7383
}
7484

85+
7586
@Override
76-
public void simpleUpdate(float tpf){
77-
//float x = (float) (Math.cos(angle) * xDist);
78-
float dx = (float) Math.sin(angle) * xDist;
79-
80-
//float z = (float) (Math.sin(angle) * zDist);
81-
float dz = (float)(-Math.cos(angle) * zDist);
82-
83-
x += dx * tpf * 0.05f;
84-
z += dz * tpf * 0.05f;
85-
86-
angle += tpf * rate;
87-
88-
if (angle > FastMath.TWO_PI){
89-
angle = FastMath.TWO_PI;
90-
rate = -rate;
91-
}else if (angle < -0){
92-
angle = -0;
93-
rate = -rate;
87+
public void simpleUpdate(float tpf) {
88+
pos += tpf * vel;
89+
if (pos < -10 || pos > 10) {
90+
vel *= -1;
9491
}
95-
96-
ufo.setVelocity(new Vector3f(dx, 0, dz));
97-
ufo.setLocalTranslation(x, 0, z);
98-
ufo.updateGeometricState();
99-
100-
System.out.println("LOC: " + (int)x +", " + (int)z +
101-
", VEL: " + (int)dx + ", " + (int)dz);
92+
ufoNode.setLocalTranslation(new Vector3f(pos, 0, 0));
10293
}
103-
10494
}

0 commit comments

Comments
 (0)