|
Replies:
0
|
|
|
|
|
|
|
Hello / Newby Javax.media.j3d question
Posted:
May 13, 2008 5:41 AM
|
|
|
Hello All, -Very glad I found this list!
I have what probably will amount to two very newby questions re: javax.media.j3d so please do excuse me if you would. 
First off, just a quick bit about me; I'm a visually impaired (blind) code hobbyist, among other things, and am interested in using j3d to develop 3d audio environments on the Macintosh. I've had experience with DirectX in C# on windows, as well as coding in C / C++ and QC for the creation of mods for Audio Quake, which is a project to demo a proof of concept of the accessibility of virtual 3d environments for the visually impaired.
Anyway, re: this particular note / code snippet; my questions are these…
• I'm trying to set up aural attributes and they just won't seem to work, no matter what I try. Ick! I'd like to at the minimum, have the sound attenuated with distance from the viewer, as well as have doppler effect applied while sounds are moving.
• In my below code, I have the viewer rotating on the Y axis at roughly 1 degree every iteration of a 100 FPS loop. -or so I should, at least. The sound that plays is positioned off to the left and slightly ahead of, and above the listener / viewer, however, rather than a nice smooth panning / rotational effect of the sound moving 'around' the listener's head, it seems to jump back and forth from side to side, and completely destroy any sense of rotational idea.
What in the world am I doing wrong? 
So, let me apologize in advance for the state of the below code. This not only is a lovely lil Frankensteinian work in progress, but is also simply a very raw test to figure out some basic coding to demo / test a few concepts so I can see if this package is something I might think about using. I'd *really* like to work with j3d as I do like it's paradigm so any help / suggestions any of you might be able to send along my way would sure be appreciated! 
Have a lovely day and happy coding!…
Smiles,
Cara 
// Begin code
import java.net.URL; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.universe.*; import java.io.File; import javax.media.j3d.*; import javax.vecmath.*;
public class SoundTestX extends Frame{
// set up variables
Canvas3D canvas = new Canvas3D( SimpleUniverse.getPreferredConfiguration());
SimpleUniverse universe = new SimpleUniverse(canvas);
// BranchGroup viewParent = universe.getViewingPlatform();
TransformGroup viewTrans = universe.getViewingPlatform().getViewPlatformTransform();
BranchGroup branchGroup = new BranchGroup(); TransformGroup objTrans = new TransformGroup();
public SoundTestX(){//constructor // set up frame
setLayout(new BorderLayout()); add(BorderLayout.CENTER,canvas);
// adjust user's position - just testing
universe.getViewingPlatform().setNominalViewingTransform(); universe .getViewingPlatform().getViewPlatform().setActivationRadius(1000.0F);
// detach the view platform branch group so it's not live, to edit nodes
universe.getViewingPlatform().detach();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); viewTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
AudioDevice audioDev = universe.getViewer().createAudioDevice();
// start experimental aural attributes code
/* Point2f[] distanceFilter = new Point2f[2]; distanceFilter[0] = new Point2f(6.0f, 6000f); distanceFilter[1] = new Point2f(17.0f, 700f); AuralAttributes attributes = new AuralAttributes(1.0f, 2.0f, 0.3f, 4.0f, 5, distanceFilter, 0.8f, 0.0f); distanceFilter = new Point2f[2]; distanceFilter[0] = new Point2f(2.0f, 20000.0f); distanceFilter[1] = new Point2f(20.0f, 2000.0f); distanceFilter[0] = new Point2f(5.0f, 15000.0f); distanceFilter[1] = new Point2f(15.0f, 500.0f); attributes2.setDistanceFilter(distanceFilter); BoundingSphere bounds2 = new BoundingSphere(new Point3d(-2.0,0.0,0.0), 0.38); // set BoundingLeaf as a child of transform node */
// AuralAttributes myAural = new AuralAttributes( ); Point2f[] distanceFilter = new Point2f[2]; distanceFilter[0] = new Point2f(6.0f, 6000f); distanceFilter[1] = new Point2f(17.0f, 700f); AuralAttributes myAural = new AuralAttributes(1.0f, 2.0f, 0.3f, 4.0f, 5, distanceFilter, 0.8f, 0.0f); // myAural.setAttributeGain(1.2f); // myAural.setRolloff(2.2f); myAural.setReverbDelay(1313.0f) ; myAural.setReflectionCoefficient(1.0f) ; myAural.setReverbOrder(15) ; myAural.setFrequencyScaleFactor(6.0f); myAural.setVelocityScaleFactor(6.0f); Soundscape myScape = new Soundscape(); myScape.setAuralAttributes( myAural ); BoundingSphere myBounds = new BoundingSphere( new Point3d(0.0, 0.0, 0.0), 1000.0); BoundingLeaf sScapeBounds2 = new BoundingLeaf(myBounds); myScape.setApplicationBoundingLeaf(sScapeBounds2); myScape.setApplicationBounds( myBounds ); viewTrans.addChild(sScapeBounds2); viewTrans.addChild(myScape);
// end aural attributes code
//Set the Frame size and title and make it all visible. setSize(475,475); setTitle("Sound Test"); setVisible(true);
//This listener is used to terminate the program when // the user clicks the X in the upper-right corner of // the Frame. addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }//end windowClosing }//end new WindowAdapter );//end addWindowListener }//end constructor
public static void main(String[] args) throws Exception { // set up objects for this test // these will later be in their own class
MediaContainer sample = new MediaContainer("file:./chopper.wav");
PointSound sound = new PointSound();
Transform3D trans3 = new Transform3D(); Transform3D viewerTrans3 = new Transform3D();
SoundTestX thisObj = new SoundTestX();
// start experimental sound code
// Create a sound node and add it to the scene graph before it goes live
sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); sound.setSoundData(sample); sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); sound.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); sound.setCapability(PointSound.ALLOW_RELEASE_WRITE); sound.setCapability(PointSound.ALLOW_DURATION_READ); sound.setCapability(PointSound.ALLOW_IS_PLAYING_READ); sound.setCapability(PointSound.ALLOW_POSITION_WRITE); sound.setCapability(PointSound.ALLOW_POSITION_READ); sound.setCapability(PointSound.ALLOW_LOOP_WRITE); sound.setCapability(PointSound.ALLOW_RATE_SCALE_FACTOR_WRITE); sound.setCapability(PointSound.ALLOW_RATE_SCALE_FACTOR_READ);
BoundingSphere soundBounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 200.0); sound.setSchedulingBounds(soundBounds); sound.setLoop(BackgroundSound.INFINITE_LOOPS); sound.setInitialGain(1.0f);
thisObj.objTrans.addChild(sound); thisObj.branchGroup.addChild(thisObj.objTrans); thisObj.universe.addBranchGraph(thisObj.branchGroup); thisObj.universe.addBranchGraph(thisObj.universe.getViewingPlatform());
// end experimental sound code
// start sound playing after it's been added and the scene graph is live
sound.setEnable(true);
// set up variables for the view platform rotation test
// from previous test
// boolean direction = true; float xVal = 0.0F;
// Point3f soundPos = new Point3f(30.0F, 20.0F, -20.0F); // sound.setPosition(soundPos);
// set the position for the sound's transform
Vector3f vector = new Vector3f(-100.0f, 2.0f, -2.0f); trans3.setTranslation(vector); thisObj.objTrans.setTransform(trans3);
// begin rotation test for view platform transform
while(true) {
long frameTime = (System.currentTimeMillis() + 10); // sets a ten millisecond frame for a frame rate of 100
viewerTrans3.rotY(xVal); thisObj.viewTrans.setTransform(viewerTrans3);
// increase xVal (change that name!) lol! by approx 1 degree in radians
xVal+= 0.017f;
// Ignore this code // carry-over from earlier test
/* if(direction) { xVal++; if(xVal > 199) direction = false; } else { xVal--; if(xVal < -199) direction = true; } */
|
|
|
|