Game Development Reference
In-Depth Information
Objectives
To learn how to implement the picking algorithm and understand
how it works. We break picking down into the following four steps:
Given the clicked screen point s , find its corresponding point
on the projection window, namely p .
Compute the picking ray, that is, the ray originating at the ori-
gin that shoots through p .
Transform the picking ray and the models into the same space.
Determine the object that the picking ray intersects. The inter-
sected object corresponds to the picked screen object.
15.1 Screen to Projection Window Transform
The first task is to transform the screen point to the projection window.
The viewport transformation matrix is:
Width
0
0
0
2
Height
0
0
0
2
0
0
MaxZ
MinZ
0
Width
Height
X
Y
MinZ
1
2
2
Transforming a point p =( p x , p y , p z ) on the projection window by the
viewport transformation yields the screen point s =( s x , s y ):
Width
Width
s
p
X
x
x
2
2
Height
Height
s
p
Y
y
y
2
2
Recall that the z-coordinate after the viewport transformation is not
stored as part of the 2D image but is stored in the depth buffer.
In our situation we are initially given the screen point s , and we
need to find p . Solving for p , we obtain:
2
s
2
X
Width
p
x
x
Width
2
s
2
Y
Height
y
p
y
Height
Search WWH ::




Custom Search