1.二维观察(三角形)
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
/* 初始化显示窗口大小 */
GLsizei winWidth = 600, winHeight = 600;
/* 设置世界坐标系的显示范围 */
GLfloat xwcMin = 0.0, xwcMax = 225.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;
/* 定义二维点数据结构 */
//class wcPt2D
//{
//public:
// GLfloat x, y;
//};
struct wcPt2D
{
GLfloat x, y;
};
typedef GLfloat Matrix3x3[3][3];
Matrix3x3 matComposite; //定义复合矩阵
const GLdouble pi = 3.14159;
void init(void)
{
/* 设置显示窗口的背景颜色为白色 */
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); // 清空显示窗口
}
/* 构建3*3的单位矩阵 */
void matrix3x3SetIdentity(Matrix3x3 matIdent3x3)
{
GLint row, col;
for (row = 0; row < 3; row++)
for (col = 0; col < 3; col++)
matIdent3x3[row][col] = (row == col);
}
/* 变换矩阵m1前乘矩阵m2,储存结果到m2中 */
void matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)
{
GLint row, col;
Matrix3x3 matTemp;
//矩阵乘法
for (row = 0; row < 3; row++)
for (col = 0; col < 3; col++)
matTemp[row][col] = m1[row][0] * m2[0][col] + m1[row][1] * m2[1][col] + m1[row][2] * m2[2][col];
//将矩阵matTemp复制进m2
for (row = 0; row < 3; row++)
for (col = 0; col < 3; col++)
m2[row][col] = matTemp[row][col];
}
/* 平移变换函数,平移量tx,ty */
void translate2D(GLfloat tx, GLfloat ty)
{
Matrix3x3 matTransl;
/* 初始化平移矩阵为单位矩阵 */