[an error occurred while processing this directive]

Mandatory assignments, Computer Graphics MN1/DV1


The assignments are designed to constitute about 50% of the credit points. Note however that the assignments will not be reported individually to Uppdok.

Your assignment status on the day of the deadline reflects how many bonus points you get. Every correct assignment that is handed in before the corresponding deadline will give you 1.5 bonus point on the exam except assignment 5, which gives 2.5p, if and only if any needed revision of that assignment is completed before the revision deadline (see schedule).

The later an assignment is handed in, the lower priority it will get, and the longer it will take to correct it.

If your assignment has been corrected you should have

  1. received an email with comments,
  2. got a indication here if you have passed (R or G).
If not, mail the apropriate teacher, and we will make another try.

We strongly recommend that you try to complete the assignments before the exam; not only will you get bonus points, you will also get your credits earlier. And working with the assignments is an excellent way of preparing for the exam.

We prefer that you program in groups of two or three students. You are requested to hand in short reports (one or two pages) for each assignment. The report should contain a short description of what the program does, what you have done, as well as detailed instructions how to compile and test the program (we will do that). In addition, you may be required to demonstrate your programs "live", and all group members should be able to answear questions about it.

We prefer reports via e-mail, but do not attach all the code etc. as mailboxes tend to get stuffed pretty fast. Do mail us a path were we have read rights, or even better, an URL to a web page. Formats that we can read without troubble includes plain ASCII, html, ps and pdf.

Choice of language is free in all assignments, but it must compile on a UNIX platform in room 4408. (I'm sorry about this, but it takes too much time for us to correct otherwise.)

Here you can find some words about make if you run into trouble with that one.

The Assignments


1: Scan conversion of triangles


In-depth presentation and coverage of connected concepts: L02 and L03
Purpose: To give the student a thorough understaning of scan conversion.

Your task

In this exercise you are requested to implement the following:

You are not allowed to use any ready made scan conversion code, put_pixel (or similar) is the only thing allowed in this assignment (maybe with an exception for horiz_line).

This page might be a good source of inspiration. If you like, you may e.g. implement his "Perfect scan converting" routine for polygonfilling. (But personally I think mine is better:)

To help you get started, there exists some C++ code for X, OpenGL, SDL and Allegro here (or zipped), which you may use if you like. To use the OpenGL version for rasterisation does not really make sense, as this part is normaly hidden in OpenGL, therefore putpixel will be faster in the X-version, but do try OpenGL also. An example using unfilled triangles is attached in the code, so you can testrun it without modification.
Note: Do not copy/paste the Makefiles, as this ruins the tabulation, rightclick and select "Save link as..." instead.

I have put down effort to make the compilation as easy as possible without losing flexibility. As I wish to be able to choose between different API's, the code is separated into many directories. The common (non-API speciffic) code is located in the 'root' directory, while the code that is speciffic for each API is located in a separate directory.

If you use GNU-make, the included makefile should enable you to select the desired API by setting the variable 'api' to the directory of choise, see examples below.

Do have a look at all README file, and all the files in the 'root' directory as well as the files of some API directory of your choise. (The different API directories are fairly look-alike.) You will most sertainly write code into draw_triangle.cc, you must also select the triangle drawing mode (empty/solid/interpolated) in gasket.cc. To test how the finished program should work, you can use OpenGL's draw_triangle functions. To do this uncomment the line #define GL_PRIM in the beginning of draw_triangle.cc, and compile with api=GL.

If you work on a SUN machine at school, just downloading everything (unzip is a program to unzip zip files) and type $ gmake api=GW should work fine for the X-version.
If you like to test the OpenGL version, type $ gmake api=GL instead.
Note: The ordinary make at tdb gives me an error, so use gmake.
OBS: Add /opt/hacks/bin to your path (write: export PATH=$PATH:/opt/hacks/bin in your .bashrc) to find gmake

The makefile produces by default a file called myprog, type $ ./myprog to run it. You may edit the makefile to change the name from myprog to something of your choise.

If you work at a Linux machine at home I hope that the X-version should work straight of the shelf. To use the OpenGL version, you must of course also download Mesa.

If you work under a Microsoft OS, you cannot use the X-version. To use the OpenGL version it is probably easiest to download Mesa. Just throw in the common source files + the GL/main.cc file in a project.

If you like the Allegro game programming library, it is probably a nice choice also. It will run using X at school, but the faster on your PC at home. To compile at TDB type $ gmake api=ALLEGRO.

If you like the Simple Direct Media Layer library, it is probably a nice choice also. It will run using X at school, but the faster on your PC at home. To compile at TDB type $ gmake api=SDL.

The README briefly describes the different files.

The X code is wrapped in the C++ class "GraphicsWindow" ( GraphicsWindow.h, GraphicsWindow.cc)
which is supossed to provide a simple interface to the X Window System. It is documented in the source code.

Note 1: You can start/stop the X (GW) version with by pressing the 's' key.

Note 2: If you have problems with GraphicsWindow and shared memory, try to disable this by commenting the line #define ENABLE_SHMX in the beginning of GraphicsWindow.cc (which unfortunately will make things a bit slower).

Note 3: Some old and stupid compilers do not recognize, the in c++ defined keyword, "bool". If this happens to you, try and put the line #include <bool.h> first in your GraphicsWindow.h file.

Note 4: Use of the integer based color class icolor is optional. If you wish to speed things up it gives a nice effect in the inner loop of the shaded triangles. But do make sure that the floating point version works perfectly first.


2: Definition and wireframe rendering of a 3D scene

In-depth presentation and coverage of connected concepts: L06
Purpose: To give the student insight in 3D viewing, the use of transformations, as well as the various coordinate systems involved in the display pipeline.

Your task

All these should be implemented as matrix multiplications, using homogeneous coordinates.

The above order is probably a good order to implement things in. The window to viewport is e.g. needed to get things at the center of the screen, so we can see them.
Do not implement perspective until your lookat is properly working.

Build around these functions a framework for wireframe rendering of a 3D scene/object. It is enough to care only about triangles. Shading and hidden surfaces we will deal with in assignment 3. As we have not implemented hidden surface removal yet, the scene looks best in wireframe rendering. Use e.g. empty_triangle from assignemnt 1. (We will save your nice fill routines until assignment 3).

A keyboard mapping may e.g. look like this: (you are allowed to implement a mouse interface if you wish).

        x/X=move observer along World Coordinate system x-axis
        y/Y=move observer along WC y-axis
        z/Z=move observer along WC z-axis

        i/I=rotate observer around View Coordinate system x-axis
        o/O=rotate observer around VC y-axis
        p/P=rotate observer around VC z-axis

        w/W=rotate object around Object Coordinate system x-axis
        e/E=rotate object around OC y-axis
        r/R=rotate object around OC z-axis

        +/-=scale object

        d/D=change perspective distance

It is suggested to use a simple fileformat for the scene, e.g. a simplified version of nff (which is quite easy to implement).
If you are programming in Java you can use ReadNFF.java as a starting point for the nff parser.

If you whish you may use the framework that I have written in C++ which you can find in source/a2/ or download zipped from a2.zip.
Do read the README file.

It contains vector and matrix classes, as well as a simple object list structure. I have avoided templates not to mess up any compilers. It also has a loader for part of the nff format, which enables you to try and render e.g. the teapot.nff. Though, it's probably much better to start with e.g. the cube.

Note 1: The teapot is very small. My framework code supports a second command line option giving an overall scaling factor. E.g. $ engine teapot.nff 50 makes the world 50 times larger from start (this relies on your implementation of scale).

Note 2: I have not written any main for the Allegro and SDL api's. It should not be too hard to write yourself if you feel that you need one. If not, then stick to GW or GL.

I strongly suggest that you have a look at my code framework, regardless of which environment you choose to work in. At least some parts you should be able to, if not use directly, get useful ideas from (I hope).

But of course as previous, you are perfectly free to choose your own environment, as long as you do not use any ready made functions for 3D viewing of course.

An example program which has the desired functionallity and the keyboard interface from above, and which should (hopefully) run at TDB you can find here.

And as always! Well structured, well commented code with a small documentation telling how to compile and use the program.


3: Implementation of hidden surface removal, the Phong illumination model and Gouraud shading.

In-depth presentation and coverage of connected concepts:
Purpose: To give the student insight in basic HSR and illumination concepts.

Your task

Implemention of some (choise is free) hidden surface removing technique
A switch to turn on/off backface culling.
Implementation of the Phong reflection model in the, from assignment 2, existing framework.
The finished program should handle multiple lightsources of different colours.
A switch between Flat and Interpolated / Gouraud shading.
A switch to turn on/off the different parts of the Phong model (Ambient,diffuse and specular)

For the flat shading, you calculate a normal vector for each polygon, from the vertices of the polygon.
For the Gouraud shading, you may read the normal vectors for each vertex from the nff file or you may interpolate from all it's neighbouring polygons.
Rember to be careful when transforming normal vector (see lecture 8).

Make sure that you only illuminate the right sides of the polygons. See exam 000111 question 6.

Try values for the distance term yourself. Values that works for me are: a=0.01, b=0.01, c=0.0001 (without any physical explanation).

Note 1: If you are building on my code framework, you will have to write a lightsource class yourself. You will also have to add a lot of variables to the triangle class to hold the different color components.

Note 2: My recommended place to put the shading code is in a shade function of the triangle class, i.e. in triangle.cc.

Note 3: It is only the teapot.nff that has normal vectors in the nff file, so use that one for the Gouraud shading.


4: OpenGL

In-depth presentation and coverage of connected concepts:

Purpose:  To learn some basic things in OpenGL

Your task

In the previous assignment you wrote your own algorithms,
now it's time to get the feeling with a widely used API. 

Specification:
    Combine some hierarchical object with the given 3D room. 
    Increase realism with the help of texture mapping.

The room:
    This is a simple 3D room where you can place your objects and look at them
    from different positions. You get the source code for the room, just to have 
    something to start on.
    Note: it's recommended to read the room.cc file,to understand how the room
    works.  We have tried to comment it well. 

The hierachical object: 
    must consist of at least 3 or 4 Hierarchically dependent parts.
    An example could be a mechanical arm  with one rotating base attached to the 
    floor or a wall of the 3D room. To give you an example of an hierarchical object 
    we have included a link, which you can follow. Download that program and see 
    how works. That should give you some ideas about hierarchical objects. Another 
    example could be taken from the computer graphics course VT00, where you were 
    supposed to do an planetary system.

Download: (files for the assignment)
    -  Zip file
    -  Readme file
    -  Room  (Containing all the files unzipped)
    -  Hierarchical object exmple

OpenGL web site:
      http://www.opengl.org/

Tutorials: (Other tutorials than the one you will use for the assignment)
      http://www.opengl.org/developers/code/tutorials.html

Documentation:
    - OpenGL Specification & Manual Pages
      http://www.opengl.org/developers/documentation/index.html
    - GLUT specification:
      http://reality.sgi.com/mjk/spec3/spec3.html

 


5: A Spline surface editor

Splines - control points and movements: L15
Purpose: to yield understanding of how splines and control points work.
Bonus: 2.5p

Task:

*To write a program to create and move a cubic B-spline surface, given m by m control points, 4 <= m <= 10.

**Render using the recursive subdivision algorithm in the book by Angel, but there is a bug on p. 453, 4 lines from bottom of page: t[i]=(c[1][i]+c[2][i])/2; instead. Render the wire frame of the surface.

**Do it first for a 2D example (cubic B-spline curve). NOT obligatory, but gives 0.5 bonus points. You then have m control points.

**Rotate the surface, rotation about centre of gravity, by typing
R 45
on the keyboard, if you wish to rotate the surface 45 degrees. Any degree between 0 and 360 could be argument. The old wire frame is deleted and the new is plotted on the screen.

**Do Goraud shading, instead of naked wire frame. NOT obligatory, but gives 0.5 bonus points.
Hints: Use few mesh points when you test the algorithm, say m=4.
Note: You only obtain 1.5 bonus points if the 2 non-obligatory subtasks are not done.
The control points are fed in by typing them simply in a file. This is not typical for interactive computer graphics, but simpler. Read pp. 450- carefully. Conversion between Bezier and B-splines.


[Course homepage]