Graphics Reference
In-Depth Information
The vertex shader code to perform this is quite concise and looks like this:
uniform float uK;
uniform float uTransX;
uniform float uTransY;
void main( )
{
vec2 pos = ( uModelViewMatrix * aVertex ).xy;
pos += vec2( uTransX, uTransY );
float r = length( pos );
vec4 pos2 = vec4( pos/(r + uK), 0., 1. );
gl_Position = uProjectionMatrix * pos2;
}
In this case, a separate set of translations is explicitly being passed in,
although the translations encapsulated in the ModelView matrix will work
just fine. Also, it turns out that the scale factor encapsulated in the ModelView
matrix can be used as another way to zoom in and out. If a uniform scale factor
s is applied to the scene using glScalef( ) , the resulting hyperbolic geometry
equation would be
sr
sr
r
rks .
=
r
=
+
k
+
Thus, what we just thought of as k can actually also be thought of as 1/ s .
One other thing to notice is the use of the built-in GLSL length( ) func-
tion. Even though that same line could be writen as
float r = sqrt( pos.x*pos.x + pos.y*pos.y );
it is always beter to take advantage of built-in functions if they are available.
At the worst, they will be the same speed as your own version. At best, though,
they could take advantage of some features you don't have access to, and could
be much faster.
If you are not comfortable with this fish-eye type of zoom, you could look
at a Cartesian hyperbolic zoom, as shown in Figure 15.7. In this case, we do not
go to polar coordinates, but use hyperbolic transformations for the rectangular
coordinates, as
x
xk
=
x
,
2
+
2
y
yk
y
′ =
.
2
2
+
 
Search WWH ::




Custom Search