CS430 - 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/page) 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/page, 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.
15. Print the projected 2D lines to standard out in the
output Postscript format.
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.ps
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.ps
ii. Output:
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.ps
ii. Output:
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.ps
ii. Output:
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.ps
ii. Output:
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.ps
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.ps
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.ps
./CG_hw4 -f bound-cow.smf -P > cow_parallel.ps
./CG_hw4 -f bound-cow.smf -j 0 -k 30 -o 275 -p 305 -P > cow_jkopP.ps
./CG_hw4 -f bound-cow.smf -x 1.5 > cow_x1.5.ps
./CG_hw4 -f bound-cow.smf -x 4.75 -y -3.25 -z 3.3 -P > cow_xyzPar.ps
./CG_hw4 -f bound-cow.smf -X 0.25 -Y -0.15 -Z 0.3 > cow_XYZ.ps
./CG_hw4 -f bound-cow.smf -X 0.35 -Y -0.3 -Z 0.3 -u -0.35 -v -0.35 -P > cow_XYZuvP.ps
./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.ps
./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.ps
./CG_hw4 -f bound-cow.smf -q -1 -r 1.5 -w -2.0 > cow_q_r_w.ps
./CG_hw4 -f bound-cow.smf -Q 1.5 -R 1 -W .4 > cow_QRW.ps
./CG_hw4 -f bound-cow.smf -u -1.5 -v -0.9 -U 1.2 -V 0.7 > cow_uvUV.ps
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.ps.
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.111111 | 0 | 0 | 0
|
---|
0 | 0.111111 | 0 | 0
|
---|
0 | 0 | -0.166667 | -0.166667
|
---|
0 | 0 | 0 | 1
|
---|
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.ps
The matrix for the associated normalizing tranformation is
0.522451 | 0 | -0.156735 | 0
|
---|
-0.0560753 | 0.509351 | -0.186918 | 0
|
---|
0.0243935 | 0.0325246 | 0.0813116 | -0.545455
|
---|
0 | 0 | 0 | 1
|
---|
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.ps
The matrix for the associated normalizing tranformation is
0.134164 | 0 | -0.626099 | 0
|
---|
0 | 0.5 | 0 | 0
|
---|
0.0894427 | 0 | -0.0447214 | -0.5
|
---|
0 | 0 | 0 | 1
|
---|
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.ps.
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.666667 | 0 | 0 | 0
|
---|
0 | 0.666667 | 0 | 0
|
---|
0 | 0 | -0.166667 | -0.166667
|
---|
0 | 0 | 0 | 1
|
---|
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.ps
The matrix for the associated normalizing tranformation is
0.957826 | 0 | -0.287348 | 0
|
---|
-0.102805 | 0.933809 | -0.342682 | 0
|
---|
0.0447214 | 0.0596285 | 0.149071 | -0.166667
|
---|
0 | 0 | 0 | 1
|
---|
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.ps
The matrix for the associated normalizing tranformation is
0.268328 | 0 | -1.2522 | 0
|
---|
0 | 1 | 0 | 0
|
---|
0.149071 | 0 | -0.0745356 | -0.166667
|
---|
0 | 0 | 0 | 1
|
---|
3. Grading Scheme
- viewport mapping correct : 0.5 point
- PRP correct : 1 point
- VRP correct : 1 point
- VPN correct : 1 point
- VUP correct : 1 point
- VRC window correct : 1 point
- clipping correct : 1 point
- parallel projection implemented : 1.5 point
- perspective projection implemented : 2 points
- backface culling (extra credit) : 2 points
4. Submission Guidelines:
- Assignments must be submitted via Bb Learn.
- 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.
- All source code. Your code must compile and run
on tux (Linux).
- You may program in any language you like as long it can produce
a usable executable on tux.
- 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.
- Makefile: have the default rule compile your program.
- 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 Postscript to standard out.
- Points will be deducted if submission guidelines are not followed.
- Further details about Bb Learn
- You can reach Bb Learn through DrexelOne.
- 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.
- Click on the assignment you wish to submit.
- Find your file and click Upload button.
- 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 December 3, 2021.