List of usage examples for javax.media.j3d PointSound setSchedulingBounds
public void setSchedulingBounds(Bounds region)
From source file:SimpleSounds.java
/** * Add a sound to the transform group. This takes a point sound object and * loads into it a sounds from a given file. The edge of the sound's extent * is also defined in a parameter.//from w ww . ja v a 2 s . c om * * @param tg * TransformGroup that the sound is to be added to * @param sound * PointSound to be used * @param soundFile * String that is the name of the sound file to be loaded * @param edge * float that represents the sound's maximum extent */ protected void addObjectSound(TransformGroup tg, PointSound sound, String soundFile, float edge) { //First we get the current transform so that we can //position the sound in the same place Transform3D objXfm = new Transform3D(); Vector3f objPosition = new Vector3f(); tg.getTransform(objXfm); objXfm.get(objPosition); //Create the media container to load the sound MediaContainer soundContainer = new MediaContainer(soundFile); //Use the loaded data in the sound sound.setSoundData(soundContainer); sound.setInitialGain(1.0f); //Set the position to that of the given transform sound.setPosition(new Point3f(objPosition)); //Allow use to switch the sound on and off sound.setCapability(PointSound.ALLOW_ENABLE_READ); sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); sound.setSchedulingBounds(bounds); //Set it off to start with sound.setEnable(false); //Set it to loop forever sound.setLoop(BackgroundSound.INFINITE_LOOPS); //Use the edge value to set to extent of the sound Point2f[] attenuation = { new Point2f(0.0f, 1.0f), new Point2f(edge, 0.1f) }; sound.setDistanceGain(attenuation); //Add the sound to the transform group tg.addChild(sound); }