For next week I want you to do two things:
int faces[M*N][4]
and an array of
double vertices[(M+1)*(N+1)][6]
.
As we discussed in class, face (i,j) indexes vertices by
[ j * (M+1) + i , j * (M+1) + i+1 , (j+1) * (M+1) + i+1 , (j+1) * (M+1) + i ]
and where
u = (double)i / M; v = (double)j / N;
You will want to implement a matrix
stack to do this, which is just an array of
matrices
Matrix stack[];
,
initialized to
stack[0].identity();
,
as well as a top pointer int top
initialized to
top = 0.
All your
translate
,
rotate
,
scale
,
and
transform
methods should access
the matrix stack[top]
currently at the top of the matrix stack,
and you'll need to implement two
additional methods:
As we discussed on Monday,
an example of using push
and
pop
methods can be
seen on-line at:
http://mrl.nyu.edu/~perlin/swinging_arm/.
A note about perspective:
As we discussed in class today, you can implement perspective (assuming that the camera is at the origin (0,0,0)) by the transformation:
(x,y,z) → ( fx/z , fy/z, 1/z )
where f is the negative value of z representing the distance from the camera at which objects will appear neither magnified nor reduced in size. A larger magnitude of f results in a telephoto view; A smaller magnitude of f results in a wide angle view.
After you have applied the perspective transformation, then you can apply the viewport transformation to convert x and y into pixels.
There's always room for JelloTM:
The little interactive example that we worked through in class is available on-line at:
http://mrl.nyu.edu/~perlin/a_test/