lecture21 other java gamming technologies – java3d (this lecture will not be assessed)

21
Lecture21 Lecture21 Other Java Gamming Other Java Gamming technologies – Java3D technologies – Java3D (This lecture will not be (This lecture will not be assessed) assessed)

Post on 19-Dec-2015

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Lecture21Lecture21

Other Java Gamming Other Java Gamming technologies – Java3D (This technologies – Java3D (This lecture will not be assessed)lecture will not be assessed)

Page 2: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Java3DJava3D The Java 3D API provides a collection of high-level

constructs for creating, rendering, and manipulating a 3D scene graph composed of geometry, materials, lights, sounds, and more.

There are two Java 3D variants: • one implemented on top of OpenGL, the other above

DirectX Graphics. • The low-level API handles the native rendering at the

vertex and pixel levels, while the 3D scene, application logic, and scene interactions are carried out by Java code. This dual approach encourages application portability, hardware independence, and high-speed rendering.

Intended application areas include visualization, CAD/CAM, virtual reality, simulation, and gaming.

Page 3: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

The Scene GraphThe Scene Graph

Java 3D’s scene graph is a directed acyclic graph (a DAG), so there's a parent-child relationship between most of its nodes, and the graph doesn't contain loops.

It is possible for nodes to be shared in a graph, for example to duplicate geometry details.

Page 4: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Scene Graph - ExampleScene Graph - Example

A simplified scene graph for an office:

Page 5: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Scene Graph Symbols

Page 6: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

NodesNodes A shape node employs Shape3D (or its

subclasses) as a container for Geometry and Appearance node components. The main geometry class is GeometryArray, used for drawing points, lines, and polygons. There are many Appearance subclasses, including ones for colour, texture, and transparency.

Environment nodes handle environmental concerns, such as lighting, sound, and behaviours that change the virtual world.

Group nodes are containers for other groups or leaf nodes.

Leaf nodes are usually shape or environmental nodes. The Group class supports node positioning and orientation for its children, and is subclassed in various ways. • For instance, BranchGroup allows children to be added or

removed from the graph at run time, while TransformGroup permits the position and orientation of its children to be changed.

Page 7: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Scene Graph – Virtual UniverseScene Graph – Virtual Universe

Each scene graph has a single VirtualUniverse. • The VirtualUniverse object has a list of Locale

objects. A Locale object provides a reference point in the

virtual universe. Think of a Locale object as being a landmark used to

determine the location of visual objects in the virtual universe.

While a VirtualUniverse object may reference many Locale objects, most Java 3D programs have only one Locale object.

Page 8: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Virtual UniverseVirtual Universe

The visual objects in front of the image plate are rendered to theimage plate. Rendering can be thought of as projecting the visual objects to the image plate.

Page 9: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Virtual UniverseVirtual Universe

Page 10: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Scene Sub GraphsScene Sub Graphs There are two different categories of scene

sub graph: the view branch graph and the content branch graph. • The content branch graph specifies the

contents of the virtual universe - geometry, appearance, behaviour, location, sound, and lights.

• The view branch graph specifies the viewing parameters such as the viewing location and direction.

Together, the two branches specify much of the work the renderer has to do.

Page 11: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Basic Recipe for java3D programBasic Recipe for java3D program

1. Create a Canvas3D object2. Create a VirtualUniverse object3. Create a Locale object, attaching it to the

VirtualUniverse object4. Construct a view branch graph5. Construct content branch graph(s)6. Compile branch graph(s)7. Insert content branch graphs into the

Locale

Page 12: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Using a SimpleUniverse ObjectUsing a SimpleUniverse Object Steps 2, 3, and 4 of the previous basic recipe are

replaced by step 2 of the following simple recipe.1. Create a Canvas3D Object2. Create a SimpleUniverse object which references the earlier Canvas3D object

a. Customize the SimpleUniverse object3. Construct content branch4. Compile content branch graph5. Insert content branch graph into the Locale of the SimpleUniverse

Page 13: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

SimpleUniverseSimpleUniverse The SimpleUniverse object creates a complete

view branch graph for a virtual universe. The view branch graph includes an image plate. An image plate is the conceptual rectangle where the content is projected to form the rendered image. The Canvas3D object, which provides an image in a window on your computer display, can be thought of as the image plate.

Specifically, this class creates Locale, VirtualUniverse, ViewingPlatform, and Viewer objects (all with their default values). The objects have the appropriate relationships to form the view branch graph.

SimpleUniverse(Canvas3D canvas3D) • Construct as simple universe with a reference to the

named Canvas3D object.

Page 14: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

ExampleExample

The rotating colour The rotating colour cube example from cube example from Java3D tutorial Java3D tutorial available from sun available from sun websitewebsite

Page 15: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

The scene graph for the rotating colour cube

Page 16: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Rotating Colour CubeRotating Colour Cubepublic class HelloJava3D extends Applet {

public HelloJava3D() {setLayout(new BorderLayout());Canvas3D canvas3D = new Canvas3D(null);add("Center", canvas3D);

BranchGroup scene = createSceneGraph();scene.compile();

// SimpleUniverse is a Convenience Utility classSimpleUniverse simpleU = new SimpleUniverse(canvas3D);

// This moves the ViewPlatform back a bit so the// objects in the scene can be viewed.simpleU.getViewingPlatform().setNominalViewingTransform();

simpleU.addBranchGraph(scene);} // end of HelloJava3D (constructor)…

}

Page 17: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Rotating Colour CubeRotating Colour Cubepublic BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();TransformGroup objSpin = new TransformGroup();objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);objRoot.addChild(objSpin);objSpin.addChild(new ColorCube(0.4));

// BehaviourAlpha rotationAlpha = new Alpha(-1, 4000);RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

// a bounding sphere specifies a region a behavior is activeBoundingSphere bounds = new BoundingSphere();rotator.setSchedulingBounds(bounds);objSpin.addChild(rotator);return objRoot;

} // end of createSceneGraph method

Page 18: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

CapabilitiesCapabilities There are cases when a program still

needs the capability to change values in a scene graph object after it becomes live. • For example, changing the value of a

TransformGroup object creates animations. For this to happen, the transform must be able to change after it is live.

• The list of parameters that can be accessed, and in which way, is called the capabilities of the object.

ALLOW_TRANSFORM_READ - Specifies the TransformGroup node allows access to the transform information of its object.

ALLOW_TRANSFORM_WRITE - Specifies the TransformGroup node allows writing the transform information of its object.

Page 19: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Specifying Animation Behavior

A behavior action can be a change in location (PositionInterpolator), orientation (RotationInterpolator), size (ScaleInterpolator), color (ColorInterpolator), or transparency (TransparencyInterpolator) of a visual object.

RotationInterpolator object - This class defines a behavior that modifies the rotational component of its target TransformGroup by linearly interpolating between a pair of specified angles (using the value generated by the specified Alpha object). The interpolated angle is used to generate a rotation transform.

Page 20: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Specifying Animation Behavior Alpha class objects are used to create a time

varying function. It converts time into an alpha value (a value in the range 0 to 1).

• Alpha(int loopCount, long increasingAlphaDuration) loopCount - number of times to run this alpha object; a

value of -1 specifies that the alpha loops indefinitely. increasingAlphaDuration - time in milliseconds during

which alpha goes from zero to one

Page 21: Lecture21 Other Java Gamming technologies – Java3D (This lecture will not be assessed)

Behaviour - Scheduling Region

Scheduling region is a spatial boundary for a behavior to take place. • A behavior is not active unless the

ViewPlatform’s activation volume intersects a Behavior object’s scheduling region.

• In other words, if there is no one in the forest to see the tree falling, it does not fall.