assignment代写：Flight Simulator

Draw
3 lines that represent the positive unit vectors in the X, Y, and Z directions,
with line width = 5. Make the lines colored red, green and blue, respectively.
Draw a small white ball at the origin.

Construct
a grid of GL_QUADS on the X-Z plane centered at the origin. The size of the
grid should be set as a global C constant (which you could change later). Set
the grid size to be 100×100 vertices.

Use
perspective projection. Handle a window re-size properly.

The
user can toggle between wireframe and solid rendering by pressing the ‘w’ key.
The user can switch between full-screen mode and windowed mode by pressing the
‘f’ key. Pressing ‘q’ quits from the application. Your scene should look like
this (wireframe and solid):

(ii)
Twin Engine Plane

You
will need to read the mesh data of the plan from a txt file. The file format is
very similar to obj files. The new feature in our file is that the lines that
begin with ‘g’ indicate a new sub-object. You should use different colors for
different sub-objects. By breaking the object up into sub-objects, it allows us
to color the plane properly:

(iii)
Camera Control

Allow
the user to control the direction of the camera/airplane movement with keyboard
keys and the mouse. The page-up and page-down keys increase and decrease the
speed of the camera/airplane movement in the direction that the camera is
currently pointing:

GLUT_KEY_PAGE_UP
: increase speed

GLUT_KEY_PAGE_DOWN
: decrease speed

But,
limit the speed so that it is always greater than zero. The up and down arrow
keys control the vertical position of the camera/airplane:

GLUT_KEY_
UP : moves the camera up

GLUT_KEY_
DOWN : moves the camera down

Moving
the camera/airplane up and down does not alter the direction that the
camera/airplane is pointing. The user can hold down a key to continuously move
in a direction, so you might want to use glutKeyboardUpFunc (which tells you
when the user has released a key) as well as glutKeyboardFunc (which tells you
when a key has been pressed).

Moving
left and right is significantly different. It is controlled by the mouse and
actually changes the direction that camera/airplane moves (not just its
position). This means that you can turn around and go in the opposite
direction. When the mouse is to the right of center or the left of center:

mouse
to the right : rotates the direction the camera is pointing/moving to right

mouse
to the left : rotates the direction the camera is pointing/moving to left

The
more the mouse is to the left or the right of center, the greater is the change
of camera direction. When the mouse is in the center, there is no change of
direction, but you will still be moving forward at some speed. The mouse button
does not need to be down for this to work.

Use
perspective projection with gluPerspective and gluLookAt to position the
camera.

You
DO need to tilt the airplane when the mouse is to the left or right.

(iv)
Lighting

Use
openGL’s lighting model. Use at least one directional light source, with
appropriate ambient, specular and diffuse levels. Position the light source so
that it is similar to sunlight.

You
need to set appropriate shininess, ambient, specular and diffuse material
properties for each object. You will have set the normal for each vertex in the
plane/propeller and the grid.

Part
B: Sea, Sky and Land

(v)
Sea & Sky

In
this section, you will replace the grid floor (and origin lines) from Part A
with a texture mapped disk, and a texture mapped cylinder. The disk lies on the
ground and is texture mapped with a water image. The cylinder stands upright
and encloses the ‘world’. The cylinder is texture mapped with a sky image.

Your
scene should look like this (wireframe and solid):

The
disk should be slightly bigger than the cylinder. The cylinder should sit
slightly lower than the disk. This will prevent any gaps. Make sure the
cylinder is large enough so that you cannot see the top of it but not so high
that the texture is overly stretched vertically.

You
can either write your own functions for constructing the cylinder and the disk,
or you can use the OpenGL functions that construct them for you. If you use the
OpenGL functions, you will need gluNewQuadric, gluQuadricTexture, gluCylinder
and gluDisk.

Make
sure that the textures appear in a similar fashion to the example program that
is given. The texture on the cylinder should wrap around like a label on a soup
can. The disk is textured as if a round cookie cutter was used on the water
image.

Use
a high emissive term for the lighting of both the sky and the sea so that they
are both evenly lit.

Turn
texture mapping on only for texture mapped objects. Use texture mipmapping.

(vi)
Fog

Add
fog to the sea. Use the built-in OpenGL functions to achieve this. Make the fog
a very transparent pink so that the sea blends in slightly with the sky at a
distance. Use an exponential fog function. Give the fog a very low density.
Make it look like the example program. Fog should only affect the sea. Turn the
fog on before drawing the sea and off

Fog
should only affect the sea. Turn the fog on before drawing the sea and off
afterward. The fog is toggled on and off with the ‘b’ key.

(vii)
Land

Create
islands in the sea. The construction of the islands follows a fractal landscape
stochastic algorithm.

You
should generate the mountain only once and store it in an array, don’t
construct it each time you draw it. The mountain should be constructed with 5
or 6 levels, whatever looks best. The mesh resolution for the islands should be
a changeable constant. Set it to a size of at least 40×40. The mountains are
toggled on and off with the ‘m’ key.

You
will need to color the mountain as well. Make the color at each vertex be a
function of the height (y value) of that vertex. Make it go from gray to white
near the top and dark green to the light green below the white. Also, add some
randomness so that it doesn’t look too uniform.

Your
islands should look like this (wireframe, solid and textured mode):

You
must make at least 3 mountains, with a different randomness. You can try
explicitly setting the value you pass to srand if you want to keep particular
mountain shapes. Each should be scaled differently in X, Y, Z. This you can do
with glScale. You can use the same texture and coloring function for all three
mountains.