|
1 | 1 | /* |
2 | | - * Copyright (c) 2009-2021 jMonkeyEngine |
| 2 | + * Copyright (c) 2009-2025 jMonkeyEngine |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
|
39 | 39 | import com.jme3.math.ColorRGBA; |
40 | 40 | import com.jme3.math.Vector3f; |
41 | 41 | import com.jme3.scene.Geometry; |
42 | | -import com.jme3.scene.shape.Box; |
| 42 | +import com.jme3.scene.Mesh; |
| 43 | +import com.jme3.scene.debug.Grid; |
| 44 | +import com.jme3.scene.shape.Sphere; |
43 | 45 |
|
44 | 46 | public class TestAmbient extends SimpleApplication { |
45 | 47 |
|
46 | | - public static void main(String[] args) { |
47 | | - TestAmbient test = new TestAmbient(); |
48 | | - test.start(); |
49 | | - } |
| 48 | + public static void main(String[] args) { |
| 49 | + TestAmbient test = new TestAmbient(); |
| 50 | + test.start(); |
| 51 | + } |
50 | 52 |
|
51 | | - @Override |
52 | | - public void simpleInitApp() { |
53 | | - float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0, |
54 | | - 1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, |
55 | | - 0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, |
56 | | - 0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f}; |
57 | | - Environment env = new Environment(eax); |
58 | | - audioRenderer.setEnvironment(env); |
| 53 | + private final float[] eax = { |
| 54 | + 15, 38.0f, 0.300f, -1000, -3300, 0, |
| 55 | + 1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, |
| 56 | + 0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, |
| 57 | + 0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f |
| 58 | + }; |
59 | 59 |
|
60 | | - AudioNode waves = new AudioNode(assetManager, |
61 | | - "Sound/Environment/Ocean Waves.ogg", DataType.Buffer); |
62 | | - waves.setPositional(true); |
63 | | - waves.setLocalTranslation(new Vector3f(0, 0,0)); |
64 | | - waves.setMaxDistance(100); |
65 | | - waves.setRefDistance(5); |
| 60 | + @Override |
| 61 | + public void simpleInitApp() { |
| 62 | + configureCamera(); |
66 | 63 |
|
67 | | - AudioNode nature = new AudioNode(assetManager, |
68 | | - "Sound/Environment/Nature.ogg", DataType.Stream); |
69 | | - nature.setPositional(false); |
70 | | - nature.setVolume(3); |
71 | | - |
72 | | - waves.playInstance(); |
73 | | - nature.play(); |
74 | | - |
75 | | - // just a blue box to mark the spot |
76 | | - Box box1 = new Box(.5f, .5f, .5f); |
77 | | - Geometry player = new Geometry("Player", box1); |
78 | | - Material mat1 = new Material(assetManager, |
79 | | - "Common/MatDefs/Misc/Unshaded.j3md"); |
80 | | - mat1.setColor("Color", ColorRGBA.Blue); |
81 | | - player.setMaterial(mat1); |
82 | | - rootNode.attachChild(player); |
83 | | - } |
| 64 | + Environment env = new Environment(eax); |
| 65 | + audioRenderer.setEnvironment(env); |
84 | 66 |
|
85 | | - @Override |
86 | | - public void simpleUpdate(float tpf) { |
87 | | - } |
| 67 | + AudioNode waves = new AudioNode(assetManager, |
| 68 | + "Sound/Environment/Ocean Waves.ogg", DataType.Buffer); |
| 69 | + waves.setPositional(true); |
| 70 | + waves.setLooping(true); |
| 71 | + waves.setReverbEnabled(true); |
| 72 | + rootNode.attachChild(waves); |
| 73 | + |
| 74 | + AudioNode nature = new AudioNode(assetManager, |
| 75 | + "Sound/Environment/Nature.ogg", DataType.Stream); |
| 76 | + nature.setPositional(false); |
| 77 | + nature.setLooping(true); |
| 78 | + nature.setVolume(3); |
| 79 | + rootNode.attachChild(nature); |
| 80 | + |
| 81 | + waves.play(); |
| 82 | + nature.play(); |
| 83 | + |
| 84 | + // just a blue sphere to mark the spot |
| 85 | + Geometry marker = makeShape("Marker", new Sphere(16, 16, 1f), ColorRGBA.Blue); |
| 86 | + waves.attachChild(marker); |
| 87 | + |
| 88 | + Geometry grid = makeShape("DebugGrid", new Grid(21, 21, 2), ColorRGBA.Gray); |
| 89 | + grid.center().move(0, 0, 0); |
| 90 | + rootNode.attachChild(grid); |
| 91 | + } |
| 92 | + |
| 93 | + private void configureCamera() { |
| 94 | + flyCam.setMoveSpeed(25f); |
| 95 | + flyCam.setDragToRotate(true); |
| 96 | + |
| 97 | + cam.setLocation(Vector3f.UNIT_XYZ.mult(5f)); |
| 98 | + cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); |
| 99 | + } |
| 100 | + |
| 101 | + private Geometry makeShape(String name, Mesh mesh, ColorRGBA color) { |
| 102 | + Geometry geo = new Geometry(name, mesh); |
| 103 | + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
| 104 | + mat.setColor("Color", color); |
| 105 | + geo.setMaterial(mat); |
| 106 | + return geo; |
| 107 | + } |
88 | 108 | } |
0 commit comments