|
33 | 33 | package jme3test.audio; |
34 | 34 |
|
35 | 35 | import com.jme3.app.SimpleApplication; |
| 36 | +import com.jme3.audio.AudioData; |
36 | 37 | import com.jme3.audio.AudioNode; |
37 | | -import com.jme3.audio.Environment; |
38 | 38 | import com.jme3.math.FastMath; |
39 | 39 | 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; |
42 | 43 |
|
43 | 44 | /** |
44 | 45 | * Test Doppler Effect |
45 | 46 | */ |
46 | 47 | public class TestDoppler extends SimpleApplication { |
47 | 48 |
|
48 | | - private AudioNode ufo; |
| 49 | + private float pos = -5; |
| 50 | + private float vel = 5; |
| 51 | + private AudioNode ufoNode; |
49 | 52 |
|
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 | | - |
56 | 53 | public static void main(String[] args){ |
57 | 54 | TestDoppler test = new TestDoppler(); |
58 | 55 | test.start(); |
59 | 56 | } |
60 | 57 |
|
61 | 58 | @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); |
73 | 83 | } |
74 | 84 |
|
| 85 | + |
75 | 86 | @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; |
94 | 91 | } |
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)); |
102 | 93 | } |
103 | | - |
104 | 94 | } |
0 commit comments