Title: 3D Graphics
1Chapter 4
2Java 3D Overview
- Java3D picture is a scene or virtual universe
- has a coordinate system to describe location of
scene graphs - each scene graph attaches at specific point in
virtual universe coordinate system - scene graph has its own internal coordinate
system and branch graphs - root node in scene graph is Locale
- Two types of branch graphs are content branch and
view branch graphs - content branch includes geometry, lighting,
textures, fog, behaviors - view branch graph contains viewing
platform/viewport with perspective, position,
orientation, scale
3Java3DWorld
- Extends Canvas3D blank area for drawing/
trapping events
minimal user environment, root of scene
SimpleUniverse
contains
Locale
Viewer
ViewingPlatform
position in VirtualUniverse collection of
BranchGroups defines VirtualWorld coord system
describes presence in Java3D universe physical
objects head track sensor etc. virtual objects
View, ViewerAvatar
set up View contains ViewPlatform and geometries
4Java3DWorld cont
root of Scene add to Locale to insert into
Universe can compile can reparent or detach
scene
BranchGroup
add
translateBehavior
add
add
add
add
add
transformGroup
rotateBehavior
ambientLight
directionalLight
scaleBehavior
Mouse Behaviors
ALLOW_TRANSFORM_READ ALLOW_TRANSFORM_WRITE
add
shape
BoundingSphere bounds applied to ambientLight,
directionalLight, rotateBehavior,
scaleBehavior AmbientLight room lighting.
DirectionalLight between source/destination
53D Classes used in Example
- Group
- General purpose grouping
- 1 parent, some number of children
- Methods to add, remove, count children
- Set collision bounds
- TransformGroup
- Single spatial transform
- position, orient, scale all children
- Must specify ALLOW_TRANSFORM_READ/
ALLOW_TRANSFORM_WRITE to modify while running - Transform3D specifies how to transform
- 4x4 matrix (normally created for you)
- Must be affine (preserves collinearity, ratios
but not angles or lengths) - translations, rotations, scaling, shear
63D Classes cont.
- Properties of objects and scene appearance,
texture, lighting etc. covered in separate files - MouseRotate, MouseTranslate, MouseZoom lets
users control action of object using a mouse.
Works on TransformGroup based on scheduling
Bounds.
7Java3DExample
- Creates a Java3DWorld with just one shape
- Creates a control panel
- Can use mouse to rotate, move, change size
8Exercise
- Run Java3DExample
- If you need to update the library (shouldnt in
CTLM) - Project-gtProperties-gtJava Build Path
- Libraries-gtclick on JRE, select Edit
- Check Alternate JRE
- In dialog, Add, give a name (e.g., Graphics VM),
set JRE Home to location containing graphics
libraries (vecmath, j3dcore, j3dutils) - Be sure to select that JRE after dialog is done
(it may not be the default) - To download Java3D,go to https//java3d.dev.java.n
et/ - Read Java3DWorld
- Try changing bounds (e.g., try with center at
(-.9, -.9, 0). Rotate cube to see several faces.
Change directional light. What do you notice?
93D Game Overview
SimpleUniverse
Background
ViewPlatform
sceneBranchGroup
directionLight
ambientLight
sceneSwitch
navigator
collider
goalDetector
collidable read/write report collision
loserTransformGroup
winnerTransformGroup
gameBranchGroup
shapeSwitch
startTransform
targetTransform
flyingBall
targetSphere
path Transform
spin Transform
Appearance
Shape
10Interpolators
- Interpolator abstract
- methods to convert time to alpha, initialize
- schedules Behavior to awaken next frame
- TransformInterpolator abstract
- set/get target of TransformGroup
- set/get transform of axis
- defines local coordinate system
- abstract computeTransform compute new transform
based on alpha value - process stimulus called every frame. Gets
alpha value for current time, calls
computeTransform, updates target TransformGroup
11Interpolators, cont
- RotationInterpolator
- linearly interpolates between specified angles
- generates rotation transform about Y-axis
- uses Alpha
- PositionInterpolator
- linearly interpolates between pair of specified
positions
12Alpha
Assume path from point A to point B
B
A
Where should the object be at time 0? Point A.
At time 1? Point B. But in between, does the
object move at constant velocity? Does it
accelerate? Is there a delay before it begins to
move?
13Alpha cont.
- loopCount times to run, -1 indefinitely
- triggerTime time in ms since start time that
this object should first trigger - if (startTime triggerTime gt currentTime) then
start running - phaseDelayDuration additional ms after
TriggerTime - mode - INCREASING_ENABLE DECREASING_ENABLE
- increasingAlphaDuration time Alpha goes from 0
to 1 - increasingAlphaRampDuration Alpha step size,
increases at begin of duration, decreases at end.
Clamped to ½ AlphaDuration. if non-zero,
constant acceleration during ramp. If zero,
acceleration is 0. - alphaAtOneDuration how long stays at 1.
14(No Transcript)
15createShapes
shapes
random shape, Box, Cone, Cylinder,
Sphere collidable read/write
Primitive
16createAppearance
material
shapeAppearance
set Ambient Black set diffuse random, determines
color when illuminated
Material
17createRotationalInterpolator
spinner
alphaSpin
spinTransform
creates Alpha as increasing duration, rand
rotation speed from 2000 to 2500 ms
spinAxis
Rotation Interpolator
Alpha
Transform Group
Transform3D
create rotx (counter clockwise around x, angle in
radians) spinAxis will be set to random axis of
rotation PI Math.random() 2 is arg to rotx,
linearly interpolates between angles
RotationInterpolator
Transform3D
TransformGroup
Alpha
applies Transform3D to all objects in
TransformGroup, Alpha provides details
18createPositionalInterpolator
mover
alphaPath
pathTransform
creates Alpha as increasing/decreasing to move
back and forth, phase delay so doesnt move
immediately, rand speed from 2500 - 7500 ms
pathAxis
Position Interpolator
Alpha
Transform Group
Transform3D
PositionInterpolator
random transform axis different directions
1, -1 start/end
Transform3D
TransformGroup
Alpha
applies Transform3D to all objects in
TransformGroup, Alpha provides details
19Behavior
- Framework for adding user-defined actions to
scene graph. - Abstract class. Subclasses must define
initialization and processStimulus. - Initialization called once when behavior becomes
live. - processStimulus called by 3D behavior scheduler.
Behavior node is active when ViewPlatform's
activation region intersects scheduling region. - Scheduling region bounds on what nodes exhibit
behaviors. - Scheduling interval provides partial ordering for
behaviors that respond to same condition. - Must set wakeup or behavior never occurs.
- Typical behavior modifies one or more nodes in a
scene graph. - Structure of behavior methods decode wakeup
condition, perform manipulation, establish new
wakeup condition, exit.
20WakeUpCondition
- Abstract class.
- Fourteen different WakeUp Criterion, such as of
frame drawn, collision, movement, etc.
21Navigator
- Navigator attached to flying ball transform
- Starts at .9, -.9, 0, read/write set
- WakeupCondition is AWTEvent like key press
- Get Transform3D from object
- Update x, y or z vector depending on key pressed
- Update Transform3D using vector
22GoalDetector
- Initialize goal coordinates and radius in
constructor - Whenever key is pressed
- get current position as Vector3F
- compare to goal
- if within radius of goal, shift scene to winner
23Partial Class Hierarchy
Object
SceneGraphObject
Transform3D View Virtual Universe
Node
NodeComponent
Group
Alpha Appearance Texture etc
ViewSpecific Group
Switch
BranchGroup
OrderedGroup
Primitive
viewer Avator
Platform Geometry
View Platform
Box
Cone
Cylinder
Sphere
Leaf
Bounding Leaf
Shape3D
Morph
Sound
AlternateApp
ModelClip
Fog
Light
Background
Behavior
24Exercise
- Run Java3DGame
- Run FallingBall
- Modify FallingBall to start from the other side
of the screen. Modify the appearance of the
sphere. - Run MoveIntoObject
- Modify MoveIntoObject to exhibit some behavior
when the game piece touches one of the spheres
25Exercises
- Read the other information in Java3DInfo
- Create a new scene of your own