COMP3421/9415 Computer Graphics Assignment 2
Computer Graphics 09s2 Last updated Wed 07 Oct 2009 14:27

Introduction

In assignment 1, you developed a 2D editor, DSEdit, that allowed you to design a top-down view of a scene. Now, using the saved files from that program, you are going to develop a program that will allow the user to drive a car through the scene. Using the mouse, users will be able to move through the scene and observe the effects of things like lighting and texture; not to mention daytime and night time. You must also render a car that can be driven around.

So, what you have to do is go from something like this:

to something like this:

Specification

You are to develop a program, called DSView, that renders scenes created using DSEdit. In addition to supporting the file format used by DSEdit, two additional shapes are supported in ds files:

What you get

You get something that includes the solution to assignment 1; but also has a few additional files and modifications. It implements the following functionality:

The files added and/or included are:

There are other minor modifications here and there; but reading the source code and understanding it is part of the assignment.

You also might find a few ds files to play with, some of which may or may not be useful for testing ;-).

Try my solution:
% 3421
% cd /web/cs3421/09s2/assignments/dsview
% ./dsviewsol maps/view.ds

What remains to be implemented

The following things have to be added to the solution (in the order I think is easiest):

Interaction

Your implementation of DSView should support the following behaviour to keyboard presses.

It should react in the following way to mouse movements: If any mouse button is held down, then if the mouse is moved up, the viewer's position should move forward in the direction he is facing (note consequently that the point he is looking at changes). If the mouse is moved down, the viewer's position should be moved backwards in a direction opposite to the one he is facing. If the mouse is dragged left or right, then the direction the viewer is facing should turn to the left or right.

Appropriate rates of movement and turning should be set. However, the rate should be independent of the viewer's position in the scene, so that the behaviour is predictable.

3D shapes

The convention in 3D graphics is that the y axis points up and the ground plane is y=0. That means that the 2D points in a DSShape actually give the x and z coordinates in the 3D world. For example, all DSPolygons lie in the ground plane, so the vertices need to be defined like this.
gl.glVertex3d(p.x, 0, p.y);
Roads should be assumed to be elevated 1 unit or so above the DSpolygons. This is to ensure that roads appear in front of DSPolygons. The car may be represented as a simple white rectangular prism.

Signs are rendered as vertical rectangles, the bottom of the sign is at height 6, while the top is at the height given by the extra number stored in each DSSHape. The post holding up the sign is a rectangular prism going from 0 to 6.

Trees are rendered as a cylinder (vertical) combined with a sphere. The height of the trunk is given by the extra number. Code for rendering tree trunks is provided. You will have to add code for rendering the sphere. The radius of the sphere is the distance between the two control pointws that define the Tree.

Buildings are rendered as four vertical rectangles with the height given by the extra number.

Lights and ViewPoints

Lights and ViewPoints are not visible by themselves, but affect how the other shapes are drawn. The render3d method for these should do nothing. A Light represents a light source and is defined with one control point:
Light <red> <green> <blue> null 1.0 <height> 1 <x> <y> 
red, green and blue represent the red green and blue intensities of the light source, ranging from 0 to 255. null and 1.0 (texture and texture scale) are ignored. This is a point light source at [x,height,y,1]. Note that you must always give four numbers (homogenous coordinates) when you tell OpenGL the position of a light. There are a maximum of 4 light sources in any one scene.

A ViewPoint is defined by two control points. The first gives the x and z coordinates of the eye position, while the second is the x and z coordinates of the look position. The extra number is the y coordinate of the eye position, while the y coordinate of the look position is always 10. The up vector is (0,1,0).

Textures

Textures are to be applied to polygons and roads as for assignment 1. The scaling factor defined in the DS file is to be interpreted as follows: A scale factor of n means that there are n repetitions of the texture in every 100 units along each axis (i.e. a total of n*n actual repetitions per 100 units).

Textures for signs have a different meaning. A scale of 1 for a sign means that there is 1 copy of the texture on the whole sign. A scale of 2 means there are 2x2 = 4 copies of the texture on the sign. If a sign is defined as (x1,y1)-(x2,y2) and the scale factor is 1, then the point (x1, y1) has coordinates (0,0) in texture space, and (x2, y2) has coordinates (1,0) in texture space. This determines which side of the texture should be rendered on the billboard. Surfaces are assumed to have the same textures on both sides.

Textures on buildings are scaled so that they stretch from the bottom to top. In the horizontal direction they are scaled as for roads.

Trees don't need to be textured.

See the source code for rendering polygons for an example of using textures.

Lighting

Lighting is to use the usual illumination model; with no light source attenuation. All surfaces have no specular component. Use Gouraud (GL_SMOOTH) shading for the shading model.

Constants

You can assume the following constants:

Initial state

Initially, the system should start in the following state:

Command Line

Your program will be called DSView. It should be called from the command line like:
% java DSView <ds file>

C++ version

You can use C++ if you prefer. There is a zip file of C++ code you can start with.

Marking, Submission, etc

The assignment will be marked out of 20. Most of the marks are for implementing the various features, but there are six marks for programming style and documentation. Markers will be allowed to give up to 4 bonus marks for additional interesting features in the viewer if a high level of accomplishment in the base assignment is completed; hence it is theoretically possible (although unlikely) to get 24/20 for this assignment. Examples of additional features likely to get bonus marks would include things like :

but you should not limit yourself to these. Use your imagination! Be sure to document these features and how to use them in a readme.txt file. You must submit a readme.txt -- if you haven't made any extensions just hand in an empty file. Extensions should not interfere with the basic specification; if they do, you may lose marks.

If you think your extensions are really cool, submit your readme.txt like this:

% give cs3421 dsviewbonus readme.txt
I will look at all these and in the last lecture I will give a prize for the best one.

This assignment is due 11:59:59 on Sunday 11th October. Submissions will be allowed up to 5 days late. For each day late, you will lose 2 marks from your maximum possible base mark (i.e. bonus marks are not included in late calculations).

If you do change a file, please leave a comment at the top of the file saying something like: /** THIS FILE HAS CHANGED **/ so it indicates to the marker that they should take a careful look at it. Also, within your source, it would make the marker's job easier if you indicated where you had changed files; again, through marking new functions with /* NEW FUNCTION*/ or something like it as appropriate.

Submit ALL the files required for your assignment to run DSView correctly. Do NOT submit any java files that are NOT required for your assignment to compile and run. They will break the marking system. If javac *.java does not work, then the assignment marking system will break and it will delay the marking and return of your assignment.

Hand in the Java classes, your readme.txt file and any other files related to extensions you have written using give:

% give cs3421 dsview <files>
Please do not hand in textures or ds files that were included in the distribution.

Hints

Ambient light should be the OpenGL default of (0.2,0.2,0.2). If your code doesn't change it explicitly, then it will be this value anyway. The code you are given has it set to a particular value so that you can see the scene before you implement lighting. Once you have implemented lighting, you should modify and/or remove the line.

Getting left and right mouse movement working when the height of the viewpoint and the height of the point being looked at are different can be tricky, so you don't have to worry about it -- your code will only be tested for mouse left/right movement with files for which the height of the eye and the height of the lookat point are identical. You can also assume that the lookat point is not directly beneath the eye. In other words, if the viewpoint line is:

ViewPoint 255 255 255 null 1.0 10.0  2 78.9 85.3 79.8 85.3
Viewpoint 0 0 0 null 1.0  <eyeheight> 2 <eyex> <eyez> <lookx> <lookz>
Then for the purposes of left/right movement (and only for that purpose, your assignment should work in all other regards in this situation), you can assume eyeheight=lookheight. Further, you can always assume that the situation where eyex=lookx AND eyey=looky will never occur.

More hints can be found in the FAQ.

Please post questions about the assignment to the forum instead of emailing them.

cs3421 @ CSE @ UNSW