Pro OpenGL ES for iOS

(singke) #1

CHAPTER 2: All That Math Jazz (^47)
Figure 2-12. Projecting x and y onto the device’s screen. You can visuallize this as either translating the iPhone
(or iPad) to the object’s coordinates (left) or translating the object to the iPhone’s coordinates (bright.
And when the pixel dust settles, we have a nice matrixy form:





⎤ ⎢ ⎢ ⎢ ⎢ ⎣
⎡ ⎥ ⎥ ⎥ ⎥ ⎦
⎤ ⎢ ⎢ ⎢ ⎢ ⎣







⎤ ⎢ ⎢ ⎢ ⎢ ⎣




0 0 1 1
0 0 0 0
0 0
0 0
1
z
y
x
d
d T
d T
z
y
x
y
x
Usually, some final scaling is required------for example, if the viewport is normalized. But
that is left up to you.
Now Do it Backward and in High Heels
Such was a quote allegedly given by Ginger Rogers on how she felt about dancing with
the great Fred Astaire. The response was that although he was very good, she had to do
everything he did and do it backward and in high heels. (Rogers apparently never
actually said that; its use has been traced back to a gag line from the comic strip Frank
and Ernest.)
So, what does this have to do with transformations? Say you wanted to tell whether
someone picked one of your objects by touching the screen. How do you know which of
your objects has been selected? You must be able to do inverse transformations to
‘‘unmap’’ the screen coordinates back into something recognizable within your 3D
space. But because the z-value gets dropped in the process, it will be necessary to

Free download pdf