Graphics Reference
In-Depth Information
PushMatrix
Rotate -90 1 0 0
WireTeapot
PopMatrix
Notice that this uses an orthographic projection. That seems strange,
because we would expect to use perspective for most of the images we would
want to display. The perspective is actually here—it is created as part of the
dome equation in the vertex shader. This happens through the use of the
point's z -coordinate in computing the angle Φ. That dome equation makes
geometry appear to reach a vanishing point as it gets farther away and maps
everything to be inside the unit circle. This orthographic projection is there to
handle the display of the unit circle and to set up the depth clipping.
The dome vertex shader code actually does all the work of converting
spaces that is shown in Figure 7.5. As is often the case when working with
glman , we have hardcoded a variable, the light position that would be picked
up from the OpenGL environment in a real application.
const float PI = 3.14159265;
out vec4 vColor;
void
main( void )
{
vColor = aColor;
vec4 pos = uModelViewMatrix * aVertex;
float lenxy = length( pos.xy );
if( lenxy != 0.0 )
{
float phi = atan( lenxy, -pos.z );
pos.xy = normalize( pos.xy );
// pos.xy is now equal to (cos theta, sin theta)
float r = phi / (PI/2.);// radius <= 1.
pos.xy *= r; // same theta, different radius
// pos.z is left alone so that it can participate in depth
// clipping
}
gl_Position = uProjectionMatrix * pos;
}
Search WWH ::




Custom Search