Presentation is loading. Please wait.

Presentation is loading. Please wait.

VR Juggler 1.0 Application Programming Patrick Hartling Virtual Reality Applications Center IEEE VR 2002.

Similar presentations


Presentation on theme: "VR Juggler 1.0 Application Programming Patrick Hartling Virtual Reality Applications Center IEEE VR 2002."— Presentation transcript:

1 VR Juggler 1.0 Application Programming Patrick Hartling Virtual Reality Applications Center IEEE VR 2002

2 VR Juggler Objectives Learn VR Juggler programming basicsLearn VR Juggler programming basics Be able to write VR Juggler applicationsBe able to write VR Juggler applications Please: Ask questions!!!Please: Ask questions!!!

3 VR Juggler Overview Application objectsApplication objects VR Juggler utility classesVR Juggler utility classes Simple VR Juggler applicationSimple VR Juggler application Advanced OGL applicationAdvanced OGL application

4 VR Juggler Online Documentation ProjectsProjects –VR Juggler – Documentation Guides and referencesGuides and references

5 VR Juggler Application Objects –All VR Juggler applications are objects –Override methods of a pre-defined interface – Derived class for each graphics API –No main() – Dont call me, Ill call you – Kernel controls application by calling methods

6 VR Juggler Application Objects Application object is derived from graphics API specific base classApplication object is derived from graphics API specific base class User application methods must fill-in-the-blankUser application methods must fill-in-the-blank

7 VR Juggler #include 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 main() How VR Juggler starts-upHow VR Juggler starts-up

8 VR Juggler #include 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 main() Get handle to kernelGet handle to kernel

9 VR Juggler #include 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 main() Create the applicationCreate the application –Instance of users application object

10 VR Juggler #include 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 main() Give the kernel initial configuration filesGive the kernel initial configuration files Start the kernel threadStart the kernel thread –VR Juggler is now fully running

11 VR Juggler #include 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 main() Give the kernel an application to runGive the kernel an application to run Kernel now starts calling the application objects methodsKernel now starts calling the application objects methods

12 VR Juggler Application Object Methods Initialization init() : Application initializationinit() : Application initialization –Ex: Loading data files, lookup tables apiInit() : Graphics API specific initializationapiInit() : Graphics API specific initialization –Ex: scene graph loading Frame functions preFrame() : Called at start of framepreFrame() : Called at start of frame –Ex: Updating data in response to device input intraFrame() : Called while renderingintraFrame() : Called while rendering –Ex: Time consuming computation for next frame postFrame() : Called after frame is donepostFrame() : Called after frame is done –Ex: Clean up, sync with external net or compute

13 VR Juggler Application Interface Other…Other… –Reconfiguration –Reset –Exit –Focus change

14 VR Juggler #include 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 } } Call Timing setApplication() starts the kernel calling the applications member functionssetApplication() starts the kernel calling the applications member functions

15 VR Juggler Call timing: Init members init()init() –Called after kernel gets app apiInit()apiInit() –Called after graphics API is running

16 VR Juggler Call timing: Frame members preFrame()preFrame() –Called after input update intraFrame()intraFrame() –Called while rendering of environment is happening postFrame()postFrame() –Called after frame but before tracker updates

17 VR Juggler vjGlApp : OpenGL Application Interface Derived from vjAppDerived from vjApp OpenGL specific extensionsOpenGL specific extensions – draw() – Draw the scene in OpenGL – Called for each OpenGL context – Stereo Called once per eye – contextInit(), contextPreDraw(), contextClose() – Discussed later

18 VR Juggler vjPfApp : Performer Application Interface Derived from vjAppDerived from vjApp Performer specific extensionsPerformer specific extensions – initScene() – Create the scene graph – getScene() – Return the root of the scene graph

19 VR Juggler Common Classes Helper classes needed for app development Mathematics: matrix, vector, pointMathematics: matrix, vector, point Input devicesInput devices

20 VR Juggler Common Classes: vjMatrix 4x4 matrix OpenGL orderingOpenGL orderingMethods Rotation: makeXYZEuler(), makeRot()Rotation: makeXYZEuler(), makeRot() Translation: makeTrans(), setTrans()Translation: makeTrans(), setTrans() Multiplication: mult(), preMult(), postMult()Multiplication: mult(), preMult(), postMult() Many others… (see Programmers Guide)Many others… (see Programmers Guide)

21 VR Juggler Common Classes: vjVec3 & vjVec4 Class for float vectorClass for float vector Used for points and raysUsed for points and rays MethodsMethods –+,-,= – dot(), normalize(), cross() –Many others… (see Programmers Guide)

22 VR Juggler Common Classes: vjProxy Proxies are used to access all input dataProxies are used to access all input data wand_pos = mWandProxy->getData(); Proxies cache and transform input dataProxies cache and transform input data

23 VR Juggler Common Classes: vjDeviceInterface –Used to get access to devices through proxies –Smart pointer to a device proxy –Makes proxies easier to use – init() mWand.init(VJWand);

24 VR Juggler Common Classes: vjPosInterface vjPosInterface Used to get positional information.Used to get positional information. –Ex. trackers, wand position, head position Derived from vjDeviceInterfaceDerived from vjDeviceInterface Dereferences to vjPosProxyDereferences to vjPosProxy – operator*(), operator->() –Get proxy data with: getData() vjMatrix* wand_pos; wand_pos = mWand->getData();

25 VR Juggler Common Classes: vjDigitalInterface vjDigitalInterface Used to get digital information (ie. 0 or 1)Used to get digital information (ie. 0 or 1) –Ex: wand buttons getData() returns integergetData() returns integer –States (return value): – OFF – ON – TOGGLE_ON: Just switched to on state – TOGGLE_OFF: Just switched to off state

26 VR Juggler Sample Application 1: Simple OpenGL Application simpleApp

27 VR Juggler Sample Application 1: simpleApp Simple OpenGL drawing app Member functionMember function – vjApp::init() – vjGlApp::draw() FilesFiles – simpleApp/simpleApp.h, simpleApp/simpleApp.cpp

28 VR Juggler class simpleApp: public vjGlApp { public: simpleApp(); virtual void init(); virtual void draw(); public: vjPosInterface mWand; vjPosInterface mHead; vjDigitalInterface mButton0; vjDigitalInterface mButton1; }; simpleApp: Data Members mWand, mHead :mWand, mHead : –Position interface to positional proxy –Get position vjMatrix wand_pos; wand_pos = *(mWand->getData()); mButton0, mButton1mButton0, mButton1 –Digital interface to digital proxy if(mButton0->getData()) cout << Button Pressed; cout << Button Pressed;

29 VR Juggler simpleApp: init() Initialize device interfaceInitialize device interface Device nameDevice name –From configuration file –Name of device alias or proxy void simpleApp::init() { // Initialize devices mWand.init(VJWand); mHead.init(VJHead); mButton0.init(VJButton0); mButton1.init(VJButton1); }

30 VR Juggler 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();... } simpleApp: draw() Create an offset matrixCreate an offset matrix Draw cubeDraw cube

31 VR Juggler Sample Application 2: OpenGL Application with Context- Specific Data contextApp

32 VR Juggler Context-Specific Data What is a Context? OpenGL Window Context for OGL state machineOpenGL Window Context for OGL state machine What is context-specific data? Display lists, texture objects, etc.Display lists, texture objects, etc. Why do you need it? VR Juggler uses a single memory pool for all threadsVR Juggler uses a single memory pool for all threads –All threads have access to the same variables Ex: Multi-wall systemEx: Multi-wall system

33 VR Juggler Context-Specific Data How does it work Template-based smart pointer classTemplate-based smart pointer class Dereference like normal pointerDereference like normal pointer –ie. operator*(), operator->() vjGlContextData myDispList; … (* myDispList) = glGenList(1); …glCallList(*myDispList);

34 VR Juggler Class contextApp: public vjGlApp { public: contextApp(); virtual void init(); virtual void contextInit(); virtual void draw(); … public: // Identifier for the cube display list vjGlContextData mCubeDlId; … }; Context App: Data Members Context-specific data for a display list that draws a cubeContext-specific data for a display list that draws a cube

35 VR Juggler Context App: contextInit() Create display listCreate display list Context-specific version is usedContext-specific version is used void simpleApp::contextInit() { // Allocate context specific data (*mCubeDlId) = glGenLists(1); glNewList((*mCubeDlId), GL_COMPILE); glScalef(0.50f, 0.50f, 0.50f); drawCube(); glEndList();... }

36 VR Juggler Context App: draw() Render display listRender display list De-reference context-specific display list IDDe-reference context-specific display list ID void simpleApp::draw() { // Get Wand matrix vjMatrix wand_matrix; wand_mat = *(mWand->getData());... glPushMatrix(); glMultMatrixf(wand_mat.getFloatPtr()); glCallList(*mCubeDlId); glPopMatrix();... glPopMatrix(); }

37 VR Juggler Conclusion Questions?


Download ppt "VR Juggler 1.0 Application Programming Patrick Hartling Virtual Reality Applications Center IEEE VR 2002."

Similar presentations


Ads by Google