i
i
i
i
i
i
i
i
532 18. Building on the Basics, Some Projects in VR
// something has changed - may be set in many places
static bChange=FALSE;
// key function - called in response to Windows timer
static void RefreshScene(void){
// indicates if we are already busy !!!!!!
static BOOL bBusy=FALSE;
// indicates if collision detected between L & R tools
static BOOL bToolsHit=FALSE;
// acquire the latest data from the joysticks
UpdateInputState(glWndFrame);
// Move the virtual sculpting tools to mimic the
UpdateRightObject();
// actions of the joysticks.
UpdateLeftObject();
// can’t do anything if we not finished last call
if(bBusy)return;
// flag that we are busy
bBusy=TRUE;
RelaxDeformation(bChange);
// If something has changes e.g. a tool
if(bChange){
// has moved, then apply the algorithm.
// get new positions of tools
UpdateObjectTransformations(FREE);
// check to see if tools hit each other
if(CheckToolIntersections()){
// If they hit and we have force feedback
if(!bToolsHit){
// devices send them a force forcing tools
bToolsHit=TRUE; SendForce(4,0);
// apart.
}
// don’t let tools do the physically impossible
RestoreOldToolPositions();
// do it again!
UpdateObjectTransformations(FREE);
}
// if the tools are now apart - switch of repulsion
else if(bToolsHit){
bToolsHit=FALSE; SendForce(0,1); SendForce(0,2);
}
Listing 18.1. The sculpt programs most vital actions are dispatched from function
RefreshScene(), which has to do the data acquisition, all the collision detection
and simulation of elastic deformation within the available time interval (about 30 to
50 times per second).
i
i
i
i
i
i
i
i
18.8. Virtual Sculpting in 3D 533
// do the collision detection of tool into objects
CheckIntersection();
// apply the spring mass deformation model
UpdateDeformation();
}
if(IsWindow(glWnd))InvalidateRect(glWnd, NULL, FALSE);
bChange=FALSE;
bBusy=FALSE;
return;
}
Listing 18.1. (continued).
because the damper provides a force which is proportional to the velocity of
avertex: F
d
= k
d
(p p)/ t. This force is added to the spring restoration
force in Equation (18.1).
The stability and type of behavior of the simulation is governed by the
choice of values for the coefficients
t, m, k and k
d
.Inthecode,wehave
used experimentally determined values that work quite well. As we men-
tioned before the values we use will govern the stability and convergence of
our simulation but the study of this is well outside the scope of this book.
18.8.3 Implementation
The polygonal mesh models we will use for the elastic surfaces and the sculpt-
ing tools are loaded as part of the program initialization. Rectangular bound-
ing boxes are built around them. These bounding boxes are used so that
collision detection can be done as quickly as possible. That is, a rectangular
box around a sculpting tool is checked for intersection with a rectangular box
around each of the elastic objects. If the boxes intersect then every polygon
in a tool is checked for intersection against every polygon in the object.
As mentioned before, the key steps in the program are initiated from func-
tion
RefreshScene(), which is shown in outline in Listing 18.1. The input
for the two instruments is obtained from two joysticks by using DirectInput.
The mesh models are rendered in real time using OpenGL, which allows for
stereoscopic display.
It only remains to sum up by saying that this has been quite a complex
project in terms of what it set out to achieve. But apart from the mathematical
model for deformation, all of the other elements arise just by the application
of common sense, and most of the coding details, e.g., OpenGL/DirectInput,
have been described before.
i
i
i
i
i
i
i
i
534 18. Building on the Basics, Some Projects in VR
18.9 Summary
Well, this brings us to the end of our projects chapter and indeed to the end
of the book itself. There are many more project ideas we might have followed
up, but as we hope youve seen from these few examples, most of the elements
that such projects would be built on are not that different from those we
explored in detail in Part II. We hope that our book has shown you some
new things, excited your imagination to dream up new ways of u sing VR and
provided some clues and pieces of computer code to help you do just that.
Have fun!
Bibliography
[1] The Augmented Reality Toolkit. http://www.hitl.washington.edu/artoolkit/.
[2] M. Donahoo and K. Calvert. TCP/IPSocketsinC:PracticalGuideforProgram-
mers. San Fransisco, CA: Morgan Kaufmann, 2000.
[3] C. Gerald. Applied Numerical Analysis. Reading, MA: Addison Wesley, 1980.
[4] D. House and D. Breen (Editors). Cloth Modeling and Animation. Natick, MA:
A. K. Peters, 2000.
[5] C. Hunt. TCP/IP Network Administration, Second Edition. Sebastopol, CA:
O’Reilly, 1998.
[6] Intel Corporation. Open Source Computer Vision Library. http://www.intel.com/
technology/computing/opencv/, 2006
[7] Microsoft Corporation. “DirectShow SDK”. http://msdn.microsoft.com/
directx/sdk/, 2006.
[8] M. Pesce. Programming Microsoft DirectShow for Digital Video and Television.
Redmond, WA: Microsoft Press, 2003.
[9] L. Verlet. “Computer Experiments on Classical Fluids”. Physical Review 159
(1967) 98–103.
i
i
i
i
i
i
i
i
Appendices
i
i
i
i
i
i
i
i
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.28.108