Hi monkeys!
So, I am following “The Book”, and I’m stuck with the LowPassFilter exercise.
The exercise consists of applying the LowPassFilter to my wavesAudio node when the the camera goes up and down, to change the sound underwater. The code works. If I go underwater, the sound lowers. If i emerge, the sound comes back to normal. However, if I go underwater again, the sound doesn’t change.
So, I debugged the app and I found this when printing my two LowPassFilter’s:
-
When I go underwater and go up the first time, it prints this (the first one is underwaterFilter, the second is aboveWaterFilter):
NativeLowPassFilter -1 NativeLowPassFilter -1
-
When I repeat that, it starts printing this:
NativeLowPassFilter 68 NativeLowPassFilter 69
I think this is a weird bug. My code is exactly the same of the book example.
Source:
-
The part where I change filters
@Override public void simpleUpdate(float tpf) { listener.setLocation(cam.getLocation()); listener.setRotation(cam.getRotation()); if(agua.isUnderWater() && !debaixoDeAgua) { aguaAudio.stop(); debaixoDeAgua = true; aguaAudio.setDryFilter(debaixoDeAguaFiltro); System.out.println(debaixoDeAguaFiltro); aguaAudio.play(); } else if(!agua.isUnderWater() && debaixoDeAgua) { aguaAudio.stop(); debaixoDeAgua = false; aguaAudio.setDryFilter(acimaDeAguaFiltro); System.out.println(acimaDeAguaFiltro); aguaAudio.play(); } }
-
The whole code
package mygame; import com.jme3.app.SimpleApplication; import com.jme3.audio.AudioNode; import com.jme3.audio.Filter; import com.jme3.audio.LowPassFilter; import com.jme3.light.AmbientLight; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.renderer.RenderManager; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.shape.Box; import com.jme3.util.SkyFactory; import com.jme3.water.WaterFilter; public class SonsDebaixoDeAgua extends SimpleApplication { private Node cenaRefletida; private AudioNode aguaAudio; private LowPassFilter debaixoDeAguaFiltro = new LowPassFilter(.5f, .1f); private LowPassFilter acimaDeAguaFiltro = new LowPassFilter(1, 1); private boolean debaixoDeAgua = false; private WaterFilter agua; public static void main(String[] args) { SonsDebaixoDeAgua app = new SonsDebaixoDeAgua(); app.start(); } @Override public void simpleInitApp() { DirectionalLight sol = new DirectionalLight(); //sol.setDirection(new Vector3f(.3f, -.5f, -.5f)); sol.setDirection(new Vector3f(-.39f, -.32f, -.74f)); sol.setColor(ColorRGBA.White); rootNode.addLight(sol); cenaRefletida = new Node("Cena"); rootNode.attachChild(cenaRefletida); cenaRefletida.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); Material caixaMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); caixaMat.setTexture("DiffuseMap", assetManager.loadTexture("Interface/Monkey.png")); Box caixaMesh = new Box(2, 2, 2); Geometry caixaGeo = new Geometry("Caixinha", caixaMesh); caixaGeo.setMaterial(caixaMat); cenaRefletida.attachChild(caixaGeo); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); viewPort.addProcessor(fpp); agua = new WaterFilter(cenaRefletida, sol.getDirection()); fpp.addFilter(agua); AmbientLight ambiente = new AmbientLight(); ambiente.setColor(ColorRGBA.White); rootNode.addLight(ambiente); flyCam.setMoveSpeed(15); aguaAudio = new AudioNode(assetManager, "Sounds/Environment/Ocean Waves.ogg"); aguaAudio.setLooping(true); aguaAudio.setPositional(false); aguaAudio.play(); rootNode.attachChild(aguaAudio); } @Override public void simpleUpdate(float tpf) { listener.setLocation(cam.getLocation()); listener.setRotation(cam.getRotation()); if(agua.isUnderWater() && !debaixoDeAgua) { aguaAudio.stop(); debaixoDeAgua = true; aguaAudio.setDryFilter(debaixoDeAguaFiltro); System.out.println(debaixoDeAguaFiltro); aguaAudio.play(); } else if(!agua.isUnderWater() && debaixoDeAgua) { aguaAudio.stop(); debaixoDeAgua = false; aguaAudio.setDryFilter(acimaDeAguaFiltro); System.out.println(acimaDeAguaFiltro); aguaAudio.play(); } } @Override public void simpleRender(RenderManager rm) { //TODO: add render code } }
Btw @nehon, when I paste my code, I need to ident my code 8 spaces, instead of the supposed 4 spaces. I try to use the </> key on the editor, but it doesn’t work. Am I doing anything wrong?
Thanks,
Ev1lbl0w