I came across the following segment of code that is supposed to project an image on a hemisphere:
void main(void)
{
vColor = aColor;
vec4 pos = uModelViewMatrix * vertex;
float lenxy = length(pos.xy);
if(lenxy != 0.0)
{
float phi = atan(lenxy, -pos.z);
pos.xy = normalize(pos.xy);
// pos.xy is equal to (cos theta, sin theta)
float r = phi / (PI/2.);
// radius is less than or equal to 1.
pos.xy *= r;
// same theta, different radius
}
gl_Position = uProjectionMatrix * pos;
}
The followings are what I need clarifications for:
- Why would
r
be less than or equal to1
by dividingphi
byPI/2.
? - Why are we multiplying
pos.xy
withr
? - And, how does normalizing
pos.xy
give us cos theta and sin theta?
The followings are the accompanying images:
Thanks.