Collaborative VR

Download Report

Transcript Collaborative VR

VR Juggler 1.0
Application Programming
Patrick Hartling
Virtual Reality Applications Center
IEEE VR 2002
Objectives
• Learn VR Juggler programming basics
• Be able to write VR Juggler applications
• Please: Ask questions!!!
VR Juggler — www.vrjuggler.org
Overview
•
•
•
•
Application objects
VR Juggler utility classes
Simple VR Juggler application
Advanced OGL application
VR Juggler — www.vrjuggler.org
Online Documentation
• www.vrjuggler.org
• “Projects”
– VR Juggler
–
Documentation
• Guides and
references
VR Juggler — www.vrjuggler.org
Application Objects
vjApp
+init()
+apiInit()
+exit()
+preFrame()
+intraFrame()
+postFrame()
class MyApp : public vjApp
{
void init();
void apiInit();
void exit();
void preFrame();
.
.
.
};
– All VR Juggler applications are objects
– Override methods of a pre-defined interface
–
Derived class for each graphics API
– No main() – “Don’t call me, I’ll call you”
–
Kernel controls application by calling methods
VR Juggler — www.vrjuggler.org
Application Objects
vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
• Application object is
derived from graphics API
specific base class
• User application methods
must “fill-in-the-blank”
vjGlApp
+draw()
+contextInit()
+contextPreDraw()
+...()
myApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+draw()
+contextInit()
+contextPreDraw()
+...()
VR Juggler — www.vrjuggler.org
VR Juggler main()
#include <simpleApp.h>
int main (int argc, char* argv[])
{
// Get kernel
vjKernel* kernel = vjKernel::instance();
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
kernel->setApplication(app); // Give app to kernel
while ( ! exit )
{
// sleep
}
}
VR Juggler — www.vrjuggler.org
• How VR Juggler
“starts-up”
VR Juggler main()
#include <simpleApp.h>
int main (int argc, char* argv[])
{
// Get kernel
vjKernel* kernel = vjKernel::instance();
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
kernel->setApplication(app); // Give app to kernel
while ( ! exit )
{
// sleep
}
}
VR Juggler — www.vrjuggler.org
• Get handle to
kernel
VR Juggler main()
#include <simpleApp.h>
int main (int argc, char* argv[])
{
// Get kernel
vjKernel* kernel = vjKernel::instance();
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
kernel->setApplication(app); // Give app to kernel
while ( ! exit )
{
// sleep
}
}
VR Juggler — www.vrjuggler.org
• Create the
application
– Instance of user’s
application object
VR Juggler main()
#include <simpleApp.h>
int main (int argc, char* argv[])
{
// Get kernel
vjKernel* kernel = vjKernel::instance();
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
kernel->setApplication(app); // Give app to kernel
while ( ! exit )
{
// sleep
}
}
VR Juggler — www.vrjuggler.org
• Give the kernel
initial configuration
files
• Start the kernel
thread
– VR Juggler is now
fully running
VR Juggler main()
#include <simpleApp.h>
int main (int argc, char* argv[])
{
// Get kernel
vjKernel* kernel = vjKernel::instance();
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
kernel->setApplication(app); // Give app to kernel
while ( ! exit )
{
// sleep
}
}
VR Juggler — www.vrjuggler.org
• Give the kernel an
application to run
• Kernel now starts
calling the
application object’s
methods
Application Object Methods
Initialization
• init(): Application initialization
– Ex: Loading data files, lookup tables
vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
• apiInit(): Graphics API specific initialization
– Ex: scene graph loading
Frame functions
vjGlApp
+draw()
+contextInit()
+contextPreDraw()
+...()
• preFrame(): Called at start of frame
– Ex: Updating data in response to device input
myApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+draw()
+contextInit()
+contextPreDraw()
+...()
• intraFrame(): Called while rendering
– Ex: Time consuming computation for next frame
• postFrame(): Called after frame is done
VR Juggler — www.vrjuggler.org
– Ex: Clean up, sync with external net or compute
Application Interface
vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
• Other…
– Reconfiguration
– Reset
– Exit
– Focus change
vjGlApp
+draw()
+contextInit()
+contextPreDraw()
+...()
myApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+draw()
+contextInit()
+contextPreDraw()
+...()
VR Juggler — www.vrjuggler.org
Call Timing
#include <simpleApp.h>
kern
OGLApp
drawMgr
inputMgr
vjKernel
vjGlApp
vjGlDrawManager
vjInputManager
int main (int argc, char* argv[])
/init():void
{
/initAPI():void
// Get kernel
vjKernel* kernel = vjKernel::instance();
/apiInit():void
simpleApp* app = new simpleApp(); // Create app obj
kernel->loadConfigFile(…);
// Configure kernel
kernel->start();
// Start kernel thread
while(running)
/preFrame():void
kernel->setApplication(app); // Give app to kernel
/draw():void
/intraFrame():void
while ( ! exit )
/sync():void
{
/postFrame():void
// sleep
}
/updateAllData():void
}
• setApplication() starts the kernel calling the
application’s member functions
VR Juggler — www.vrjuggler.org
kern
OGLApp
drawMgr
inputMgr
vjKernel
vjGlApp
vjGlDrawManager
vjInputManager
/init():void
/initAPI():void
/apiInit():void
while(running)
/preFrame():void
/draw():void
/intraFrame():void
/sync():void
/postFrame():void
/updateAllData():void
VR Juggler — www.vrjuggler.org
Call timing: Init
members
• init()
– Called after kernel
gets app
• apiInit()
– Called after
graphics API is
running
kern
OGLApp
drawMgr
inputMgr
vjKernel
vjGlApp
vjGlDrawManager
vjInputManager
/init():void
/initAPI():void
/apiInit():void
while(running)
/preFrame():void
Call timing: Frame
members
• preFrame()
– Called after input update
/draw():void
/intraFrame():void
/sync():void
• intraFrame()
– Called while rendering of
environment is happening
• postFrame()
/postFrame():void
/updateAllData():void
VR Juggler — www.vrjuggler.org
– Called after frame but before
tracker updates
vjGlApp: OpenGL
Application Interface
vjApp
• Derived from vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
• OpenGL specific extensions
– draw()
vjGlApp
+draw()
+contextInit()
+contextPreDraw()
+...()
–
–
–
myApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+draw()
+contextInit()
+contextPreDraw()
+...()
VR Juggler — www.vrjuggler.org
Draw the scene in OpenGL
Called for each OpenGL context
Stereo  Called once per eye
– contextInit(),
contextPreDraw(),
contextClose()
–
Discussed later
vjPfApp: Performer
Application Interface
vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
• Derived from vjApp
• Performer specific
extensions
vjPfApp
– initScene()
+initScene()
+getScene()
+...()
–
myPfApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+initScene()
+getScene()
+...()
VR Juggler — www.vrjuggler.org
Create the scene graph
– getScene()
–
Return the root of the scene
graph
Common Classes
Helper classes needed for app
development
• Mathematics: matrix, vector, point
• Input devices
VR Juggler — www.vrjuggler.org
Common Classes: vjMatrix
4x4 matrix
• OpenGL ordering
Methods
• Rotation: makeXYZEuler(), makeRot()
• Translation: makeTrans(), setTrans()
• Multiplication: mult(), preMult(),
postMult()
• Many others… (see Programmer’s Guide)
VR Juggler — www.vrjuggler.org
Common Classes: vjVec3 &
vjVec4
• Class for float vector
• Used for points and rays
• Methods
– +,-,=
– dot(), normalize(), cross()
– Many others… (see Programmer’s Guide)
VR Juggler — www.vrjuggler.org
getProxiedInputDevice
getChunkT ype
Common Classes: vjProxy
0..*
v j PosProxy
v j PosInterface
vjPosInterface
operator->
operator*
refresh
vjPosProxy
~vjPosProxy
updateData
getUpdateT ime
setT ransform
0..1 set
getData
getUnit
getPositionPtr
getT ransform
transformData
getChunkT ype
config
getProxiedInputDevice
vjPosition
vjPosition
~vjPosition
config
0..1 startSampling
stopSampling
sample
updateData
getDeviceName
getPosData
getPosUpdateT ime
• Proxies are used to access all input data
wand_pos = mWandProxy->getData();
• Proxies cache and transform input data
VR Juggler — www.vrjuggler.org
getProxiedInputDevice
getChunkT ype
Common Classes: vjDeviceInterface
0..*
v j PosProxy
v j PosInterface
vjPosInterface
operator->
operator*
refresh
–
–
–
–
vjPosProxy
~vjPosProxy
updateData
getUpdateT ime
setT ransform
0..1 set
getData
getUnit
getPositionPtr
getT ransform
transformData
getChunkT ype
config
getProxiedInputDevice
vjPosition
vjPosition
~vjPosition
config
0..1 startSampling
stopSampling
sample
updateData
getDeviceName
getPosData
getPosUpdateT ime
Used to get access to devices through proxies
Smart pointer to a device proxy
Makes proxies easier to use
init()
mWand.init(“VJWand”);
VR Juggler — www.vrjuggler.org
Common Classes:
vjPosInterface
vjPosInterface
• Used to get positional information.
– Ex. trackers, wand position, head position
• Derived from vjDeviceInterface
• Dereferences to vjPosProxy
– operator*(), operator->()
– Get proxy data with: getData()
vjMatrix* wand_pos;
wand_pos = mWand->getData();
VR Juggler — www.vrjuggler.org
Common Classes:
vjDigitalInterface
vjDigitalInterface
• Used to get digital information (ie. 0 or 1)
– Ex: wand buttons
• getData() returns integer
– States (return value):
–
–
–
–
OFF
ON
TOGGLE_ON: Just switched to on state
TOGGLE_OFF: Just switched to off state
VR Juggler — www.vrjuggler.org
Sample Application 1:
Simple OpenGL Application
simpleApp
VR Juggler — www.vrjuggler.org
Sample Application 1: simpleApp
vjApp
+init()
+apiInit()
+preFrame()
+intraFrame()
+postFrame()
+...()
Simple OpenGL drawing app
• Member function
vjGlApp
+draw()
+contextInit()
+contextPreDraw()
+...()
simpleApp
+init()
+draw()
+contextInit()
+...()
VR Juggler — www.vrjuggler.org
– vjApp::init()
– vjGlApp::draw()
• Files
– simpleApp/simpleApp.h,
simpleApp/simpleApp.cpp
simpleApp: Data Members
class simpleApp: public vjGlApp
• mWand, mHead:
{
public:
simpleApp();
virtual void init();
virtual void draw();
– Position interface to positional
proxy
– Get position
vjMatrix wand_pos;
public:
vjPosInterface mWand;
vjPosInterface mHead;
vjDigitalInterface mButton0;
vjDigitalInterface mButton1;
wand_pos = *(mWand->getData());
• mButton0, mButton1
– Digital interface to digital proxy
if(mButton0->getData())
};
cout << “Button Pressed”;
VR Juggler — www.vrjuggler.org
simpleApp: init()
void simpleApp::init()
{
// Initialize devices
mWand.init(“VJWand”);
mHead.init(“VJHead”);
mButton0.init(“VJButton0”);
mButton1.init(“VJButton1”);
}
VR Juggler — www.vrjuggler.org
• Initialize device
interface
• Device name
– From configuration file
– Name of device alias or
proxy
simpleApp: draw()
void simpleApp::draw()
{
...
// Create box offset matrix
vjMatrix box_offset;
box_offset.makeXYZEuler(-90,0,0);
box_offset.setTrans(0.0,1.0f,0.0f);
...
glPushMatrix();
// Push on offset
glMultMatrixf(box_offset.getFloatPtr());
...
drawCube();
glPopMatrix();
...
}
VR Juggler — www.vrjuggler.org
• Create an offset
matrix
• Draw cube
Sample Application 2:
OpenGL Application with ContextSpecific Data
contextApp
VR Juggler — www.vrjuggler.org
Context-Specific Data
What is a Context?
• OpenGL Window  Context for OGL state
machine
What is context-specific data?
• Display lists, texture objects, etc.
Why do you need it?
• VR Juggler uses a single memory pool for all
threads
– All threads have access to the same variables
• Ex: Multi-wall system
VR Juggler — www.vrjuggler.org
Context-Specific Data
How does it work
• Template-based “smart pointer” class
• Dereference like normal pointer
– ie. operator*(), operator->()
vjGlContextData<GLuint> myDispList;
…
(* myDispList) = glGenList(1);
…
glCallList(*myDispList);
VR Juggler — www.vrjuggler.org
Context App: Data Members
Class contextApp: public vjGlApp
{
public:
contextApp();
virtual void init();
virtual void contextInit();
virtual void draw();
…
public:
// Identifier for the cube display list
vjGlContextData<Gluint> mCubeDlId;
…
};
VR Juggler — www.vrjuggler.org
• Context-specific
data for a display
list that draws a
cube
Context App: contextInit()
void simpleApp::contextInit()
{
// Allocate context specific data
(*mCubeDlId) = glGenLists(1);
glNewList((*mCubeDlId), GL_COMPILE);
glScalef(0.50f, 0.50f, 0.50f);
drawCube();
glEndList();
...
}
VR Juggler — www.vrjuggler.org
• Create display list
• Context-specific
version is used
Context App: draw()
void simpleApp::draw()
{
// Get Wand matrix
vjMatrix wand_matrix;
wand_mat = *(mWand->getData());
...
glPushMatrix();
glPushMatrix();
glMultMatrixf(wand_mat.getFloatPtr());
glCallList(*mCubeDlId);
glPopMatrix();
...
glPopMatrix();
}
VR Juggler — www.vrjuggler.org
• Render display list
• De-reference
context-specific
display list ID
Conclusion
Questions?
VR Juggler — www.vrjuggler.org