electrical and computer engineering dept
Post on 30-Dec-2015
26 Views
Preview:
DESCRIPTION
TRANSCRIPT
Electrical and Computer Engineering Dept.
VR PROGRAMMING
System architecture
VR ToolkitsVR Toolkits
VR Programming ToolkitsVR Programming Toolkits Are extensible libraries of object-oriented functions designed to help the VR developer; Support various common i/o devices used in VR (so drivers need not be written by the developer); Allow import of CAD models (saves time), editing of shapes, specifying object hierarchies, collision detection and multi-level of detail, shading and texturing, run-time management; Have built-in networking functions for multi-user interactions, etc.
VR Toolkits can be classified by:VR Toolkits can be classified by: Whether text-based or graphical-programming; The type of language used and the library size; The type of i/o devices supported; The type of rendering supported; Whether general-purpose or application specific; Whether proprietary (more functionality, better documented) or public domain (free, but less documentation and functionality)
VR Toolkits in Early ‘90sVR Toolkits in Early ‘90s RenderWare (Cannon), VRT3/Superscape (Dimension Ltd.), Cyberspace Developer Kit (Autodesk), Cosmo Authoring Tool (SGI/Platinum/CA), Rend386 and others; They allowed either text-based programming (RenderWare, CDK and Rend386), or graphical programming (Superscape and Cosmo); They were platform-independent and generally did not require graphics acceleration hardware; As a result they tended to use “low-end” I/o devices (mouse) and to support flat shading to maintain fast rendering.
Rend386 sceneRend386 scene
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in C
Programming in Java
19 packages, 275 classes
Vizard Toolkit and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
The scene graph:The scene graph: Is a hierarchical organization of objects (visible or not) in the virtual world (or “universe”) together with the view to that world; Scene graphs are represented by a tree structure, with nodes connected by branches. Visible objects are represented by external nodes, which are called leafs (they have no children). Example nodes F, G, H, I Internal nodes represent transformations (which apply to all their children)
A
B C
ED J
F G H I
Root nodeRoot node
Internal nodeInternal node
External nodeExternal node
palmpalm
SceneScene
BallBall
Scene graph shows that the ball is a child of “scene”
Scene graphs are not static
palmpalm
SceneScene
BallBall
Scene graph has been modified, such that the ball is now a child of the palm
VC 6.1 on book CD
Authoring Authoring (Modeling) (Modeling) StagesStages
Model GeometryModel Geometry
Define and link Define and link sensorssensors
Define action Define action functionsfunctions
Define scene graphDefine scene graph
Define networkingDefine networking
Run-time loopRun-time loop
Start SimulationStart Simulation
Update ObjectsUpdate Objects(from sensors and (from sensors and intelligent actionsintelligent actions
Render sceneRender scene(graphics, audio, (graphics, audio,
haptics)haptics)
Read Sensor DataRead Sensor Data
Exit SimulationExit Simulation
Rep
eats
eve
ry f
ram
eR
epea
ts e
very
fra
me
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in C
Programming in Java
19 packages, 275 classes
Vizard and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
Java and Java 3DJava and Java 3D Java
object oriented programming language developed for network applications platform independence slower than C/C++
Java 3D Java hierarchy of classes that serves as an interface to 3D graphics rendering and sound rendering systems Perfectly integrated with Java Strong object oriented architecture Powerful 3D graphics API
Java 3D Java 3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Define behaviorsDefine behaviors
Define scene graphDefine scene graph
NetworkingNetworking
Java 3D Java 3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Define behaviorsDefine behaviors
Define scene graphDefine scene graph
NetworkingNetworking
Java 3D geometry:Java 3D geometry: Geometry can be imported from various file formats (e.g. 3DS, DXF, LWS, NFF, OBJ, VRT, VTK, WRL) Can be created as a primitive geometry (e.g. sphere, cone, cylinder, …) Custom geometry created by specifying the vertices, edges, normals, texture coordinates using specially defined classes
Imported geometryImported geometryloader.load(“Hand.wrl")loader.load(“Hand.wrl")
Geometry primitive:Geometry primitive:new Sphere(radius)new Sphere(radius)
Custom geometry:Custom geometry:new GeometryArray(…)new GeometryArray(…)new LineArray(…)new LineArray(…)new QuadArray(…)new QuadArray(…)new TriangleArray(…)new TriangleArray(…)
Java 3D object Java 3D object appearance:appearance: The appearance of a geometry is specified using an appearance object An appearance-class object stores information about the material (diffuse, specular, shininess, opacity, …) and texture
Mat = new Material();Mat.setDiffuseColor(r, g, b);Mat.setAmbientColor(r, g, b);Mat.setSpecularColor(r, g, b);
TexLd = new TextureLoader(“checkered.jpg”, ...);Tex = TexLd.getTexture();
Appr = new Appearance();Appr.setMaterial(Mat);Appr.setTexture(Text);
Geom.setAppearance(Appr)
Java 3D Java 3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Define behaviorsDefine behaviors
Define scene graphDefine scene graph
NetworkingNetworking
Java3D node types:Java3D node types:
Node
Group
Leaf
BranchGroup
TransformGroup
Switch
Background
Behavior
Fog
Light
Shape3D
Compilable sub-graph
Transform + child nodes
Select which of the children are visible (useful for LOD)
Universe background. Can be a color or an image
Actions to be performed by the simulation
Fog node
Light node. Special derived classes: AmbientLight, PointLight, DirectionalLight
Geometry + Appearance + BoundingBox
Java3D scene graphJava3D scene graph
Node
Loading objects from filesLoading objects from files
Java3D offers by default support for Lightwave and Wavefront model files Loaders for other file formats can be downloaded for free from the web http://www.j3d.org/utilities/loaders.html Loaders add the content of the read file to the scene graph as a single object. However, they provide functions to access the subparts individually
Universe Universe RootRoot
CubeCube SphereSphere HandHand
ThumbThumb IndexIndex MiddleMiddle RingRing SmallSmall
Scene Sc = loader.load(“Hand.wrl”);BranchGroup Bg = Sc.getSceneGroup();RootNode.addChild(Bg);
Java3D model loadingJava3D model loading
Scene Sc = loader.load(“Hand.wrl”);BranchGroup Bg = Sc.getSceneGroup();Thumb = Bg.getChild(0);Index = Bg.getChild(1);Middle = Bg.getChild(2);Ring = Bg.getChild(3);Small = Bg.getChild(4);
Adding the model to the scene graph
Accessing subparts of the loaded model
Palm = loader.load("Palm.wrl").getSceneGroup();ThumbProximal = loader.load("ThumbProximal.wrl").getSceneGroup();ThumbDistal = loader.load("ThumbDistal.wrl").getSceneGroup();IndexProximal = loader.load("IndexProximal.wrl").getSceneGroup();IndexMiddle = loader.load("IndexMiddle.wrl").getSceneGroup();IndexDistal = loader.load("IndexDistal.wrl").getSceneGroup();MiddleProximal = loader.load("MiddleProximal.wrl").getSceneGroup();MiddleMiddle = loader.load("MiddleMiddle.wrl").getSceneGroup();MiddleDistal = loader.load("MiddleDistal.wrl").getSceneGroup();RingProximal = loader.load("RingProximal.wrl").getSceneGroup();RingMiddle = loader.load("RingMiddle.wrl").getSceneGroup();RingDistal = loader.load("RingDistal.wrl").getSceneGroup();SmallProximal = loader.load("SmallProximal.wrl").getSceneGroup();SmallMiddle = loader.load("SmallMiddle.wrl").getSceneGroup();SmallDistal = loader.load("SmallDistal.wrl").getSceneGroup();
Java3D virtual hand loading:Java3D virtual hand loading:
Java3D virtual hand hierarchy:Java3D virtual hand hierarchy:
Palm.addchild(ThumbProximal );Palm.addchild(ThumbProximal );ThumbProximal .addchild(ThumbDistal );ThumbProximal .addchild(ThumbDistal );
Palm.addchild(IndexProximal );Palm.addchild(IndexProximal );IndexProximal .addchild(IndexMiddle );IndexProximal .addchild(IndexMiddle );IndexMiddle .addchild(IndexDistal );IndexMiddle .addchild(IndexDistal );
Palm.addchild(MiddleProximal );Palm.addchild(MiddleProximal );MiddleProximal .addchild(MiddleMiddle );MiddleProximal .addchild(MiddleMiddle );MiddleMiddle .addchild(MiddleDistal );MiddleMiddle .addchild(MiddleDistal );
Palm.addchild(RingProximal );Palm.addchild(RingProximal );RingProximal .addchild(RingMiddle );RingProximal .addchild(RingMiddle );RingMiddle .addchild(RingDistal );RingMiddle .addchild(RingDistal );
Palm.addchild(SmallProximal );Palm.addchild(SmallProximal );SmallProximal .addchild(SmallMiddle );SmallProximal .addchild(SmallMiddle );SmallMiddle .addchild(SmallDistal );SmallMiddle .addchild(SmallDistal );
Java3D Java3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Define behaviorsDefine behaviors
Define scene graphDefine scene graph
NetworkingNetworking
Input devices in Java3DInput devices in Java3D
The only input devices supported by Java3D are the mouse and the keyboard The integration of the input devices currently used in VR applications (position sensors, track balls, joysticks, sensing gloves…) relies entirely on the developer Usually the drivers are written in C/C++. One needs either to re-write the driver using Java or use JNI (Java Native Interface) to call the C/C++ version of the driver. The latter solution is more desirable. Java3D provides a nice general purpose input device interface that can be used to integrate sensors. However, many times developers prefer custom made approaches
Java3D General purpose sensor interfaceJava3D General purpose sensor interfaceclass PhysicalEnvironment - stores information about all the input devices and sensors involved in the simulation
class InputDevice - interface for an input device driver
class Sensor - class for objects that provide real time data
PhysicalEnvironment
InputDevices Sensors
One input device can provide one or more sensorsOne input device can provide one or more sensors
A sensors object needs not be in relation with an input device (VRML style sensors)A sensors object needs not be in relation with an input device (VRML style sensors)
Java3D Java3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Animating the sceneAnimating the scene
Define scene graphDefine scene graph
NetworkingNetworking
Java3D - Animating the simulationJava3D - Animating the simulation
Java3D offers Behavior objects for controlling the simulation A Behavior object contains a set of actions performed when the object receives a stimulus A stimulus is sent by a WakeupCondition object Some wakeup classes:
WakeupOnCollisionEntryWakeupOnCollisionExitWakeupOnCollisionMovementWakeupOnElapsedFramesWakeupOnElapsedTimeWakeupOnSensorEntryWakeupOnSensorExitWakeupOnViewPlatformEntryWakeupOnViewPlatformExit
Java3D - Behavior usageJava3D - Behavior usage
WakeupOnElapsedFrames Wup = new WakeupOnElapsedFrames(0);WakeupOnElapsedFrames Wup = new WakeupOnElapsedFrames(0);
Bhv.wakeupOn(Wup);Bhv.wakeupOn(Wup);
Universe Universe RootRoot
• We define a behavior We define a behavior Bhv Bhv that rotates the that rotates the sphere by 1 degreesphere by 1 degree
• We want this behavior to be called each We want this behavior to be called each frame so that the sphere will be spinningframe so that the sphere will be spinning
VC 6.3 on book CD VC 6.4 on book CD
The Java 3D View object describes the graphics display used in the simulation, as well as the user’s position versus that display (given by the tracker);
The View model provides a separation between the virtual world provided by the ViewPlatform node and the real I/O devices used in the interaction; This separation helps portability.
Several users that are tracked can be mapped to the same location in the virtual world. This corresponds to several Views and a single ViewPlatform;
Conversely, a single user can control several ViewPlatforms;
This corresponds to several Views since each ViewPlatform has its own View; Thus a single user can have several Views to a virtual world, and can “teleport” between them. Thus a single user can have several Views to a virtual world, and can “teleport” between them.
View platform 1View platform 1View platform 2View platform 2
Java3D Java3D InitiationInitiation
Model GeometryModel Geometry
Setup sensorsSetup sensors
Define behaviorsDefine behaviors
Define scene graphDefine scene graph
NetworkingNetworking
Java3D Java3D simulationsimulation
Java Java ApplicationApplication
Java3D Java3D simulationsimulation
Java Java AppletApplet
Java3D Java3D simulationsimulation
Java Java ApplicationApplication
Java3D - NetworkingJava3D - Networking Java3D does not provide a built-in solution for networked virtual environments However, it’s perfect integration in the Java language allows the developer to use the powerful network features offered by Java Java3D applications can run as stand alone applications or as applets in a web browser
Java3D Java3D simulationsimulation
Java Java AppletApplet
Server
Java3D and VRMLJava3D and VRML
VRML provides possibilities for defining the objects and animating the objects in a virtual world Graphics APIs such as Java3D or WTK load from a VRML file only the static information, ignoring the sensors, routes, scripts, etc. Java3D structure is general enough to make the import of sensors and routes possible but currently we are not aware of any loader that does it One of the most popular library of Java3D loaders is the NCSA Portfolio (http://www.ncsa.uiuc.edu/~srp/Java3D/portfolio/)
NCSA PortfolioNCSA Portfolio
Offers loaders for several model files
3D Studio (3DS) TrueSpace COB loader (COB) Java 3D Digital Elevation Map (DEM) AutoCAD (DXF ) Imagine (IOB) Lightwave (LWS) Sense8 (NFF ) Wavefront (OBJ) Protein Data Bank (PDB) Visualization Toolkit (VTK) VRML97
Loades the following parts of VRML97 files
Appearance Box Coordinate Collision (for grouping only) Group IndexedFaceSet IndexedLineSet Material Normal Shape Sphere Transform
Java3D on-line resources
http://java.sun.com/products/java-media/3D/index.html http://www.j3d.org http://www.ncsa.uiuc.edu/~srp/Java3D/portfolio/
Comparison between Java3D and WTKComparison between Java3D and WTK
A comparative study was done at Rutgers between Java3d (Version 1.3beta 1) and WTK (Release 9); The simulation ran on a dual Pentium III 933 MHz PC (Dell) with 512 Mbytes RAM, with an Wildcat 4110 graphics accelerator which had 64 Mbytes RAM; The I/o interfaces were a Polhemus Insidetrack or the Rutgers Master II force feedback glove; The scene consisted of several 420-polygon spheres and a virtual hand with 2,270 polygons; The spheres rotated constantly around an arbitrary axis, while the hand was either rotating, or driven by the user.
Java3D –WTK ComparisonGraphics scene used in experimentsGraphics scene used in experiments
Comparison between Java3D and WTKComparison between Java3D and WTK
The simulation variables used to judged performance were: graphic mode (monoscopic, stereoscopic), rendering mode (wireframe, Gouraud, textured); scene complexity (number of polygons 5,000 – 50,000); lighting (number of light sources 1, 5, 10); interactivity (no interaction, hand input, force feedback)
Java3D –WTK Comparison
Java3d is faster on average than WTK, but has higher variability
Java3D –WTK Comparison
Java3d Release 3.1 Beta 1 has less system latencies than WTK Release 9
But Java3d has more variability in the scene rendering time
WTK does not have spikes in the scene rendering time
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in CImplemented in C
Programming in JavaProgramming in Java
19 packages, 275 classes19 packages, 275 classes
Vizard and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
Vizard characteristics:Vizard characteristics: Uses Python which is a scalable and cross-platform; It is object-oriented and simple to integrate with C/C++ It runs on Unix, Windows, Mac and other platforms; Uses a 4-window “workbench” which allows programmers to write and execute code, inspect 3D models, drag-and-drop objects, and issue commands while the scene is being rendered.
Stack of scripts – errors are highlighted as you type
Interactive window – input commands
Resource window – Text list of word assets
3D window – Explore individualobjects
Workbench use:Workbench use:Icon menu
Scene exploration with the mouse
Importing objects
import vizimport handviz.go()#Identify the 5DT glove's port.PORT_5DT_USB = 0
#Add the 5DT sensorsensor = viz.add('5dt.dls')
#Create a hand object from the data gloveglove = hand.add(sensor,hand.GLOVE_5DT)
#Place the hand in front of the userglove.translate(0,1,5)glove.rotate(180,-90,180) # now when you run the script the glove should be moving
Vizard virtual hand:Vizard virtual hand:
import vizviz.go()
logo = viz.add('logo.wrl') #add vizard logo and place it in front of userlogo.translate(0,2,4)
tex1 = viz.add('gb_noise.jpg') #add two textures that will then be applied to the logo#tex2 = viz.add('brick.jpg')logo.texture(tex1) #applies the first texturelogo.texture(tex2,'',1) #applies the second texture to the logoblend = viz.add('multitexblend.fp') #indicate how to blend the two textureslogo.apply(blend)
Vizard multi-texturing:Vizard multi-texturing:
Vizard Simulation Servers:Vizard Simulation Servers: More than one user can inhabit the same environment. Each user needs to run Vizard. After the world is set up, each user has to set up two “mail boxes”. One receives information from the other user after it was given network name. Messages come in sequence [0] who sent it, [1] what is sent, [2] and larger the actual data
User 2User 2User 1User 1
Position is the propertyPosition is the property
Ball is the objectBall is the object
action
information
Vizard networking example:Vizard networking example:Import vizViz.go()Ball=viz.add(‘ball.wrl’) #create a Ball object that is controlled by the other user #add the world that will be displayed on your computer #Use a prompt to ask the other user the network name of his computer.target_machine = viz.input('Enter the name of the other machine'). upper()
#Add a mailbox from which to send messages to the other user. This is your outbox.target_mailbox = viz.add(viz.NETWORK, target_machine) #Add an id for the timer.BROADCAST = 1
#Add the timer.def mytimer(num): if num == BROADCAST: #Retrieve your current position. position = viz.get(viz.HEAD_POS) #Send the data to the target mailbox. All the recipient will get your yaw, x and z coordinates. target_mailbox.send(position[0], position[1], position[2])
Vizard networking example:Vizard networking example:
##This function will deal with incoming messages.def mynetwork(message): #message[0] is who sent the message, message[1] is a description of what he #sent and message[2] and greater are the messages themselves. x = message[2] y = message[3] z = message[4] ball.translate(x,y,z)
# Callback the network function to await incoming messages.viz.callback(viz.NETWORK_EVENT, mynetwork)# Callback the timer. viz.callback(viz.TIMER_EVENT, mytimer)# Start the timer.viz.starttimer(BROADCAST, 0.01, -1)
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in CImplemented in C
Programming in JavaProgramming in Java
19 packages, 275 classes19 packages, 275 classes
Vizard and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
GHOST Toolkit for the PHANToMGHOST Toolkit for the PHANToM Provides realistic haptic interaction
Provides and intuitive interfaces to haptics
Provides a haptic scene graph aligned with 3D graphics APIs
Provides an extensible environment for extending haptic interaction technologies
Point haptic interaction with PHANTOM
geometry based on user defined force models
Geometry moves dynamically in response to forces
x
y
z(0,0,0)
PHANToM Desktop modelPHANToM Desktop model
GHOST – Application interactionGHOST – Application interaction
x
y
z (0,0,0)
adapted from Ghost SDK Programmer’s Guide (version 3.1)
Application ProcessApplication Process Haptic ProcessHaptic Process
Scene CreationScene Creation
Collision detectionCollision detectionCollision responseCollision response
Haptic State Haptic State UpdateUpdate
Clean-upClean-up
HapticHapticRenderingRendering
HapticHapticServo loopServo loop
30 f
ps
30 f
ps Scene RenderingScene Rendering
1000 Hz1000 Hz
The GHOST haptics scene graphThe GHOST haptics scene graph
x
y
z (0,0,0)
adapted from Ghost SDK Programmer’s Guide (version 3.1)
Application ProcessApplication Process Haptic ProcessHaptic Process
Scene CreationScene Creation
Collision detectionCollision detectionCollision responseCollision response
Haptic State Haptic State UpdateUpdate
Clean-upClean-up
HapticHapticRenderingRendering
HapticHapticServo loopServo loop
30 f
ps
30 f
ps Scene RenderingScene Rendering
1000 Hz1000 Hz
Haptic scene graphHaptic scene graph Provides a structured way to construct a haptic scene, including geometry and dynamics;
is traversed only from top to bottom (unlike WTK);
each node reachable by only one (unique) traversal from the root (a child node has only one parent node)
Each node has its own transform (no separate transform nodes);
cannot use pointers to repeat instances of the same object, since similar objects have different haptic interactions;
Separator nodes to create a hierarchy – Transforms on the Separator affect its sub-tree;
GHOST node classesGHOST node classes
3D supportStatic NodesDynamic NodesUtility Classes
gstBoundedHapticObjgstNode gstTransform gstShape
gstCube
gstSphere
gstCone
gstCylinder
gstTorus
gstTriPolyMeshHaptic
gstPHANToM_SCP
gstBoundary
gstBoundaryCube
gstSeparator gstDynamic gstDial
gstButton
gstSlider
gstPHANToM
gstPHANToMDynamic
gstPHANToMTranslation
gstPHANToMRotation
gstRigidBody
gstForceField
gstConstantForceField
gstPoint gstVector
gstTransformMatrix
gstEffect gstInertiaEffect
gstBuzzEffect
gstConstraint
gstManipulator gstTranslateManip
gstRotateManip
gstScaleManip
gstSpatialObject
gstSpatialPartition
gstPlane
gstTriPolyMeshBase
gstTriPolyBase
gstTriPoly
gstBinTree
gstTriPolyMesh
GHOST nine node classesGHOST nine node classes
GHOST nine node classes (continued)GHOST nine node classes (continued)
GHOST nine node classes (continued)GHOST nine node classes (continued)
Scene graph exampleScene graph example
y
xz
Head
y
xz
Left Shoulder
y
xz
Right Shouldery
xz
Right Elbow
y x
zLeft Elbow
y
xz
Torso
y
xz
Body
Static scene graph – only separators and geometry nodes as leavesStatic scene graph – only separators and geometry nodes as leaves
GHOST code example:GHOST code example: #include <stdlib.h>#include <stdlib.h>#include <gstBasic.h>#include <gstBasic.h>#include <gstSphere.h>#include <gstSphere.h>#include <gstPHANToM.h>#include <gstPHANToM.h>#include <gstSeparator.h>#include <gstSeparator.h>#include <gstScene.h>#include <gstScene.h>
Main()Main()gstScene *scene = new gstScene;gstScene *scene = new gstScene;gstSeparator *root = new gstSeparator;gstSeparator *root = new gstSeparator;gstSphere *sphere = new gstSphere;gstSphere *sphere = new gstSphere;
Sptere -> setRadius(20);Sptere -> setRadius(20);gstPHANToM *phantom = new gstPHANToM (``PHANToM name``);gstPHANToM *phantom = new gstPHANToM (``PHANToM name``);Root -> addChild(phantom);Root -> addChild(phantom);Root-> addChild(sphere);Root-> addChild(sphere);Scene-> setRoot(root);Scene-> setRoot(root);Scene -> startServoLoop();Scene -> startServoLoop();
While(!scene -> getDoneServoLoop()) While(!scene -> getDoneServoLoop()) // end application by calling scene -> stopServoLoop ();// end application by calling scene -> stopServoLoop ();
Force calculation and dynamicsForce calculation and dynamics
x
y
z (0,0,0)
adapted from Ghost SDK Programmer’s Guide (version 3.1)
Application ProcessApplication Process Haptic ProcessHaptic Process
Scene CreationScene Creation
Collision detectionCollision detectionCollision responseCollision response
Haptic State Haptic State UpdateUpdate
Clean-upClean-up
HapticHapticRenderingRendering
HapticHapticServo loopServo loop
30 f
ps
30 f
ps Scene RenderingScene Rendering
1000 Hz1000 Hz
Collision detection and responseCollision detection and response
The scene graph contains at least one representation of the haptic interface through gstPHANToM node. There can be up to four such nodes (four haptic interfaces in one haptic scene)
Collisions are detected between this node and the geometry nodes through the gstShape node that goes from “untouched” to “touched”;
When collision exists, the gstPHANToM_SCP (surface contact point) is added to the scene graph. This node should be added to the scene graph under the same parent as gstPHANToM node.
Collision detection and responseCollision detection and response
Normal ForceNormal Force (depends on spring(depends on springand damper coefficients)and damper coefficients)
Friction ForceFriction Force (depends on static and dynamic (depends on static and dynamic friction coefficients)friction coefficients)
Forces are calculated following collision;
Collision response through dynamic effects (movable nodes, solid body dynamics);
Application informed if needed (user defined).
Dynamic nodesDynamic nodes
The gstDynamic node adds movement ability to the geometry nodes beneath it. A subtree under a gstDynamic node represents one physically dynamic object.
Forces generated by gstPHANToM node colliding with one of the geometries of such object are added to the state of the gstDynamic node
Transformations (rotations, translations) are always applied to the gstDynamic node, not its children;
It has four derived classes gstDial, gstButton, gstSlider and gstRigidBody.
Dynamic nodes (continued)Dynamic nodes (continued) When a gstDynamic node changes state, an event is generated which calls a user-defined callback function.
Example – the application may quit if a gstButton changes state from pressed to released.
gstButton gstButton behavioral examplebehavioral example
Updating the applicationUpdating the application
x
y
z (0,0,0)
adapted from Ghost SDK Programmer’s Guide (version 3.1)
Application ProcessApplication Process Haptic ProcessHaptic Process
Scene CreationScene Creation
Collision detectionCollision detectionCollision responseCollision response
Haptic State Haptic State UpdateUpdate
Clean-upClean-up
HapticHapticRenderingRendering
HapticHapticServo loopServo loop
30 f
ps
30 f
ps Scene RenderingScene Rendering
1000 Hz1000 Hz
Graphics and event callbacksGraphics and event callbacks The user selects which nodes have call-back functions, and what information needs to be sent back to the application;
This way the application calls updateGraphics to have graphics information updated. Nodes that have a graphics call-back defined, and have a new state since the last call to updateGraphics will copy their current state to a defined data structure
Call-backs pass new state information of the haptic scene nodes from GHOST haptics process to the application process;
For example, the user can create a callback for the graphics representation of the position of the gstPHANToM node. This should change to callback of gstPHANToM_SCP after collision, so the user can see the location of the contact point on the object.
Mapping the user to the haptic scene Mapping the user to the haptic scene
Phantom workspacePhantom workspace
User workspaceUser workspace
Camera mapping to PHANToM workspaceCamera mapping to PHANToM workspace
Camera
Phantom workspace
z-axis
Phantom
workspac
e
Camera
Phantom
workspac
e
phantomSepphantomSepTransform M Transform M rotationrotation
phantomSepphantomSepTransform M Transform M cameracamera
phantomSepphantomSepTransform M Transform M zaxisOffsetzaxisOffset
from Ghost SDK Programmer’s Guide (version 3.1)
Scaling camera and PHANToM workspacesScaling camera and PHANToM workspaces
Camera workspaceCamera workspacetoo largetoo large
Camera workspaceCamera workspacetoo smalltoo small
Camera workspace Camera workspace appropriateappropriate
Camera
Phantom workspace
Camera
Phantom workspace
Camera
Phantom workspace
Scaling camera and PHANToM workspacesScaling camera and PHANToM workspaces
Camera
Dxmax Dphantomxmax
The scale factor depends on the distance Dxmax from the focal point to the frustum
The distance Dphantomxmax from the non-scaled PHANTOM workspace center to the side limit must also be determined
The scale factor is then Sfrustum=Dxmax/Dphantomxmax
Scaling camera and PHANToM workspacesScaling camera and PHANToM workspaces
To maintain haptic fidelity, the gstShape node physical properties (compliance and damping) need to be scaled too;
SurfaceKspringnew = SurfaceKspringcurrent/Sfrustum
SurfaceKdampingnew = SurfaceKdampingcurrent/Sfrustum
where SurfaceKspring and SurfaceKdamping are gstShape compliance and damping coefficients.
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in CImplemented in C
Programming in JavaProgramming in Java
19 packages, 275 classes19 packages, 275 classes
Vizard and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
BDI PeopleShop/DI-Guy characteristicsBDI PeopleShop/DI-Guy characteristics Provides a realistic way to simulate human characters in real-time scenes without using tracking suits;
Is a task-level programming environment combined with a menu-based GUI;
Tasks are mapped to pre-defined (stored) joint motions which are interpolated in real time;
Well-suited for Distributed Interactive Simulations (DIS) due to low bandwidth requirements and live reckoning;
Initially designed for the military, now extended to civilian applications, such as accident reenactment, architectural walk-through, driving simulators, police training, etc.
BDI PeopleShop/DI-Guy characteristics - continuedBDI PeopleShop/DI-Guy characteristics - continued
Linkable object library that runs on SGI, Intel PCs, as well as other platforms;
The library has modules for run-time motion engines, graphics display, motion data, 3D graphics models, textures, and network interfaces for DIS;
Runs under OpenGL, Direct3D, Mak Stealth and other packages;
Recommended hardware is Intel > 200MHz, 64 MB Ram, and graphics accelerator (for Open GL, OpenGVS or Direct3D).
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
Define Define sensorssensors
Define Define behaviorbehavior
Define character Define character pathpath
Define networkingDefine networking
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
Define Define sensorssensors
Define Define behaviorbehavior
Define character Define character pathpath
Define networkingDefine networking
PeopleShop Characters PeopleShop Characters
Are articulated polygonal structures with 54 DOF and 11 links;
Vehicles are also treated as characters;
Different types of characters have different acceptable actions;
Each type of character has different user-selectable appearances (ex. Character vehicle can be a tank or a police car, etc.);
Characters are textured to increase realism and reduce polygonal count
Character selectionCharacter selection
Character type determines acceptable actions (menu selectable)
Appearance selectionAppearance selection
Bob_shorts Bob_shorts Joe_blue Joe_blue Bridget_skirt Bridget_skirt Diane_teen Diane_teen
Character appearance (menu selectable)
BDI ToolkitsBDI Toolkits
Character level-of-detail segmentation based on distance to virtual camera improves real-time performance (up to about 100 characters can be in a scene)
38 polygons38 polygons
2500 polygons2500 polygons
Supplemental bdi.DI-Guy-LOD.mpg
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
Define Define sensorssensors
Define Define BehaviorBehavior
Define character Define character pathpath
Define networkingDefine networking
PeopleShop path specificationPeopleShop path specification
PathPath
WaypointWaypoint
SlopeSlopeAdjuster Adjuster
Initial pathInitial path Extended pathExtended path Added waypointAdded waypoint
BDI ToolkitsBDI Toolkits
Action Action beadbead
End End bead bead
Stacked action Stacked action beadsbeads
Last action bead Last action bead
Editing actionsEditing actions
VC 6.6
on book CD
VC 6.5
on book CD
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
DefineDefinesensorssensors
Define Define behaviorbehavior
Define character Define character pathpath
Define networkingDefine networking
BDI ToolkitsBDI ToolkitsSensor boundarySensor boundary
When soldier A enters the sensor volume, the system is notified – this triggers soldier B’s shooting of A
Soldier ASoldier A
Soldier Soldier BB
PeopleShop sensorsPeopleShop sensors
Sensors are user-defined volumes in space that detect when a character enters them
(PeopleShop User’s Manual)
Sensor boundarySensor boundary
Supplemental
bdi.farmhouse.mpg
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
Define Define sensorssensors
Define Define behaviorbehavior
Define character Define character pathpath
Define networkingDefine networking
PeopleShop BehaviorsPeopleShop Behaviors Behaviors can be reflex (based on signals received from sensors); Behaviors can also be specified with decision beads; Decision beads can be placed on the character’s path (colored red); The two parameters characterizing a decision bead are distance and length; Distance specifies how far from the start of the path the decision Bead is placed; Length indicates the distance from the beginning of the decision region that the decision bead is active; Decisions can be converted to script:
BDI ToolkitsBDI ToolkitsDecision clauses (IF/THEN/ELSE)
PeopleShop PeopleShop Run-timeRun-time
PeolpeShop PeolpeShop InitiationInitiation
Interactive TrainingInteractive Training Immersive TrainingImmersive TrainingScenario VisualizationScenario Visualization
User(s)User(s) User(s)User(s)User(s)User(s)
PeopleShop Run-timePeopleShop Run-time
PeolpeShop PeolpeShop InitiationInitiation
Interactive TrainingInteractive Training Immersive TrainingImmersive TrainingScenario VisualizationScenario Visualization
User(s)User(s) User(s)User(s)User(s)User(s)
BDI PeopleShop ToolkitBDI PeopleShop Toolkit
User is interacting in real time with the simulation using a joystick or mouseand menu. Limited control and immersion. Natural speeds should not be
exceeded.(from Koechling et al., 1997)
VC 6.7
PeopleShop PeopleShop Run-timeRun-time
PeolpeShop PeolpeShop InitiationInitiation
Interactive TrainingInteractive Training Immersive TrainingImmersive TrainingScenario VisualizationScenario Visualization
User(s)User(s) User(s)User(s)User(s)User(s)
BDI PeopleShop – Run time modesBDI PeopleShop – Run time modes
User is interacting in real time with the simulation using a trackers and sensors.Control is at the joint level and immersion is increased.
Omni-directional treadmillOmni-directional treadmill
Sensorized weaponSensorized weapon
(BDI, 1997)
PeopleShop PeopleShop InitiationInitiation
Scene GeometryScene Geometry
Define Define sensorssensors
Define Define behaviorbehavior
Define character Define character pathpath
Define networkingDefine networking
PeopleShop Networking PeopleShop Networking
Updating human figures in DIS is much more bandwidth expensive than vehicles;
Vehicles have few degrees of freedom, while a human figures with 40 joints updated at 20 Hz require 800 packets/sec.;
Instead of updating every joint, PeopleShop only updates at the task level (action, position, velocity). It requires about two packets/sec to produce a smooth simulation;
Works well for large number of participants such as in dismounted infantry training.
Uses “live reckoning” vs. dead reckoning used previously for vehicles
BDI ToolkitsBDI ToolkitsClassical DIS using dead reckoningClassical DIS using dead reckoning
(from Koechling et al., 1997)
BDI ToolkitsBDI Toolkits DIS using live reckoning and human-in-the-loopDIS using live reckoning and human-in-the-loop
DI-Guy modelDI-Guy model DI-Guy modelDI-Guy model
Task-level change Task-level change (action, orientation, velocity)(action, orientation, velocity)
(from Koechling et al., 1997)
PeopleShop “Top Gun” PeopleShop “Top Gun” (courtesy Boston Dynamics Inc.)(courtesy Boston Dynamics Inc.)
VR Toolkits discussed in this chapterVR Toolkits discussed in this chapterName Application Proprietary Library size language
Java3D
(Sun Microsystems)
General Purpose no Implemented in CImplemented in C
Programming in JavaProgramming in Java
19 packages, 275 classes19 packages, 275 classes
Vizard and
PeoplePak (WorldViz)
General Purpose
avatar extension
yes OpenGL-based
Python scripting language
GHOST (SensAble Technologies)
Haptics for Phantom
yes C++C++
PeopleShop
(Boston Dynamics)
Military/civilian yes C/C++C/C++
3DGame Studio Game engine yes C++C++
3D Game Studio characteristics3D Game Studio characteristics Provides an easy and fast way to program virtual worlds using the A6 game engine;
Is a a combination of task-level programming environment combined with a menu-based GUI and script programming for more flexibility;
Well-suited for multi-user simulations over LANs and WAN (TCP/IP and UDP);
Initially designed for the games, now extended to VR programming due to its functionality and price (various versions with increasing number of features, up to commercial license of about $500)
3D Game Studio characteristics3D Game Studio characteristics the 3D Engine allows multiple views (multiple virtual cameras) and is built around DirectX 9 graphics pipeline;
light sources are point, spot or directional
optimization is done through culling (Potential Visibility Set and frustrum);
further optimization through geometric LOD and texture detail
surface meshes are deformable, and objects have dynamics
character animations are done through bones (skeletons) and are blended.
3D Game Studio geometry creation3D Game Studio geometry creation
we can import from a large library of models, or a file created with another modeling tool like 3D Studio Max
or objects can be created using the World Editor (WED) 3D editor
3D Game Studio texturing3D Game Studio texturing
bump maps
light maps and multi-texturing (up to 8)
3D Game Studio character animation3D Game Studio character animation
animation can be imported if created in Maya, or characters can be created and animated using the model editor.
Frames are declared in order of action
Physics and Sound enginesPhysics and Sound engines collision detection is done at the polygon level and objects respect physical behavior like gravity, elasticity and friction
Cscript – a simplified version of C++ is used to create physics behavior through special functions, and to do I/O programming (keyboard keys and mouse)
static and dynamic 3D sound sources can be programmed
3D Game 3D Game Studio Studio InitiationInitiation
3D Game Studio Initiation3D Game Studio Initiation
Example of games programmed in 3Dgame StudioExample of games programmed in 3Dgame StudioMore at www.3dgamestudio.com
top related