CSE 681
Autumn 2009

due Monday, Oct. 5 - electronically submit, as described below, by 11:59pm

Homework #2


ASSIGNMENT:
Write a program, called prog, to parse and process a text file that is an argument to the program. Perform the indicated 4x4 matrix computations according to the table below. In your program, keep a current 4x4 matrix, CM, that is modified by the commands. Points are column vectors multiplied on their left by the transformation matrix, CM.

You don't have to do any error checking on the input file. You can assume the input file exists and that all the commands are syntactically correct. Of course, you are welcome to include error-checking code because it might help your debugging process. I would suggest at least checking to make sure the input file opens correctly.

Process the following commands:
commandaction
identity
set the current matrix, CM, to the identity
print
print current matrix
transform  <x> <y> <z>
transform point, P, by the current matrix P' = CM*P and print out the transformed point, P'
rotate  [x|y|z] <degrees>
form rotation matrix, MR, and multiply the current matrix on the left: CM = MR*CM
translate  <tx> <ty> <tz>
form translation matrix, MT, and multiply the current matrix on the left: CM = MT*CM
scale  <sx> <sy> <sz>
form scale matrix, MS, and multiply the current matrix on the left: CM = MS*CM

NOTE: Notice that you cannot multiply the current transformation matrix back into itself directly without messing up some of the computations.

SUGGESTION: keep 2 current matrices and multiply from one into the other, keeping track of which is the 'current' current matrix.

   float      cm[2][4][4];
   int        c;
   
   c = 0;

   cm[1-c] = m * cm[c]       // really a set of triply nested loops
   c = 1-c

MAKEFILE SAMPLE
prog: prog.o
	gcc -o  prog prog.o -lm

prog.o: prog.c
	gcc -c -o prog.o prog.c

clean:
	rm -f prog.o prog 

EXECUTION EXAMPLE

assuming the grader has an input file called input.txt, (s)he should be able to do the following with your submission to compile and execute it:

make
prog input.txt

INPUT FILE SAMPLE (e.g. input.txt)
identity
print
scale 2 -3 5
print

identity
rotate x 30
print

identity
rotate z 30
print

identity
translate 1 2 3
print
rotate y 30
# translate first, then rotate 30 degrees around the y-axis
transform 1 2 3


OUTPUT SAMPLE (as a result of using sample input file, input.txt, above)

1.000000 0.000000 0.000000 0.000000 
0.000000 1.000000 0.000000 0.000000 
0.000000 0.000000 1.000000 0.000000 
0.000000 0.000000 0.000000 1.000000 

2.000000 0.000000 0.000000 0.000000 
0.000000 -3.000000 0.000000 0.000000 
0.000000 0.000000 5.000000 0.000000 
0.000000 0.000000 0.000000 1.000000 

1.000000 0.000000 0.000000 0.000000 
0.000000 0.866025 -0.500000 0.000000 
0.000000 0.500000 0.866025 0.000000 
0.000000 0.000000 0.000000 1.000000 

0.866025 -0.500000 0.000000 0.000000 
0.500000 0.866025 0.000000 0.000000 
0.000000 0.000000 1.000000 0.000000 
0.000000 0.000000 0.000000 1.000000 

1.000000 0.000000 0.000000 1.000000 
0.000000 1.000000 0.000000 2.000000 
0.000000 0.000000 1.000000 3.000000 
0.000000 0.000000 0.000000 1.000000 

4.732051 4.000000 4.196152