import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.j3d.audioengines.javasound.JavaSoundMixer;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
public class Test_Class extends JFrame
{
private SimpleUniverse universe ;
private Canvas3D canvas;
private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0);
public void setupView()
{
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
MediaContainer myWave = null;
try {
myWave = new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/Sounds/MainSound.wav"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
Point2f[] myAtten = {
new Point2f( 100.0f, 1.0f ),
new Point2f( 350.0f, 0.5f ),
new Point2f( 600.0f, 0.0f )
};
PointSound mySound = new PointSound( );
mySound.setSoundData( myWave );
mySound.setEnable( true );
mySound.setInitialGain( 1.0f );
mySound.setLoop(-1);
mySound.setPosition( new Point3f( 0.0f, 0.0f, 0.0f ) );
mySound.setDistanceGain( myAtten );
BoundingSphere myBounds = new BoundingSphere(
new Point3d(), 1.0 );
mySound.setSchedulingBounds( myBounds );
objRoot.addChild(mySound);
Color3f lightColor = new Color3f(.6f,.6f,.6f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public Test_Class()
{
setVisible(true);
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
PhysicalEnvironment environment = universe.getViewer().getPhysicalEnvironment();
AudioDevice device = new JavaSoundMixer(environment);
device.initialize();
environment.setAudioDevice(device);
}
public static void main(String[] args) {new Test_Class();}
}