+ All Categories
Home > Documents > Java 3D API, Sound

Java 3D API, Sound

Date post: 07-Jan-2016
Category:
Upload: benard
View: 63 times
Download: 0 times
Share this document with a friend
Description:
Java 3D API, Sound. James Atlas July 31, 2008. Review. J2EE. Today. Java 3D Java Media Framework (Sound). What is Java 3D?. Java 3D is: Standard extension to the Java 2 JDK An interface for writing programs to display and interact with 3D graphics - PowerPoint PPT Presentation
44
Java 3D API, Sound Java 3D API, Sound James Atlas James Atlas July 31, 2008 July 31, 2008
Transcript
Page 1: Java 3D API, Sound

Java 3D API, SoundJava 3D API, Sound

James AtlasJames Atlas

July 31, 2008July 31, 2008

Page 2: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 22

ReviewReview

• J2EEJ2EE

Page 3: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 33

TodayToday

• Java 3DJava 3D

• Java Media Framework (Sound)Java Media Framework (Sound)

Page 4: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 44

What is Java 3D?What is Java 3D?

• Java 3D is:Java 3D is:Standard extension to the Java 2 JDKStandard extension to the Java 2 JDKAn interface for writing programs to display and An interface for writing programs to display and

interact with 3D graphicsinteract with 3D graphicsProvides a collection of high-level constructs for Provides a collection of high-level constructs for

creating and manipulating 3D geometry and creating and manipulating 3D geometry and structures for rendering that geometrystructures for rendering that geometry

It is now a community source project developed It is now a community source project developed on java.net (on java.net (https://java3d.dev.java.net/https://java3d.dev.java.net/))

Page 5: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 55

What can Java 3D do?What can Java 3D do?• Java 3D includes a rich and extensible feature set Java 3D includes a rich and extensible feature set

forfor Building shapesBuilding shapes Composing behaviorsComposing behaviors Interacting with the environment and the userInteracting with the environment and the user Controlling rendering detailsControlling rendering details

• Java 3D enables:Java 3D enables: Quick development of complex 3D applicationsQuick development of complex 3D applications Fast and efficient implementation on a variety of Fast and efficient implementation on a variety of

platforms, from embedded systems to PCs to high-end platforms, from embedded systems to PCs to high-end workstationsworkstations

Page 6: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 66

Advantages and Advantages and DisadvantagesDisadvantages• AdvantagesAdvantages

It enables fast Development, so developers do It enables fast Development, so developers do not need to manipulate rendering details, they not need to manipulate rendering details, they can focus on visual contentscan focus on visual contents

Cross-platformCross-platform

• DisadvantagesDisadvantages It has lower speed than C++/OpenGLIt has lower speed than C++/OpenGL

Page 7: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 77

Online Java 3D ResourcesOnline Java 3D Resources

• Homepage of Java 3DHomepage of Java 3D https://java3d.dev.java.net/https://java3d.dev.java.net/

• Java 3D API Documentation, Examples and DownloadsJava 3D API Documentation, Examples and Downloads https://java3d.dev.java.net/binary-builds.htmlhttps://java3d.dev.java.net/binary-builds.html

• Java 3D Tutorial (Chapter 0-7, highly recommended)Java 3D Tutorial (Chapter 0-7, highly recommended) http://java.sun.com/developer/http://java.sun.com/developer/onlineTrainingonlineTraining/java3d/index.html/java3d/index.html

• Java 3D interest group mail archive (searchable):Java 3D interest group mail archive (searchable): http://archives.java.sun.com/archives/java3d-interest.htmlhttp://archives.java.sun.com/archives/java3d-interest.html

• The Java 3D Community SiteThe Java 3D Community Site http://www.j3d.org/http://www.j3d.org/

Page 8: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 88

Java3D API useful packagesJava3D API useful packages

• Core classesCore classes javax.media.j3djavax.media.j3d package, it includes the lowest-level classes package, it includes the lowest-level classes

necessary in Java 3D programmingnecessary in Java 3D programming

• Utility classesUtility classes com.sun.j3d.utilscom.sun.j3d.utils package, it is convenient and powerful additions package, it is convenient and powerful additions

to the coreto the core It has 4 major categories: content loaders, scene graph It has 4 major categories: content loaders, scene graph

construction aids, geometry classes, and convenience utilitiesconstruction aids, geometry classes, and convenience utilities

• Abstract Windowing Toolkit (AWT)Abstract Windowing Toolkit (AWT) java.awt java.awt package, it creates a window to display the renderingpackage, it creates a window to display the rendering

• Vector math classesVector math classes javax.vecmathjavax.vecmath package, it defines vector math classes for points, package, it defines vector math classes for points,

vectors, matrices, and other mathematical objectsvectors, matrices, and other mathematical objects

Page 9: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 99

Virtual Universe and Scene Virtual Universe and Scene GraphGraph• A Java 3D program describes a A Java 3D program describes a virtual virtual

universeuniverse,, which is to be renderedwhich is to be rendered

• A virtual universe is created from a A virtual universe is created from a scene scene graphgraph

• The scene graph is assembled from objects The scene graph is assembled from objects to define the geometry, sound, lights, to define the geometry, sound, lights, location, orientation, and appearance of location, orientation, and appearance of visual and audio objectsvisual and audio objects

Page 10: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1010

How to Build a Scene GraphHow to Build a Scene Graph

• A scene graph is composed of A scene graph is composed of nodesnodes and and arcsarcs. A node is a data element, and arc is a . A node is a data element, and arc is a relationship between data elementsrelationship between data elements

• The nodes in the scene graph are the The nodes in the scene graph are the instances of Java 3D classes. The arcs instances of Java 3D classes. The arcs represent the two kinds of relationship represent the two kinds of relationship between the Java 3D instancesbetween the Java 3D instances

Page 11: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1111

Two relationshipsTwo relationships• Parent-child relationshipParent-child relationship

A parent node can have any number of children but only A parent node can have any number of children but only one parentone parent

A child node can have one parent and no childrenA child node can have one parent and no children

• Reference relationshipReference relationship A reference associates a A reference associates a NodeComponentNodeComponent object with a object with a

scene graph Node. NodeComponent objects define the scene graph Node. NodeComponent objects define the Geometry, Appearance, Material Geometry, Appearance, Material andand Texture Texture attributes used to render the visual objectsattributes used to render the visual objects

For a single node, it can have many referencesFor a single node, it can have many references

Page 12: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1212

A Scene Graph ExampleA Scene Graph Example

Page 13: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1313

ConceptsConcepts• Each Each scene graphscene graph has a single has a single Virtual UniverseVirtual Universe• The Virtual Universe object has a The Virtual Universe object has a Locale Locale object object

(landmark used to determine the location of visual (landmark used to determine the location of visual objects). It is the root of multiple sub-graphsobjects). It is the root of multiple sub-graphs

• A A BranchGroupBranchGroup object is the root of a sub-graph object is the root of a sub-graph (branch graph)(branch graph)

• Two kinds of sub-graphTwo kinds of sub-graph view branch graphview branch graph

• viewing parameters (viewing location and direction)viewing parameters (viewing location and direction) content branch graphcontent branch graph

• Geometry, Appearance, Material, TextureGeometry, Appearance, Material, Texture, …, …

Page 14: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1414

SceneGraphObject classSceneGraphObject class

• SceneGraphObjectSceneGraphObject is the superclass for is the superclass for nearly every Core and Utility Java 3D nearly every Core and Utility Java 3D class. It has two subclasses:class. It has two subclasses: Node Node

• GroupGroup BranchGroup, TransformGroupBranchGroup, TransformGroup

• LeafLeaf Shape3DShape3D, , LightLight, , BehaviorBehavior, and , and Sound Sound

(have no (have no children but may reference children but may reference NodeComponents)NodeComponents)

NodeComponentNodeComponent

• Geometry, Appearance, Material, Texture, Geometry, Appearance, Material, Texture, … … ((may be referenced by A Leaf)may be referenced by A Leaf)

Page 15: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1515

Some Key ClassesSome Key Classes

• NodeNode and and NodeComponentNodeComponent superclasses for all the items that are added to a scene graphsuperclasses for all the items that are added to a scene graph

• BranchGroupBranchGroup A Container for other objects in the sceneA Container for other objects in the scene Every item in the scene graph is either a BranchGroup, or is a child of a Every item in the scene graph is either a BranchGroup, or is a child of a

BranchGroupBranchGroup A BrachGroup can be a child of another BranchGroupA BrachGroup can be a child of another BranchGroup

• Shape3DShape3D Contains information about an object in the sceneContains information about an object in the scene Contains references to Contains references to Geometry, Appearance, Material, Texture, …Geometry, Appearance, Material, Texture, …

• AppearanceAppearance Defines the way a shape appears in the scene, including texture, and attributes for Defines the way a shape appears in the scene, including texture, and attributes for

many other settingsmany other settings• TransformGroupTransformGroup

Allows translations, scales and rotations to be preformedAllows translations, scales and rotations to be preformed• GeometryGeometry

Superclass for all classes that allow you to add form to a shapeSuperclass for all classes that allow you to add form to a shape Subclasses: Subclasses: LineArray, TriangleArray, .... LineArray, TriangleArray, ....

Page 16: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1616

ShapeShape

• A Shape is composed of Geometry and A Shape is composed of Geometry and Appearance:Appearance:

Shape

Geometry Appearance

Page 17: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1717

GeometryGeometry

• There are several primitive Geometry There are several primitive Geometry classes available:classes available: BoxBox CylinderCylinder ConeCone SphereSphere Text2DText2D

Page 18: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1818

AppearanceAppearance

• ColorColor

• TextureTexture

• MaterialMaterial

• Other attributes (point, polygon, rendering, Other attributes (point, polygon, rendering, etc)etc)

Page 19: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 1919

A Recipe for Writing Java 3D A Recipe for Writing Java 3D ProgramsPrograms

• 1. Create a 1. Create a Canvas3DCanvas3D object object• 2. Create a 2. Create a VirtualUniverseVirtualUniverse object object• 3. Create a 3. Create a LocaleLocale object, attaching it to the object, attaching it to the

VirtualUniverse objectVirtualUniverse object• 4. Construct a view branch graph4. Construct a view branch graph

a. Create a a. Create a ViewView object object b. Create a b. Create a ViewPlatformViewPlatform object object c. Create a c. Create a PhysicalBodyPhysicalBody object object d. Create a d. Create a PhysicalEnvironmentPhysicalEnvironment object object e. Attach e. Attach ViewPlatformViewPlatform, , PhysicalBodyPhysicalBody, , PhysicalEnvironmentPhysicalEnvironment, ,

and and Canvas3DCanvas3D objects to View object objects to View object

• 5. Construct content branch graph(s)5. Construct content branch graph(s)• 6. Compile branch graph(s)6. Compile branch graph(s)• 7. Insert subgraphs into the Locale7. Insert subgraphs into the Locale

Page 20: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2020

The Simplest Recipe for Writing The Simplest Recipe for Writing Java 3D ProgramsJava 3D Programs• 1. Create a 1. Create a SimpleUniverseSimpleUniverse object object • 2. Construct content branch2. Construct content branch• 3. Insert content branch into the SimpleUniverse3. Insert content branch into the SimpleUniverse• 4. Optionally set nominal transformation (a 4. Optionally set nominal transformation (a

normalization transform so you can see the whole normalization transform so you can see the whole scene)scene)

• Example Hello3dExample Hello3d

Page 21: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2121

The SimpleUniverse ClassThe SimpleUniverse Class• The The SimpleUniverseSimpleUniverse object constructor creates a object constructor creates a

scene graph including scene graph including VirtualUniverseVirtualUniverse and and Locale Locale objects, and a complete view branch graphobjects, and a complete view branch graph

• The view branch graph created by SimpleUniverse The view branch graph created by SimpleUniverse uses instances of uses instances of ViewingPlatformViewingPlatform and and ViewerViewer convenience classes in place of the core classes convenience classes in place of the core classes used to create the view branch graphused to create the view branch graph

• It significantly reduces the time and effort needed to It significantly reduces the time and effort needed to create the view branch graphcreate the view branch graph

Page 22: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2222

Other FeaturesOther Features

• AppearanceAppearance

• Defining your own shapesDefining your own shapes

• TransformationsTransformations

• LightingLighting

• TexturesTextures

• AnimationAnimation

• InteractionInteraction

Page 23: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2323

AppearanceAppearanceColor3f ambient = new Color3f(0.5f, 0.5f, 0.5f);Color3f ambient = new Color3f(0.5f, 0.5f, 0.5f);

Color3f emissive = new Color3f(0.0f, 0.0f, 0.5f);Color3f emissive = new Color3f(0.0f, 0.0f, 0.5f);

Color3f diffuse = new Color3f(0.0f, 0.0f, 1.0f);Color3f diffuse = new Color3f(0.0f, 0.0f, 1.0f);

Color3f specular = new Color3f(1.0f, 1.0f, 1.0f);Color3f specular = new Color3f(1.0f, 1.0f, 1.0f);

float shininess = 20.0f;float shininess = 20.0f;

Appearance shinyBlueApp = new Appearance();Appearance shinyBlueApp = new Appearance();

Material shinyBlueMat = new Material(ambient, emissive, Material shinyBlueMat = new Material(ambient, emissive, diffuse, specular, shininess);diffuse, specular, shininess);

shinyBlueApp.setMaterial(shinyBlueMat);shinyBlueApp.setMaterial(shinyBlueMat);

bg.addChild(new Cylinder(0.5f, 4.0f, shinyBlueApp));bg.addChild(new Cylinder(0.5f, 4.0f, shinyBlueApp));

Page 24: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2424

Define your own shape typesDefine your own shape types• Use inheritance to extend Shape3dUse inheritance to extend Shape3d

Use QuadArrays to define faces, coordinates, etc.Use QuadArrays to define faces, coordinates, etc.

p1 = new Point3d(-30,0,45);p1 = new Point3d(-30,0,45); p2 = new Point3d(30,20,45);p2 = new Point3d(30,20,45);

QuadArray polygon = new QuadArray(4, QuadArray polygon = new QuadArray(4, QuadArray.COORDINATES|QuadArray.NORMALS);QuadArray.COORDINATES|QuadArray.NORMALS);

polygon.setCoordinate(0, p1);polygon.setCoordinate(0, p1); polygon.setCoordinate(1, p2);polygon.setCoordinate(1, p2);

Page 25: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2525

TransformationsTransformations• All the usual suspects…All the usual suspects…

rotationrotation translationtranslation scalingscaling

• Anything that is a child node (in the scene graph) of Anything that is a child node (in the scene graph) of a TransformGroup is affected by that a TransformGroup is affected by that TransformGroup’s Transforms! TransformGroup’s Transforms!

• TransformDemo.javaTransformDemo.java

Page 26: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2626

TransformationTransformation

//set up the transformation//set up the transformationTransform3D trans = new Transform3D();Transform3D trans = new Transform3D();

trans.setTranslation(new Vector3f(-3.0f,0.0f,0.0f));trans.setTranslation(new Vector3f(-3.0f,0.0f,0.0f));trans.setScale(new Vector3d(4.0,0.25,4.0));trans.setScale(new Vector3d(4.0,0.25,4.0));trans.setRotation(new trans.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/2.0));AxisAngle4d(1.0,1.0,0.0,Math.PI/2.0));

//set up a group to use the transformation//set up a group to use the transformationTransformGroup tg = new TransformGroup(trans);TransformGroup tg = new TransformGroup(trans);bg.addChild(tg);bg.addChild(tg);tg.addChild(new Cylinder(0.5f, 4.0f, shinyBlueApp));tg.addChild(new Cylinder(0.5f, 4.0f, shinyBlueApp));

Page 27: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2727

Nesting groupsNesting groups

• You can add Shapes directly to the You can add Shapes directly to the BranchGroupBranchGroup

• Or you can add them to a TransformGroup Or you can add them to a TransformGroup and make that a child of the BranchGroup…and make that a child of the BranchGroup…

• You can nest the TransformGroupsYou can nest the TransformGroups

Page 28: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2828

TranslationTranslation

trans.setTranslation(new Vector3f(-3.0f,0.0f,0.0f));trans.setTranslation(new Vector3f(-3.0f,0.0f,0.0f));

Page 29: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 2929

ScalingScaling

trans.setScale(new Vector3d(4.0,0.25,4.0));trans.setScale(new Vector3d(4.0,0.25,4.0));

Page 30: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3030

RotationRotation

trans.set(new AxisAngle4d(1.0,1.0,0.0,Math.PI/2.0));trans.set(new AxisAngle4d(1.0,1.0,0.0,Math.PI/2.0));

Page 31: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3131

LightingLightingprotected BranchGroup createContentBranch(){protected BranchGroup createContentBranch(){

BranchGroup bg = new BranchGroup();BranchGroup bg = new BranchGroup();......

addLights(bg);addLights(bg);return bg;return bg;}}

protected void addLights(BranchGroup b){protected void addLights(BranchGroup b){......

}}

Page 32: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3232

Ambient LightAmbient Lightprotected void addLights(BranchGroup bg){protected void addLights(BranchGroup bg){

BoundingSphere bounds = new BoundingSphere(new BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);Point3d(0.0,0.0,0.0),100.0);

Color3f ambientColour = new Color3f(0.2f,0.2f,0.2f);Color3f ambientColour = new Color3f(0.2f,0.2f,0.2f);

AmbientLight ambLight= new AmbientLight(ambientColour);AmbientLight ambLight= new AmbientLight(ambientColour);

ambLight.setInfluencingBounds(bounds);ambLight.setInfluencingBounds(bounds);

bg.addChild(ambLight);bg.addChild(ambLight);

}}

Page 33: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3333

Directional LightDirectional Lightprotected void addLights(BranchGroup bg){protected void addLights(BranchGroup bg){

Color3f dirColour = new Color3f(1.0f,1.0f,1.0f);Color3f dirColour = new Color3f(1.0f,1.0f,1.0f);

Vector3f lightDir = new Vector3f(-1.0f,-1.0f,-1.0f);Vector3f lightDir = new Vector3f(-1.0f,-1.0f,-1.0f);

DirectionalLight dirLight= new DirectionalLight dirLight= new DirectionalLight(dirColour,lightDir);DirectionalLight(dirColour,lightDir);

dirLight.setInfluencingBounds(bounds);dirLight.setInfluencingBounds(bounds);

bg.addChild(dirLight);bg.addChild(dirLight);

}}

Page 34: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3434

Other lightsOther lights

• Point lightsPoint lights

• Spot lightsSpot lights

Page 35: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3535

TexturesTexturesTextureLoader tl = TextureLoader tl = newnew TextureLoader( TextureLoader("./resources/wood.jpg""./resources/wood.jpg", , nullnull););

Texture texture = tl.getTexture();Texture texture = tl.getTexture(); texture.setBoundaryModeS(Texture.texture.setBoundaryModeS(Texture.WRAPWRAP);); texture.setBoundaryModeT(Texture.texture.setBoundaryModeT(Texture.WRAPWRAP);); texture.setBoundaryColor( texture.setBoundaryColor( newnew Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) ); Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );

// Set up the texture attributes // Set up the texture attributes // could be REPLACE, BLEND or DECAL instead of MODULATE// could be REPLACE, BLEND or DECAL instead of MODULATE TextureAttributes texAttr = TextureAttributes texAttr = newnew TextureAttributes(); TextureAttributes(); texAttr.setTextureMode(TextureAttributes.texAttr.setTextureMode(TextureAttributes.REPLACEREPLACE););

Appearance ap = Appearance ap = newnew Appearance(); Appearance(); ap.setTexture(texture);ap.setTexture(texture); ap.setTextureAttributes(texAttr);ap.setTextureAttributes(texAttr); //set up the material//set up the material ap.setMaterial(ap.setMaterial(newnew Material()); Material());

// Create a ball to demonstrate textures// Create a ball to demonstrate textures intint primflags = Primitive. primflags = Primitive.GENERATE_NORMALSGENERATE_NORMALS + +

Primitive.Primitive.GENERATE_TEXTURE_COORDSGENERATE_TEXTURE_COORDS;;

Sphere sphere = Sphere sphere = newnew Sphere(0.5f, primflags, ap); Sphere(0.5f, primflags, ap); group.addChild(sphere);group.addChild(sphere);

Page 36: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3636

AnimationAnimation// Create the TransformGroup node and initialize it to the// Create the TransformGroup node and initialize it to the

// identity. Enable the TRANSFORM_WRITE capability so that// identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at run time. Add it to// our behavior code can modify it at run time. Add it to // the root of the subgraph.// the root of the subgraph. TransformGroup objTrans = TransformGroup objTrans = newnew TransformGroup(); TransformGroup(); objTrans.setCapability(objTrans.setCapability( TransformGroup.TransformGroup.ALLOW_TRANSFORM_WRITEALLOW_TRANSFORM_WRITE);); objRoot.addChild(objTrans);objRoot.addChild(objTrans);

// Create a simple Shape3D node; add it to the scene graph.// Create a simple Shape3D node; add it to the scene graph. objTrans.addChild(objTrans.addChild(newnew ColorCube(0.4)); ColorCube(0.4));

// Create a new Behavior object that will perform the// Create a new Behavior object that will perform the // desired operation on the specified transform and add// desired operation on the specified transform and add // it into the scene graph.// it into the scene graph. Transform3D yAxis = Transform3D yAxis = newnew Transform3D(); Transform3D(); Alpha rotationAlpha = Alpha rotationAlpha = newnew Alpha(-1, 4000); Alpha(-1, 4000); RotationInterpolator rotator = RotationInterpolator rotator = newnew RotationInterpolator( RotationInterpolator( rotationAlpha, objTrans, yAxis,rotationAlpha, objTrans, yAxis, 0.0f, (0.0f, (floatfloat) Math.) Math.PIPI*2.0f);*2.0f); BoundingSphere bounds =BoundingSphere bounds = newnew BoundingSphere( BoundingSphere(newnew Point3d(0.0,0.0,0.0), 100.0); Point3d(0.0,0.0,0.0), 100.0); rotator.setSchedulingBounds(bounds);rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator);objRoot.addChild(rotator);

Page 37: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3737

InteractionInteraction Canvas3D c = Canvas3D c = newnew Canvas3D(config); Canvas3D(config);

c.addKeyListener(c.addKeyListener(thisthis););

c.addMouseListener(this);c.addMouseListener(this);

frame.getContentPane().add(frame.getContentPane().add("Center""Center", c);, c);

....

publicpublic voidvoid keyPressed(KeyEvent e) { keyPressed(KeyEvent e) {

// Invoked when a key has been pressed.// Invoked when a key has been pressed.

ifif (e.getKeyChar() == (e.getKeyChar() == 's''s') {) {

xlocxloc = = xlocxloc + .1f; + .1f;

}}

ifif (e.getKeyChar() == (e.getKeyChar() == 'a''a') {) {

xlocxloc = = xlocxloc - .1f; - .1f;

}}

transtrans.setTranslation(.setTranslation(newnew Vector3f( Vector3f(xlocxloc, , heightheight, 0.0f));, 0.0f));

objTransobjTrans.setTransform(.setTransform(transtrans););

}}

Page 38: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3838

Java 3D Game exampleJava 3D Game example

• https://java3d.dev.java.net/applets/https://java3d.dev.java.net/applets/FourByFour.htmlFourByFour.html

Page 39: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 3939

Java SoundJava Sound

Page 40: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 4040

Java Sound PreliminariesJava Sound Preliminaries

File Formats SupportedFile Formats Supported• .au.au or or .snd .snd : usually stores : usually stores

8-bit 8-bit -law encoded samples, -law encoded samples, but can also store 8 or 16 bit but can also store 8 or 16 bit linear sampleslinear samples

• .aif .aif : usually stores 8 or 16 : usually stores 8 or 16 bit linear encoded samplesbit linear encoded samples

• .wav .wav :Can store 8 or 16 bit :Can store 8 or 16 bit samples using linear or samples using linear or -law -law encoded samplesencoded samples

• .midi .midi : follows the midi data : follows the midi data formatformat

Note: The file header indicates Note: The file header indicates the actual formatthe actual format

Frames and Frame RatesFrames and Frame Rates• Sample FrameSample Frame

Stores all the samples taken at Stores all the samples taken at an instant of timean instant of time

# of bytes in a frame = # of # of bytes in a frame = # of bytes in a sample X number of bytes in a sample X number of channelschannels

• Frame RateFrame Rate The number of frames per The number of frames per

second of soundsecond of sound In In mostmost cases frame rate is cases frame rate is

same as sample ratesame as sample rate In compressed sound, the In compressed sound, the

frame rate will be less than frame rate will be less than sample rate.sample rate.

Page 41: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 4141

Java Sound APIJava Sound API

TargetDataLine

Mixer DataLine Port

SourceDataLine

Line

Clip

Page 42: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 4242

Java Sound APIJava Sound API

System ResourcesSystem Resources• Audio Line:Audio Line: Any resource Any resource

that is a source or that is a source or destination of sampled destination of sampled sound datasound data A line can encapsulate A line can encapsulate

several channelsseveral channels Example: input/output ports Example: input/output ports

on the sound cardon the sound card Lines have controls (Lines have controls (gaingain

and and panpan control) control)

• Mixer: Mixer: Receives input from Receives input from one or more one or more source data source data lineslines and outputs the result and outputs the result of combining the input to an of combining the input to an output line called a output line called a target target data linedata line

Other Sound SourcesOther Sound Sources• A file or more generally a A file or more generally a

URLURL

Terminology:Terminology:• A A source data linesource data line is a source is a source

for a for a mixermixer, not a source for , not a source for you; you you; you writewrite to it to it

• A A target data linetarget data line is the output is the output from the from the mixermixer; your ; your readread from it from it

MIXERSound i/p

Sound i/p

Sound i/p

Sound o/p

Sound o/p

Target Data LinesSource Data Lines

Page 43: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 4343

Java Sound API (…contd)Java Sound API (…contd)

Packages:Packages:• javax.sound.sampledjavax.sound.sampled• javax.sound.midijavax.sound.midi• javax.sound.sampled.spijavax.sound.sampled.spi• javax.sound.sampled.midjavax.sound.sampled.mid

ii

The The AudioSystemAudioSystem class class

• Establish whether a Establish whether a particular resource is particular resource is availableavailable

• Get a ref. to the object that Get a ref. to the object that encapsulates the resourceencapsulates the resource

• Call methods to operate the Call methods to operate the resourceresource

AudioStreamInputAudioStreamInput class class

• Represents a stream that is Represents a stream that is a source of sampled sound a source of sampled sound data with a specific formatdata with a specific format

• You can create an You can create an AudioStreamInputAudioStreamInput object object from a local sound file, from from a local sound file, from another input stream or a another input stream or a URLURL

• You canYou can Read data from itRead data from it Write its contents to an Write its contents to an

output streamoutput stream Convert its formatConvert its format

Page 44: Java 3D API, Sound

July 31, 2008July 31, 2008 James Atlas - CISC370James Atlas - CISC370 4444

Resource Descriptor ClassesResource Descriptor Classes

Mixer.Info DataLine.Info Port.Info

Line.Info

The Line, DataLine, Mixer and Port interface definitions each include an inner class with the name Info. Objects of these class types encapsulate data specifying an object of the corresponding type

Specifies a Line object by its Class

Specifies a Mixer object by its name, vendor version and description

Specifies a DataLine by the audio formats to be supported, the buffer size limits, and the Class of the data line

Specifies a Port object by its Class, its name, and whether it is a source or target line


Recommended