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.