CS430/536 - Homework Assignment 4

Programming Problem:

1. Understand the Simple Model Format SMF (*.smf)

    SMF is a standard file format for specifying meshes. You do not have to implement a complete specification in SMF, just the v and f rules.
    Make sure that you ignore any other commands in the input. A v denotes a vertex, and a f denotes a face. Three floating point numbers follow a v that define the x, y, z positions of the vertex. Integer references to the vertices follow an f. The references assume the order of the vertices specified in the file. The vertices for a face are defined in counter-clockwise order. The numbering of the vertices begins at 1.
   
    Here is a small example of the format:
   
    v -1.0 -1.0 -1.0
    v -2.0 -3.0 -4.0
    ...
    f 1 2 3
    f 3 4 1

    Several example smf files can be found and here.

2. Write a program, named CG_hw4 and in your language of choice, to draw the edges of an smf model to the specified viewport. Additionally:
    1. Accept smf file as an input. Examples can be found here.
    2. [-f] The next argument is the input SMF file
    3. The output image (screen) will be [501, 501]
    4. The view plane window should be placed within the viewport.
    5. Clipping should occur along the outer boundaries of the viewport if necessary.
    6. You should be able to process any subset of the command-line arguments in any arbitrary order.
    7. [-j] The next argument is an integer lower bound in the x dimension of the view port in screen coordinates (0)
    8. [-k] The next argument is an integer in lower bound in the y dimension of the view port in screen coordinates (0)
    9. [-o] The next argument is an integer in upper bound in the x dimension of the view port in screen coordinates (500)
    10. [-p] The next argument is an integer in upper bound in the y dimension of the view port in screen coordinates (500)
    11. You can assume that the viewport will always be specified within the image, and that j & k will be less than o and p.
    12. 3D view volume defined as follows:
        i. [-x] floating point x of Projection Reference Point (PRP) in VRC coordinates (0.0)
        ii. [-y] floating point y of Projection Reference Point (PRP) in VRC coordinates (0.0)
        iii. [-z] floating point z of Projection Reference Point (PRP) in VRC coordinates (1.0)
        iv. [-X] floating point x of View Reference Point (VRP) in world coordinates (0.0)
        v. [-Y] floating point y of View Reference Point (VRP) in world coordinates (0.0)
        vi. [-Z] floating point z of View Reference Point (VRP) in world coordinates (0.0)
        vii. [-q] floating point x of View Plane Normal vector (VPN) in world coordinates (0.0)
        viii. [-r] floating point y of View Plane Normal vector (VPN) in world coordinates (0.0) NOTE: This is redefining a previous command line option!!!
        ix. [-w] floating point z of View Plane Normal vector (VPN) in world coordinates (-1.0)
        x. [-Q] floating point x of View Up Vector (VUP) in world coordinates (0.0)
        xi. [-R] floating point y of View Up Vector (VUP) in world coordinates (1.0)
        xii. [-W] floating point z of View UP Vector (VUP) in world coordinates (0.0)
           You may assume that the VUP is not parallel to VPN
        xiii. [-u] floating point u min of the VRC window in VRC coordinates (-0.7)
        xiv. [-v] floating point v min of the VRC window in VRC coordinates (-0.7)
        xv. [-U] floating point u max of the VRC window in VRC coordinates (0.7)
        xvi. [-V] floating point v max of the VRC window in VRC coordinates (0.7)
        xvii. [-P] Use parallel projection. If this flag is not present, use perspective projection.
    13. The are no limitations on the values of PRP, VRP, VPN and VUP.
    14. You can assume that u and v will always be less than U and V.

The command-line options correspond to the values in Figure 1.


Figure 1: View Frustum

    14½. Extra Credit (2 points). Add backface culling with the [-b] option. Due date is the last day of classes.

    15. While you won't be doing front and back face clipping in this assignment you will need values for the near and far plane. You can use the default values for these parameter from HW5, front (-F) equal 0.6, and back (-B) equal -0.6.

    16. The default values that should be assumed if none are entered are equivalent to the following command line option set:
    ./CG_hw4 -f bound-lo-sphere.smf -j 0 -k 0 -o 500 -p 500 -x 0.0 -y 0.0 -z 1.0 -X 0.0 -Y 0.0 -Z 0.0 -q 0.0 -r 0.0 -w -1.0 -Q 0.0 -R 1.0 -W 0.0 -u -0.7 -v -0.7 -U 0.7 -V 0.7 > out.xpm

Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.


    17. Input/Output Examples:
       i. Input: (Perspective Projection)
          PRP (-1.0 0.0 0.5)
          VRP (0.0 0.0 0.0)
          VPN (1.0 0.0 -0.5)
          VUP (0.0 1.0 0.0)
          left -0.7 right 0.7
          bottom -0.7 top 0.7
          viewport left 0 right 500
          viewport bottom 0 top 500
    ./CG_hw4 -f bound-lo-sphere.smf -x -1.0 -z 0.5 -q 1.0 -w -0.5 > out.xpm
       ii. Output:
Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

       i. Input: (Perspective Projection)
          PRP (0.0 0.0 1.0)
          VRP (0.0 0.0 0.0)
          VPN (1.0 0.0 -1.0)
          VUP (0.0 1.0 0.0)
          left -0.7 right 0.7
          bottom -0.7 top 0.7
          viewport left 0 right 500
          viewport bottom 0 top 500
    ./CG_hw4 -f bound-lo-sphere.smf -q 1.0 -w -1.0 > out.xpm
       ii. Output:
Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

       i. Input: (Perspective Projection)
          PRP (-4.0 0.0 5.0)
          VRP (0.0 0.0 0.0)
          VPN (1.0 0.0 -0.5)
          VUP (0.0 1.0 0.0)
          left -0.7 right 0.7
          bottom -0.7 top 0.7
          viewport left 0 right 500
          viewport bottom 0 top 500
    ./CG_hw4 -f bound-lo-sphere.smf -x -4.0 -z 5.0 -q 1.0 -w -0.5 > out.xpm
       ii. Output:
Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

       i. Input: (Perspective Projection)
          PRP (0.0 0.0 1.0)
          VRP (0.0 0.0 0.0)
          VPN (1.0 0.0 -1.0)
          VUP (0.0 1.0 0.0)
          left -1.4 right 1.4
          bottom -0.7 top 0.7
          viewport left 0 right 500
          viewport bottom 125 top 375
    ./CG_hw4 -f bound-lo-sphere.smf -k 125 -p 375 -q 1.0 -u -1.4 -U 1.4 > out.xpm
       ii. Output:
Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

Bunny Example Parallel Projection

./CG_hw4 -f bound-bunny_200.smf -j 100 -k 50 -o 400 -p 450 -x 0.5 -y 0.2 -z 1.0 -X 0.2 -Y -0.2 -Z 0.3 -q -3.0 -r -2.0 -w 1.0 -Q 3.0 -R -2 -W -4.0 -u -.5 -v -.9 -U 1.2 -V .8 -P > hw4_f.xpm

Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

Bunny Example Perspective Projection

./CG_hw4 -f bound-bunny_200.smf -j 100 -k 50 -o 400 -p 450 -x 0.5 -y 0.2 -z 1.0 -X 0.2 -Y -0.2 -Z 0.3 -q -3.0 -r -2.0 -w 1.0 -Q 3.0 -R -2 -W -4.0 -u -.5 -v -.9 -U 1.2 -V .8 > hw4_g.xpm

Here is the XPM image file.

PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

Cow Examples

./CG_hw4 -f bound-cow.smf > cow_default.xpm

 

./CG_hw4 -f bound-cow.smf -P > cow_parallel.xpm

 

./CG_hw4 -f bound-cow.smf -j 0 -k 30 -o 275 -p 305 -P > cow_jkopP.xpm

  ./CG_hw4 -f bound-cow.smf -x 1.5 > cow_x1.5.xpm

 

./CG_hw4 -f bound-cow.smf -x 4.75 -y -3.25 -z 3.3 -P > cow_xyzPar.xpm

 

./CG_hw4 -f bound-cow.smf -X 0.25 -Y -0.15 -Z 0.3 > cow_XYZ.xpm

 

./CG_hw4 -f bound-cow.smf -X 0.35 -Y -0.3 -Z 0.3 -u -0.35 -v -0.35 -P > cow_XYZuvP.xpm

  ./CG_hw4 -f bound-cow.smf -X 0.25 -Y -0.15 -Z 0.3 -j 103 -k 143 -o 421 -p 379 > cow_XYZjkop.xpm

 

./CG_hw4 -f bound-cow.smf -X 0.35 -Y -0.3 -Z 0.3 -u -0.35 -v -0.35 -j 43 -k 71 -o 201 -p 402 -P > cow_XYZuvjkopP.xpm

 

./CG_hw4 -f bound-cow.smf -q -1 -r 1.5 -w -2.0 > cow_q_r_w.xpm

 

./CG_hw4 -f bound-cow.smf -Q 1.5 -R 1 -W .4 > cow_QRW.xpm

 

./CG_hw4 -f bound-cow.smf -u -1.5 -v -0.9 -U 1.2 -V 0.7 > cow_uvUV.xpm

 

Debugging Examples

The following examples are generated from a student assignment.

All examples use front and back plane values of F = 1 and B = -5.

Perspective

The following image is produced by ./CG_hw4 -f cube.smf -u -1.5 -v -1.5 -U 1.5 -V 1.5 -F 1 -B -5 > ex1.xpm.
The corners of the cube in world coordinates are ((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5).
The corners of the cube in normalized coordinates in the canonical perspective view volume are ((0.05556, -0.05556, -0.0833), (-0.05556, 0.05556, -0.25)).

The matrix for the associated normalizing tranformation is

-0.111111000
00.11111100
00-0.166667-0.166667
0001

 

 

The following image is produced by ./CG_hw4 -f cube.smf -q 1.5 -r 2 -w 5 -u -1 -v -1 -U 1 -V 1 -z 6 -F 1 -B -5 > ex2.xpm

The matrix for the associated normalizing tranformation is

0.5224510 -0.1567350
-0.05607530.509351-0.1869180
0.02439350.03252460.0813116-0.545455
0001

 

 

The following image is produced by ./CG_hw4 -f cube.smf -x -4.0 -z 5.0 -q 1.0 -w -0.5 -u -1.0 -v -1.0 -U 1.0 -V 1.0 -F 1 -B -5 > ex3.xpm

The matrix for the associated normalizing tranformation is

0.1341640-0.6260990
00.500
0.08944270-0.0447214-0.5
0001

 

Parallel

The following image is produced by ./CG_hw4 -f cube.smf -u -1.5 -v -1.5 -U 1.5 -V 1.5 -F 1 -B -5 -P > ex1_P.xpm.
The corners of the cube in world coordinates are ((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5).
The corners of the cube in normalized coordinates in the canonical parallel view volume are ((0.333, -0.333, -0.0833), (-0.333, 0.333, -0.25)).

The matrix for the associated normalizing tranformation is

-0.666667000
00.66666700
00-0.166667-0.166667
0001

 

The following image is produced by ./CG_hw4 -f cube.smf -q 1.5 -r 2 -w 5 -u -1 -v -1 -U 1 -V 1 -z 6 -F 1 -B -5 -P > ex2_P.xpm

The matrix for the associated normalizing tranformation is

0.9578260-0.2873480
-0.1028050.933809-0.3426820
0.04472140.05962850.149071-0.166667
0001

 

The following image is produced by ./CG_hw4 -f cube.smf -x -4.0 -z 5.0 -q 1.0 -w -0.5 -u -1.0 -v -1.0 -U 1.0 -V 1.0 -F 1 -B -5 -P > ex3_P.xpm

The matrix for the associated normalizing tranformation is

0.2683280 -1.25220
0100
0.1490710-0.0745356-0.166667
0001

 

 

3. Grading Scheme

  1. viewport mapping correct : 1 point
  2. PRP correct : 1 point
  3. VRP correct : 1 point
  4. VPN correct : 1 point
  5. VUP correct : 1 point
  6. VRC window correct : 1 point
  7. clipping correct : 1 point
  8. parallel projection implemented : 1 point
  9. perspective projection implemented : 2 points
  10. backface culling (extra credit) : 2 points

4. Submission Guidelines:

  1. Assignments must be submitted via Bb Learn.
  2. README file: explain the features of your program, language and OS used, compiler or interpreter used, name of file containing main(), and how to compile/link your program. Text files only. Word and PDF documents will NOT be accepted.
  3. All source code. Your code must compile and run on tux (Linux).
  4. You may program in any language you like as long it can produce a usable executable on tux.
  5. Your program will be run by the TA. Please do NOT submit any image files, Visual C++ project files, or anything not requested in this section. Your program must run on tux without the installation of "special" libraries.
  6. Makefile: have the default rule compile your program. Jar file, if using java.
  7. If you are using a language that doesn't produce an executable file, e.g. python, then be sure to include a script called CG_hw4 that accepts arguments and prints XPM to standard out.
  8. Points will be deducted if submission guidelines are not followed.
  9. Further details about Bb Learn
    1. You can reach Bb Learn through DrexelOne.
    2. Choose Computer Graphics among your list of courses. There is an "assignments" link in the left frame which will give you the list of assignments in the right frame.
    3. Click on the assignment you wish to submit.
    4. Find your file and click Upload button.
    5. Hit Submit button. DO NOT FORGET TO HIT THE SUBMIT BUTTON AFTER YOU UPLOAD ALL YOUR FILES.

NOTE: Your source code for all programming assignments will be run through a plagiarism detection system. This program uses compiler techniques which are invariant of syntax and style. If you are sharing code with other classmates, you will get caught. Please refer to the student handbook for actions that will be taken.
Last modified on November 29, 2015.