Assignment 5: 3D Graphics with OpenGL - Perspective Setup and Object Manipulation - Prof. , Assignments of Computer Graphics

An assignment for a computer graphics course using opengl and glut. Students are required to set up a 3d opengl program, configure the perspective, and manipulate objects using matrices. The assignment involves rendering a 3d geometry into a window, setting up a projection matrix, and creating a cone with specific color requirements.

Typology: Assignments

Pre 2010

Uploaded on 03/10/2009

koofers-user-q4e-1
koofers-user-q4e-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fall 2006
22C:151 Introduction to Computer Graphics
Assignment 5
Due: Wednesday, September 27th at 11:59 pm
Goal: Setup a 3D OpenGL program with perspective and simple geometry, and utilize matrices to manipulate objects.
Problem 1 (20 points): Write an OpenGL/GLUT program that renders 3D geometry into a 640 ×480 window.
Part A (3 points): Set the projection matrix for 3D instead of 2D. Set your view frustum with a near plane at a
distance of 1, a far plane at distance 100, and a field of view of 90. Set the aspect ratio correctly. Hint: If you
are building on existing code, this should replace gluOrtho2D(). Also note the aspect ratio should not be 1.
Part B (1 point): You can use either gluPerspective() or glFrustum() to do Part A. In your README
file, write the equivalent calls (to gluPerspective() and glFrustum()) that give the projection matrix
required for Part A.
Part C (1 point): Set your eye point (using gluLookAt()) to have the eye at (0,5,5), looking at (0,0,0) with
an up vector of (0,1,0).
Part D (2 points): Remember that in OpenGL you can equivalently think of “moving they eye” or “moving
the scene.” A single translation and a single rotation can give you a matrix equivalent to that generated by
gluLookAt(). What translation and what rotation are required? Write the answer in your README.
Hint: The answer may not be your first thought. You can check your answer by comparing your answer
with the matrix gluLookAt() creates. You can get this matrix by reading back the modelview matrix
using the following code:
GLfloat gluLookAtMatrix[16];
glMatrixMode(GL MODELVIEW);
glLoadIdentity();
gluLookAt( <...fill in correct values...>);
glGetFloatv(GL MODELVIEW MATRIX, gluLookAtMatrix );
printf("%f %f %f %f\n", gluLookAtMatrix[0], gluLookAtMatrix[4], <...etc...>);
printf("%f %f %f %f\n", gluLookAtMatrix[1], gluLookAtMatrix[5], <...etc...>);
<...etc...>
Part E (3 points): Write a function (with no parameters) that draws a cone of height 2 with a radius of 1 at the
base.
The tip of the cone should be at (0,0,2) and the base should be on the z= 0 plane (so (1,0,0), (-1,0,0),
(0,1,0), and (0,-1,0) are all on the cone’s base).
The tip of the cone should be green and the base should be red at (-1,0,0) and blue at (1,0,0). Along the
base of the cone, you should smoothly interpolate between red and blue (e.g., the color at points (0,1,0)
and (0,-1,0) should be a dark purple color (0.5,0,0.5)).
This function will be called from inside your display function, so it should not call glClear(),glFlush(),
or glutSwapBuffers().
Suggestion: Use two triangle fans. One for the triangles on the base of the cone (in the z= 0 plane) and
one for the conical part. Since your cone will be made up of triangles, use at least 40 triangles to make it
appear smooth.
pf2

Partial preview of the text

Download Assignment 5: 3D Graphics with OpenGL - Perspective Setup and Object Manipulation - Prof. and more Assignments Computer Graphics in PDF only on Docsity!

Fall 2006

22C:151 Introduction to Computer Graphics

Assignment 5

Due: Wednesday, September 27th at 11:59 pm

Goal: Setup a 3D OpenGL program with perspective and simple geometry, and utilize matrices to manipulate objects.

Problem 1 (20 points): Write an OpenGL/GLUT program that renders 3D geometry into a 640 × 480 window.

  • Part A (3 points): Set the projection matrix for 3D instead of 2D. Set your view frustum with a near plane at a distance of 1, a far plane at distance 100, and a field of view of 90 ◦. Set the aspect ratio correctly. Hint: If you are building on existing code, this should replace gluOrtho2D(). Also note the aspect ratio should not be 1.
  • Part B (1 point): You can use either gluPerspective() or glFrustum() to do Part A. In your README file, write the equivalent calls (to gluPerspective() and glFrustum()) that give the projection matrix required for Part A.
  • Part C (1 point): Set your eye point (using gluLookAt()) to have the eye at (0,5,5), looking at (0,0,0) with an up vector of (0,1,0).
  • Part D (2 points): Remember that in OpenGL you can equivalently think of “moving they eye” or “moving the scene.” A single translation and a single rotation can give you a matrix equivalent to that generated by gluLookAt(). What translation and what rotation are required? Write the answer in your README.

Hint: The answer may not be your first thought. You can check your answer by comparing your answer with the matrix gluLookAt() creates. You can get this matrix by reading back the modelview matrix using the following code: GLfloat gluLookAtMatrix[16]; glMatrixMode(GL MODELVIEW); glLoadIdentity(); gluLookAt( <... fill in correct values ...> ); glGetFloatv(GL MODELVIEW MATRIX, gluLookAtMatrix ); printf("%f %f %f %f\n", gluLookAtMatrix[0], gluLookAtMatrix[4], < ...etc... >); printf("%f %f %f %f\n", gluLookAtMatrix[1], gluLookAtMatrix[5], < ...etc... >); < ...etc... >

  • Part E (3 points): Write a function (with no parameters) that draws a cone of height 2 with a radius of 1 at the base. - The tip of the cone should be at (0,0,2) and the base should be on the z = 0 plane (so (1,0,0), (-1,0,0), (0,1,0), and (0,-1,0) are all on the cone’s base). - The tip of the cone should be green and the base should be red at (-1,0,0) and blue at (1,0,0). Along the base of the cone, you should smoothly interpolate between red and blue (e.g., the color at points (0,1,0) and (0,-1,0) should be a dark purple color (0.5,0,0.5)). - This function will be called from inside your display function, so it should not call glClear(), glFlush(), or glutSwapBuffers(). - Suggestion: Use two triangle fans. One for the triangles on the base of the cone (in the z = 0 plane) and one for the conical part. Since your cone will be made up of triangles, use at least 40 triangles to make it appear smooth.
  • Part F (2 points): Draw your cone. You should be able to call your cone function from Part E in your display function. Rotate it so that the tip of the cone is at (0,2,0) and the base lies on the y = 0 plane. Do not change your cone function from Part E to do this!
  • Part G (2 points): Setup an idle callback that causes the cone in Part F to rotate around the y-axis by a small amount each frame. (Note: The colors will exhibit a strange behavior as the cone rotates around the y-axis. This is fine. Fixing the problem is the extra credit.)
  • Part H (2 points): Draw another cone with base centered at (3,1,0) with tip at (3,1,2). Reuse your cone function from Part E. You should have a single cone function that you call twice, once for Part F, once for Part H.
  • Part I (4 points): Draw a yellow teapot and place it somewhere (other than the origin) so that it’s visible in the scene. Make sure it does not overlap with the cones. (Hint: Use glutSolidTeapot() , which you can read about in the OpenGL Programming Guide.)

Extra Credit (2 points): Why do the cones drawn in Parts G and H look strange? put the answer in your README. Fix the problem in your program, and add a keyboard callback (using the ’x’ key) to switch back and forth between the original and fixed versions. To get credit, the discontinuity apparent in the cones must go away.

NOTES:

  • A “README” file is required in order to get full credit. It must include compiling instructions.
  • Posting images of your assignment on your webpage is required in order to get any credit.
  • You may add additional geometry to your scene, as long as it doesn’t overlap with the cones or teapot.
  • A sample executable is available on the web page for you to see my expectations.