Z-buffering and perspective
We showed how to enable Z-buffering in WebGL,
so that nearer objects are visible in the scene,
independent of the order in which the objects are rendered.
Then we added a simple camera matrix.
For now, all our matrix uCamera
is provide perspective, so that objects
nearer to the viewer appear larger, and
objects further from the viewer appear smaller.
Building a sphere mesh
We created a sphere mesh as follows:
-
Loop over j in an outer loop 0 ≤ j < 16
-
Within that, loop over i in an inner loop 0 ≤ i < 32
- For each value of i and j,
add two vertices to build
up a triangle strip:
(u,v0) = (i/32, j /16)
(u,v1) = (i/32, (j+1)/16)
sin(
- The point on the sphere surface at each value of (u,v) is:
(x,y,z) = ( cos(φ) cos(θ) , cos(φ) sin(θ) , sin(φ) )
where:
θ = 2 π u
φ = π v - π / 2
Homework
Due next Wednesday before the start of class
Start with the included code in
hw6.zip.
Make a scene that uses squareMesh,
tubeMesh and sphereMesh shapes.
Do not make a human figure.
What I am looking for is something
creative and original from you,
something that shows that you
understand how to create a hierarchical
scene using the matrix primitives:
mSave, mRestore, mIdentity, mTranslate, mRotateX, mRotateY, mRotateZ, mScale
Extra credit:
Add a torus to your scene.
To create a torus, you can use the same mesh logic that we used to create a sphere,
with the following difference:
For any given value of (u,v)
,
the point on a surface of a torus
with an inner radius of r
is given by:
(x,y,z) = ( (1 + r cos(φ)) cos(θ) , (1 + r cos(φ)) sin(θ) , r sin(φ) )
where:
θ = 2 π u
φ = 2 π v