1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
DrawStuffs()
{
Matrix4 rz; // current rotation matrix about z axis
static Matrix4 c; // composition matrix
// set up the original points for the triangle
pts[0].set( 50, 50, 0);
pts[1].set(100, 100, 0);
pts[2].set(100, 0, 0);
rz.makeTranslationMatrix(-(pts[0].x = 50), -(pts[0].y = 50), pts[0].z = 0);
rz.makeRotationMatrixZ(angle);
// update the composite matrix
c = Multiply(rz, c);
// transform the original triangle points into the new points for drawing
for (int i=0; i < 3; i++) {
newPts[i] = Multiply(c, pts[i]); // Get new set of coordinates by multiplying for each iteration.
// translate position for each vertex
rz.makeTranslationMatrix(-(pts[i].x), -(pts[i].y), -(pts[i].z));
rz.makeRotationMatrixY(angle);
rz.makeTranslationMatrix(pts[i].x, pts[i].y, pts[i].z);
}
rz.makeTranslationMatrix(newPts[0].x = 50, newPts[0].y = 50, newPts[0].z = 0);
// draw the triangle lines 0-1, 1-2, 2-0
DrawLine(newPts[0].x, newPts[0].y, newPts[1].x, newPts[1].y, green);
DrawLine(newPts[1].x, newPts[1].y, newPts[2].x, newPts[2].y, green);
DrawLine(newPts[2].x, newPts[2].y, newPts[0].x, newPts[0].y, green);
// draw the points
PGraphics->Draw();
}
|