Creating Virtual Reality Applications Using FreeVR David J. Zielinski djzielin@duke.edu Friday Visualization Forum October 1st,2004 Overview 1) What is Virtual Reality? 2) What are my choices? 3) Why use FreeVR? 4) FreeVR program outline 5) Application demos 1) What is Virtual Reality? What is Virtual Reality? ● ● Physically immersive (generate input to user's sensory systems) Interactive (user can change the experience) Examples: reading a book (not interactive or immersive) video game (interactive but not immersive) 3-d movie (immersive but not interactive) What can we use for physically immersive? ● 3-d vision – projection systems: [anaglyphic (red/blue), polarized, active stereo] – head mounted displays. What can we use for physically immersive? ● 3-d sound – multichannel – Headphone speaker setups simulation What can we use for physically immersive? ● Other: – Touch/force feedback – Taste – Smell – Environmental conditions (temperature) – Accelerations/motion – Direct connection to human nervous What can we use for interactive? • location tracking systems: magnetic, video, ultra-sonic What can we use for interactive? • joysticks: wands, game controllers • other: gloves, eye tracking, biological indicators (heart-rate, breathing), props (steering wheels, fishing poles) 2) What are my choices for developing an application/experience? A) Write from scratch B) Low-level library C) Medium-level library (scenegraph) D) High-level graphical program E) Use domain-specific, off the shelf program Write from scratch ● Pro: – complete control – maximum performance/speed possible ● Con: – Long, difficult development – Often device dependent Low-level library (CAVELib, FreeVR, DIVERSE) ● Pro: – lots of control (C/C++,OpenGL programming) – device ● independent Con: – difficult – more for non-programmers, control/freedom than most applications require Medium-level library (OpenSceneGraph, Performer) Medium-level library (OpenSceneGraph, Performer) ● Pro: – built in algorithms to cull (eliminate) non-viewable objects – built in algorithms for collision detection ● Con: – Still lots of programming – learning curve to use scenegraph High-level graphical program (Virtools) High-level graphical program (Virtools) ● Pro: – Easy visual design of worlds – Visual, flow design for object behaviors ● Con: – Expensive – speed/performance? – Still have to learn to “program” Use domain-specific, off the shelf program (Amira, VMD) Use domain-specific, off the shelf program (Amira, VMD) ● Pro: – Very easy, especially if group is already using non-VR version of program ● Con: – Individual – not configuration applicable to making custom applications 3) Why use FreeVR? ● device independence (input and output) ● free/opensource (CAVELib is not) ● ● actively developed (cluster support soon) I know how to configure it How does it become device independent? ● ● configuration file (.freevrrc) maps buttons, sensors, and screen locations to FreeVR internals. Different physical configurations require different .rc settings. on startup FreeVR opens all necessary windows, and handles projection matrices, so correct view is on correct screen. abstraction of buttons: int pressed=vrGet2switchValue(which_button) ; if(pressed) printf(“user pressed the button!”); abstraction of location sensors: vrPointGetRWFrom6sensor(&wand_locpnt, WAND_SENSOR); float x,y,z; x=wand_locpnt.v[0]; y=wand_locpnt.v[1]; z=wand_locpnt.v[2]; if((x<...) AND (y<...) AND (z<...)) /* we are touching an object, do something */ abstraction of display space: we provide single function, that is called for each frame, for each render window. void draw_world() { clear_screen glTranslatef(0,5,-5); /* real world coordinates draw_object } 4) FreeVR program Outline pt.1 Main(){ initialization calls setup callback of world render function setup callback of gfx initialization while(!terminate){ vrFrame(); update(); /* next slide */ } } FreeVR program Outline pt.2 Update(){ check buttons check sensor positions do logic } draw_world(){ look at world settings (modified in update) make openGL calls to render world } FreeVR programming Subtleties ● ● Rendering and updates occur in separate processes, so shared memory is needed. FreeVR includes vrShmemAlloc0 which is comparable to malloc. Typically a world data structure is created, modified, and passed around. because of the separate processes we need to lock the world data when we are writing and reading it. FreeVR includes vrLock. We can call vrLockReadSet(the_lock); vrLockReadRelease(the_lock); 5) Applications –PDB viewer Virtual Vibraphone FreeVR Download http://www.freevr.org/ David J. Zielinski djzielin@duke.edu