Graphics Reference
In-Depth Information
C
S
P
click!
Figure 11.11: When the user clicks near the lower-right corner of the display, we can
recover the 3-space coordinates of a corresponding point S of the imaging plane in 3-space;
we'll use this to determine where a ray from the eye through this point hits the virtual
sphere.
To determine the point P corresponding to this click, we ask where the ray
parameterized by
R ( t )= C + t ( S
C )
(11.46)
meets the virtual sphere, which we'll assume, for simplicity, is the unit sphere
defined by x 2 + y 2 + z 2 = 1. In other words, the unit sphere, if displayed, would
just touch two sides of our display rectangle. For the point R ( t ) to lie on the sphere,
its coordinates (which we'll call r x , r y , and r z ) must satisfy the defining equation
of the sphere, that is,
r x + r y + r z = 1.
(11.47)
Alternatively, we can consider the vector from the origin O to R ( t ) , that is, C +
t ( S
C )
O ; this vector must have unit length, which means it must satisfy
( R ( t )
O )
·
( R ( t )
O )= 1. Letting u denote S
C , this becomes
( C
O + t u )
·
( C
O + t u )= 1,
(11.48)
which we can simplify and expand; letting c = C
O , we get
u ) t 2 +( 2 c
( u
·
·
u ) t + c
·
c = 1,
(11.49)
which is a quadratic in t ; we solve to get
( c
t =
c
·
u
±
·
u ) 2
( u
·
u )( c
·
c )
.
(11.50)
u
·
u
The smaller t value—call it t 1 —corresponds to the first intersection of the ray with
the sphere; using this, we can compute the sphere point
P = C + t 1 ( S
C ) .
(11.51)
(It's possible that both solutions for t are not real numbers, in which case the ray
does not intersect the sphere: The user did not click on the image of the virtual
sphere on the display.)
As the user drags the mouse, we can, at each instant, compute the correspond-
ing sphere point Q in the same way. From P and Q , we compute a rotation of the
 
Search WWH ::




Custom Search