用OpenGL代写程序,模拟多边形到球体的演变过程。
Requirement
In this assignment you will implement a popular scheme to achieve a good-
quality approximation of a sphere with a triangle mesh of variable resolution.
The scheme is as follows: The starting point is a polyhedron of 8 triangular
faces. The shape of this polyhedron is like two pyramids of square base, glued
to each other at the base. This starting polyhedron is considered to be a
sphere at resolution 0.
To obtain resolution 1, add one point in the middle of each edge and then lift
each added point away from the sphere center such that they achieve distance R
from the sphere center. R is the radius of the sphere being approximated. The
added vertices will cause each original triangular face to become 4 triangular
faces.
To obtain resolution 2, just repeat the same process for each of the current
edges. The process can be repeated any number of times and in the limit if
will converge to a perfect sphere.
This subdivision scheme is quite simple to be implemented recursively. Also
remember that computing normals for a sphere is trivial.
The requirements are summarized below:
- Subdivision: implement the described subdivision scheme in order to
correctly draw a sphere at any desired resolution. Use the following keys to
allow the user to change the resolution:
‘q’ - increase the resolution by 1
‘a’ - decrease the resolution by 1 - Texturing: now add a texture mapped to the sphere in any portion of the
sphere but such that the image appears with minimal deformation on the surface
of the sphere. You will then need to refine the texture coordinates during the
subdivision algorithm such that when the resolution of the sphere is changed
you will be able to see the texture correctly mapped at all times. - Visualization. You will need to display the sphere in different modes,
using the following keys:
‘z’ - wireframe (1%) (ok to use glPolygonMode)
‘x’ - single color flat shading (2%)
‘c’ - texture display on/off (2%)
‘v’ - single color smooth shading with visible specular reflection effects
(15%) - Automatic Level of Detail. To test your adaptive sphere you will implement
several spheres moving back and forth on the screen and automatically changing
their resolutions according to the distance from the user point of view.
For example, draw at least 10 spheres like in a grid formation in the XY
plane, and have each sphere to automatically move back and forth along the Z
axis, such that they appear very big when close to the viewer, and very small
when far away from the viewer. Have the motions of the spheres to be in such a
way that at any given time about half of the spheres are close to the viewer
and the other half look far away.
Then have your spheres to progressively update their resolutions such that
when they are big their resolution is high, but when they are far way, their
resolution is low. The ideal case is when all spheres look realistic and high
resolution is only used when needed.
Controls
space bar: switches between all spheres in high resolution and adaptive
resolution.
Keys: ‘w’, ‘s’, ‘e’, ‘d’, etc., use these keys to vary a few parameters of
your animation: faster/slower, more/less resolution variation, etc.
You do not need to implement the exact example described above, feel free to
implement a more creative scene of your own design. You just have to show in
this requirement several spheres moving around in a way such that
automatically adjusting their level of detail makes sense and improves the
performance of your application.