Represent a point by a column vector that is multiplied on its left by the current transformation matrix, MC.
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:
command | action |
---|---|
identity | set the current matrix, MC, to the identity |
print current matrix, MC | |
transform <x> <y> <z> | transform point, P = [x,y,z], by the current matrix P' = MC*P and print the transformed point, P' |
rotate [x|y|z] <degrees> | form the appropriate rotation matrix, MR, and multiply the current matrix on the left: MC = MR*MC |
translate <tx> <ty> <tz> | form appropriate translation matrix, MT, and multiply the current matrix on the left: MC = MT*MC |
scale <sx> <sy> <sz> | form appropriate scale matrix, MS, and multiply the current matrix on the left: MC = MS*MC |
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 Mc[2][4][4]; int c; c = 0; Mc[1-c] = m * Mc[c] // really a set of three nested loops c = 1-c
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
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. Note that 'make' without any arguments will make the first thing in the makefile:
make prog input.txt
In this example, the point command at the bottom would result in the point being translated first, and then rotated (note that this is not the same as OpenGL which reverses the order of the transformations).
identity print scale -4 2 1.5 print identity rotate x -60 print identity rotate z 20 print identity translate -1 2 2 print rotate y 30 print transform 3 2 4
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 -4.000000 0.000000 0.000000 0.000000 0.000000 2.000000 0.000000 0.000000 0.000000 0.000000 1.500000 0.000000 0.000000 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 0.000000 0.000000 0.500000 0.866025 0.000000 0.000000 -0.866025 0.500000 0.000000 0.000000 0.000000 0.000000 1.000000 0.939693 -0.342020 0.000000 0.000000 0.342020 0.939693 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 2.000000 0.000000 0.000000 0.000000 1.000000 0.866025 0.000000 0.500000 0.133975 0.000000 1.000000 0.000000 2.000000 -0.500000 0.000000 0.866025 2.232051 0.000000 0.000000 0.000000 1.000000 4.732050 4.000000 4.196153