📄 draw.c
字号:
#include <assert.h>
#include "draw.h"
/* Local variables */
static MATRIX_4x4 te;
static MATRIX_4x4 projection;
/*
* Sets the window and the viewport.
*/
void DrawSetTransformation (const RECT *pWindow, const RECT *pViewport)
{
MATRIX_4x4 scale, translateInWnd, translateInView, temp;
assert (pWindow != NULL && pViewport != NULL);
/* Build the transformation matrixes */
MatrixTranslation (-pWindow->left, -pWindow->bottom, 0, translateInWnd);
MatrixScale ((pViewport->right - pViewport->left)/(pWindow->right - pWindow->left),
((pViewport->top - pViewport->bottom))/(pWindow->top - pWindow->bottom),
0,
scale);
MatrixTranslation (pViewport->left, pViewport->bottom, 0, translateInView);
/* Perform the multiplications */
MatrixMultiply (translateInView, scale, temp);
MatrixMultiply (temp, translateInWnd, te);
}
/*
* Sets the projection type
*/
void DrawSetProjection (const MATRIX_4x4 proj)
{
memcpy (projection, proj, sizeof (MATRIX_4x4));
}
/*
* Draws the object using the current projection
*/
void DrawObject (HDC hDC, const POBJECT_3D pObject)
{
int x1, y1, x2, y2, i, j;
PPOINT_3D pPoint;
MATRIX_4x4 matrix;
POBJECT_3D pTempObj;
assert (pObject != NULL);
MatrixMultiply (te, projection, matrix);
pTempObj = ObjectMultiply (pObject, matrix);
for (i = 0; i < pTempObj->cCols; i++)
for (j = 0; j < pTempObj->cRows; j++) {
pPoint = &pTempObj->ppPoints [i][j];
x1 = (int) pPoint->x;
y1 = (int) pPoint->y;
if (i + 1 < pTempObj->cCols) {
pPoint = &pTempObj->ppPoints [i + 1][j];
x2 = (int) pPoint->x;
y2 = (int) pPoint->y;
MoveToEx (hDC, x1, y1, NULL);
LineTo (hDC, x2, y2);
}
if (j - 1 >= 0) {
pPoint = &pTempObj->ppPoints [i][j - 1];
x2 = (int) pPoint->x;
y2 = (int) pPoint->y;
MoveToEx (hDC, x1, y1, NULL);
LineTo (hDC, x2, y2);
}
}
ObjectFree (pTempObj);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -