3D Graphics - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

3D Graphics

Description:

... give a name (e.g., Graphics VM), set JRE Home to location containing graphics ... To download Java3D,go to https://java3d.dev.java.net/ Read Java3DWorld ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 26
Provided by: cyndi8
Category:
Tags: download | graphics | java | vm

less

Transcript and Presenter's Notes

Title: 3D Graphics


1
Chapter 4
  • 3D Graphics

2
Java 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

3
Java3DWorld
  • 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
4
Java3DWorld 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
5
3D 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

6
3D 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.

7
Java3DExample
  • Creates a Java3DWorld with just one shape
  • Creates a control panel
  • Can use mouse to rotate, move, change size

8
Exercise
  • 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?

9
3D 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
10
Interpolators
  • 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

11
Interpolators, cont
  • RotationInterpolator
  • linearly interpolates between specified angles
  • generates rotation transform about Y-axis
  • uses Alpha
  • PositionInterpolator
  • linearly interpolates between pair of specified
    positions

12
Alpha
  • Converts time to 0,1.0

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?
13
Alpha 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)
15
createShapes
shapes
random shape, Box, Cone, Cylinder,
Sphere collidable read/write
Primitive
16
createAppearance
material
shapeAppearance
set Ambient Black set diffuse random, determines
color when illuminated
Material
17
createRotationalInterpolator
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
18
createPositionalInterpolator
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
19
Behavior
  • 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.

20
WakeUpCondition
  • Abstract class. 
  • Fourteen different WakeUp Criterion, such as of
    frame drawn, collision, movement, etc.

21
Navigator
  • 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

22
GoalDetector
  • 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

23
Partial 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
24
Exercise
  • 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

25
Exercises
  • Read the other information in Java3DInfo
  • Create a new scene of your own
Write a Comment
User Comments (0)
About PowerShow.com