opengl二维观察复合变换(三角形) 三维观察(矩形)

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;
	/* 初始化平移矩阵为单位矩阵 */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值