Virtual Reality Development Using Java3d - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Virtual Reality Development Using Java3d

Description:

Outline the hardware that we will be using this semester ... For comport and adjustment. Goggles display 1024x768 pixels. Connected to TV out of PC video card ... – PowerPoint PPT presentation

Number of Views:128
Avg rating:3.0/5.0
Slides: 52
Provided by: john340
Category:

less

Transcript and Presenter's Notes

Title: Virtual Reality Development Using Java3d


1
Virtual Reality Development Using Java3d
  • John Hopf
  • cisjph_at_cs.unisa.edu.au

2
This Lecture
  • Outline the hardware that we will be using this
    semester in the VR Lab
  • Introduce some basic concepts of Java3d
    programming
  • Only the basics
  • More resources on web
  • Outline the software we will be using this
    semester
  • Large
  • Only going through code youll need to change
  • Change any others and youre on your own

3
VR Laboratory PCs
  • SGI machines
  • Organising space on Bullwinkle
  • Develop models with Cosmo Worlds
  • Has Java3d so can develop and test
  • Nice big monitors
  • Two desktop windows machines
  • Itchy on south end P4 1.8GHz GF3
  • Scratchy on north end P4 1.9GHz GF4
  • Mainly for testing with the trackers
  • Logging on

4
The Polhemus Trackers
  • Reflect real movement in virtual world
  • Polhemus trackers
  • Use magnetic fields
  • Transmitter on ceiling mounting is important
  • Used to track position of receivers boresight
  • Gets Heading, Pitch, Roll, X, Y, Z data
  • Itchy Fasttrak with four receivers
  • Scratchy Isotrak2 with two receivers

5
Tracker Output
  • Translation and rotation
  • X,Y,Z co-ordinates are in centimeters units
  • Heading, Pitch, Roll are in degrees units
  • Heading left/right
  • Pitch up/down
  • Roll side to side
  • Take this data and apply it to the view and hand
    avatar

6
Hand Controllers
  • Controlling the hand in the virtual world
  • Joystick handle with 5 buttons
  • Buttons can be programmed for user defined
    functionality
  • Mounted with a receiver to track hand movement
  • Itchy has two and Scratchy has one
  • Connected through a magic box to serial port

7
Head Mount Display
  • So you can see without facing the monitor
  • VR goggles mounted on a welding helmet
  • For comport and adjustment
  • Goggles display 1024x768 pixels
  • Connected to TV out of PC video card
  • A receiver is also mounted on the helmet to track
    head movement

8
Further Information
  • Visit the Java3d resources web page
  • http//www.cis.unisa.edu.au/cisjph/vr/
  • Provides Java API software required
  • Instructions for installation
  • Information about using equipment
  • Contains code and updates for bug
    fixes/improvements visit regularly
  • Software on CD

9
Introducing Java3d
  • A Java extension For 3D Programming
  • Many platforms windows, unix, SGI
  • OpenGL and DirectX
  • This only an introduction
  • Essential reading
  • Getting Started With Java3d From Sun
  • Essential Java3d By Ian Palmer

10
How The World Is Presented
  • The World Is Displayed As An Applet
  • Currently set to 1020 x 760 to fill the screen
  • The World is placed on a Canvas3D which is a
    subclass of Canvas
  • The Canvas3D is placed on the Applet
  • The Virtual Universe is then set to the Canvas3D

11
Java3d Program Structure
  • Java3d uses a scene graph concept

12
Code To Create Our World
  • Instantiate The SimpleUniverse Class
  • Creates a simple Universe
  • Includes a default locale
  • Includes a default view branch
  • Create The Content Branch And Add It To The
    SimpleUniverse

13
Modifying The View Branch
  • Defines how the scene is displayed
  • Default from the SimpleUniverse
  • Can get the viewPlatform to modify it
  • We get the TransformGroup can use Transform3D
  • Changing the view
  • Eye position of the eye
  • Centre a point we look at
  • Up vector pointing to up location
  • Dont need to change much else

14
Creating The Content Branch
  • The branch you need to change
  • Defines what the scene looks like
  • Objects
  • Lighting
  • Behaviour
  • Contains a BranchGroup instance
  • Objects and lights are added to this instance
  • Use the createSceneGraph() method

15
Creating Objects
  • Objects to provide the look of the world
  • Two possible ways
  • Use Java3d
  • Use a 3rd party tool to create objects
  • Java3d looks better but is harder
  • Looks vs. time
  • Textures and lighting
  • Your choice

16
Java3d Objects
  • Can combine several later on
  • Create A Shape3D
  • Define Geometry usually vertices of faces
  • Define Appearance colour and texturing
  • Basic shapes are available (cubes/spheres)
  • Geometry Best Defined Using Geometry Arrays
  • QuadArray or TriangleArray
  • Appearance Is Defined In An Instance Of The
    Appearance Class

17
Defining Geometry
  • As said we use a geometry array
  • Define faces
  • Quadrilaterals or Triangles
  • Co-ordinates of points
  • Define faces
  • Use a float array
  • Three points per vertice

18
Example Defining A Cube
  • Use The QuadArray Class
  • A cube contains 6 quadrilateral faces
  • Need to specify 24 vertices
  • Create A float Array For Coordinates
  • Create A Default Appearance Object
  • Create A Shape3D object

19
Code To Create A Cube
  • Shape3D buildCube()
  • float cubeFaces
  • 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f,
  • -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
    1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
  • 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f,
    1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,
  • -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
  • 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
    -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f,
  • -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f,
    1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f
  • QuadArray cubeData new QuadArray(24,
    QuadArray.COORDINATES)
  • cubeData.setCoordinates(0, cubeFaces)
  • Appearance app new Appearance()
  • return new Shape3D(cubeData, app)

20
What Does It Look Like?
  • Doesnt Look Nice
  • It Uses A Default Appearance
  • No Lighting

21
Appearance
  • Use The Appearance Class
  • Control colour
  • Control textures
  • Others for you to try
  • Will discuss colour after lighting
  • Images Show Coloured And Textured Cubes

22
Texturing Objects
  • Apply textures to the Appearance object
  • Texture Comes From A File
  • JPEG or GIF not too big
  • Keep images in the images directory
  • Need A Texture2D Instance
  • Use TextureLoader to load the texture
  • Use ImageComponent2D to get the image
  • Create Texture2D Instance
  • Add texture to appearance instance

23
Code That Adds A Texture To An Appearance
  • protected Appearance DefineAppearance()
  • //Load the texture from the external image file
  • TextureLoader textLoad new TextureLoader("house
    brick.jpg", this)
  • ImageComponent2D textImage textLoad.getImage()
  • //Create a two dimensional texture
  • Texture2D texture new Texture2D(Texture2D.BASE_
    LEVEL, Texture.RGB,
  • textImage.getWidth(), textImage.getHeight())
  • //Set the texture from the image loaded
  • texture.setImage(0, textImage)
  • //Create the appearance that will use the
    texture
  • Appearance app new Appearance()
  • app.setTexture(texture)
  • TextureAttributes textAttr new
    TextureAttributes()
  • textAttr.setTextureMode(TextureAttributes.REPLACE
    )
  • app.setTextureAttributes(textAttr)
  • return app

24
Adding Shape3d To The World
  • Have To Add To A Transform Group
  • Can add more than one shape3d to the group
  • Table 4 legs and a table top
  • Create A Transform3D Object For Translation And
    Rotation
  • Translation Vector3f
  • Rotation rotX, rotY, rotZ
  • Add Transform3D to the Group
  • Add TransformGroup To The Root Transform Group

25
Using 3rd Party Tools - VRML
  • Using Shape3D Is Laborious
  • You can use VRML to specify objects
  • We have a VRML loader for our world
  • VRML97
  • Many Graphics Apps Can Write VRML
  • Windows ISB, Spazz3D, 3DS Max
  • SGI Cosmo Worlds
  • Easy To Manipulate Shapes And Apply Textures

26
Getting VRML Into Java3D
  • Create An Instance Of VRMLObject
  • Filename without extension is argument
  • Get the TransformGroup from the object
  • Add to the rootTrans transform group
  • Manipulating The Transform Group
  • Create a Transform3D object
  • Rotate and translate
  • Set the Transform3D to the transform group

27
Using The VRML Loader - Example
  • VRMLObject table new VRMLObject
    ("coffee_table")
  • TransformGroup tableTransformGroup
  • table.getTransformGroup ()
  • Transform3D tableTransform new Transform3D ()
  • Vector3d tableLocation new Vector3d (0.0, 1.0,
    0.0)
  • tableTransform.rotX(Math.PI/4)
  • tableTransform.setTranslation (tableLocation)
  • tableTransformGroup.setTransform
    (tableTransform)
  • rootTrans.addChild (tableTransformGroup)

28
Java3d Lighting - Lights
  • Java3d Offers Four Types Of Lighting
  • Ambient Light lights all objects equally
  • Directional Light similar to sunlight
  • Point Light a perfect light bulb
  • Spot Light similar to a real life spotlight
  • Limit The Influence Of The Light
  • Isolate bedroom light to the bedroom
  • setInfluencingBounds()
  • Well go through each light type

29
Ambient Light
  • All Virtual Worlds Should Have One
  • Left Is With And Right Is Without
  • Color3f ambientColour new Color3f(0.2f, 0.2f,
    0.2f)
  • AmbientLight ambientLight new
    AmbientLight(ambientColour)
  • ambientLight.setEnable(true)
  • ambientLight.setInfluencingBounds(new
    BoundingSphere(0.0,0.0,0.0), 10)
  • Root.addChild(ambientLight)

30
Directional Light Example
  • Color3f lightColour new
  • Color3f(1.0f,1.0f,1.0f)
  • Vector3f lightDir new
  • Vector3f(0.0f,-1.0f,-1.0f)
  • DirectionalLight light new
  • DirectionalLight( lightColour,lightDir)

31
Directional Light Example 2
  • Color3f lightColour new
  • Color3f(1.0f,1.0f,1.0f)
  • Vector3f lightDir new
  • Vector3f(0.0f,1.0f,-1.0f)
  • DirectionalLight light new
  • DirectionalLight( lightColour,lightDir)

32
Point Light
  • Color3f lightColour new
  • Color3f(1.0f, 1.0f, 1.0f)
  • Point3f lightPosition new
  • Point3f(1.5f, 1.5f, 1.5f)
  • Point3f lightAtten new
  • Point3f(1.0f, 0.0f, 0.0f)
  • PointLight light new PointLight(lightColour,
    lightPosition, lightAtten)

33
Spot Light
  • Color3f blueColour new Color3f(0.0f, 0.0f,
    1.0f)
  • Point3f bluePosition new Point3f(1.8f, 1.8f,
    1.8f)
  • Point3f blueAtten new Point3f(1.0f, 0.0f,
    0.0f)
  • Vector3f blueDir new Vector3f(-1.0f,-1.0f,-1.0f)
  • SpotLight blueLight new SpotLight(blueColour,
  • bluePosition,blueAtten,
  • blueDir,(float)(Math.PI/2.0),0.0f)
  • Color3f greenColour new Color3f(0.0f, 1.0f,
    0.0f)
  • Point3f greenPosition new Point3f(0.0f, 0.0f,
    3.0f)
  • Point3f greenAtten new Point3f(1.0f, 0.0f,
    0.0f)
  • Vector3f greenDir new Vector3f(0.0f, 0.0f,
    -1.0f)
  • SpotLight greenLight new SpotLight(greenColour,
  • greenPosition,greenAtten,
  • greenDir,(float)(Math.PI/2.0), 0.0f)

34
Java3d Lighting - Surfaces
  • The Material Class For Appearance
  • ambientColor color under ambient light
  • diffuseColor the light reflected
  • specularColor for highlights like shine
  • emissiveColor the light a surface emits
  • shininess the level of shininess of the surface

35
Surface Colour Example
  • Appearance app new Appearance()
  • Color3f ambientColour new Color3f(0.0f, 1.0f,
    0.0f)
  • Color3f diffuseColour new Color3f(1.0f, 0.0f,
    0.0f)
  • Color3f specularColour new Color3f(1.0f, 1.0f,
    1.0f)
  • Color3f emissiveColour new Color3f(0.0f, 0.0f,
    0.0f)
  • float shininess 20.0f
  • app.setMaterial(new Material(
  • ambientColour,emissiveColour,
    diffuseColour,specularColour, shininess))

36
Specifying Behaviour
  • We Have A Scene But Its Nothing Without
    Behaviour
  • Behaviour provides life
  • Behaviours Are Applied To Objects
  • Need To Specify When It Happens
  • Each Frame, Elapsed Time, Using Timers and others
  • We Will Discuss Using Rotation Interpolators And
    The Behaviour Attached To The Hand

37
Rotation Interpolators
  • Default Rotation About The Y Axis
  • Alpha Object Is Used For Timing
  • Control speed/acceleration
  • Control duration
  • Produces a value between zero and one
  • Ideal For Fans, Wheels and Other Rotating Objects

38
Rotation Interpolator Y Axis
  • Transform3D rotateCube new
  • Transform3D( )
  • TransformGroup rotationGroup new
  • TransformGroup(rotateCube)
  • Alpha rotationAlpha new
  • Alpha(-1,Alpha.INCREASING_ENABLE,0,
  • 0,4000,0,0,0,0,0)
  • Transform3D yAxis new Transform3D()
  • RotationInterpolator rotator new
  • RotationInterpolator(rotationAlpha,
    rotationGroup, yAxis,
  • 0.0f, (float) Math.PI2.0f)
  • contentBranch.addChild(rotationGroup)
  • rotationGroup.addChild(shape)
  • rotationGroup.addChild(rotator)

39
Rotation Interpolator - X Axis
  • Transform3D rotateCube new
  • Transform3D( )
  • TransformGroup rotationGroup new
  • TransformGroup(rotateCube)
  • Alpha rotationAlpha new
  • Alpha(-1,Alpha.INCREASING_ENABLE,0,0,
  • 4000,0,0,0,0,0)
  • Transform3D yAxis new Transform3D()
  • yAxis.rotZ(Math.PI/2)
  • RotationInterpolator rotator new
  • RotationInterpolator(rotationAlpha,
    rotationGroup, yAxis,
  • 0.0f, (float) Math.PI2.0f)
  • contentBranch.addChild(rotationGroup)
  • rotationGroup.addChild(shape)
  • rotationGroup.addChild(rotator)

40
Rotation Interpolator Z Axis
  • Transform3D rotateCube new
  • Transform3D( )
  • TransformGroup rotationGroup new
  • TransformGroup(rotateCube)
  • Alpha rotationAlpha new
  • Alpha(-1,Alpha.INCREASING_ENABLE,0,0,
  • 4000,0,0,0,0,0)
  • Transform3D yAxis new Transform3D()
  • yAxis.rotX(Math.PI/2)
  • RotationInterpolator rotator new
  • RotationInterpolator(rotationAlpha,
    rotationGroup, yAxis,
  • 0.0f, (float) Math.PI2.0f)
  • contentBranch.addChild(rotationGroup)
  • rotationGroup.addChild(shape)
  • rotationGroup.addChild(rotator)

41
Creating An Alpha
  • Number of loops -1 indicates this loops
    infinitely
  • Increasing or decreasing
  • The time in milliseconds after system start up
    until the behaviour starts
  • The time after the trigger time that the alpha
    values are generated
  • How long it takes for the value of alpha to go
    from 0 to 1
  • Acceleration
  • Delay until restart
  • The remaining 3 arguments are used for decreasing
    alpha.

42
Where Are We Now?
  • We Know How To Build A Scene
  • We know how to add objects VRML is easier
  • We know what lighting we can use
  • We know how to attach behaviours to objects
  • Now We Can Discuss How To Handle Interactions
    Using The Hand

43
The Hand Behaviour
  • In System We Have A Behaviour For The Hand That
    Fires On Every Frame
  • Extends The Behavior Class
  • Need to implement initialize()
  • Need to implement processStimulus()
  • Need To Make Changes To This Behaviour For
    Hand/World Interaction
  • Rotation And Translation From Tracker
  • Data Received From Button States

44
The Hand Behaviour
  • Five Buttons Available For Interaction
  • Trigger is to pick see code
  • Middle is to fly see code
  • Left is to strafe see code
  • Right is to strafe see code
  • Side see code
  • Change The Last 3 Be Creative!!

45
Interactions With Objects
  • Moving Objects Is Already Implemented
  • What About Other Interactions
  • A light switch
  • A Door
  • We Need To Differentiate Certain Objects From
    General Ones

46
Allowing Objects To Be Picked
  • You Can Specify Which Objects Are Sensitive To
    Hand Touches
  • Use the setCollidable method
  • You can set your own capabilities if you wish

47
Interactions With Objects
  • Identifying Specific Objects
  • Can use the setUserData() method
  • How can we access other objects
  • Pass Necessities To HandBehaviour
  • Arrays of Transform Groups, Lights and Others
  • Make sure you remember which objects are in what
    array elements

48
Adding To The Object Array
  • TransformGroup groups new TransformGroup1
  • ...
  • VRMLObject lghtswtch new VRMLObject
    ("lightswitch")
  • TransformGroup lghtswtchTransformGroup
    lghtswtch.getTransformGroup ()
  • Transform3D lghtswtchTransform new Transform3D
    ()
  • Vector3d lghtswtchLocation new Vector3d (4.0,
    2.0, 0.0)
  • lghtswtchTransform.setTranslation
    (lghtswtchLocation)
  • lghtswtchTransformGroup.setTransform
    (lghtswtchTransform)
  • setCollidable(lghtswtch)
  • rootTrans.addChild (lghtswtchTransformGroup)
  • groups0 lghtswtchTransformGroup

49
Accessing Array Elements
  • private void processDrag_ (int button)
  • ...
  • TransformGroup group getPickedObject_collision
    ()
  • ...
  • if (group groups0))
  • processLightSwitchInteraction()
  • ...
  • private void processLightSwitchInteraction()
  • lights0.setEnabled(true)

50
Summary
  • What Have We Covered Today
  • Hardware we will be using
  • How we have created our world following the scene
    graph concept Java3d follows
  • How to create objects and add them to our world
  • How to create lighting and adjust appearances of
    object
  • How to give life to our world using behaviour
  • How we can use the hand to interact with the world

51
Recommendations
  • Dont Leave Assignments To The Last Minute
  • Two test machines and 40 students
  • Make Use of your allocated testing time
  • Dont Sacrifice Usability For Good Looks
  • Use A Third Party VRML Editor To Create Objects
    And For Texturing
  • Make A Scaled Floorplan Of The World
Write a Comment
User Comments (0)
About PowerShow.com