资源简介
用C++编制的一个将三角形在二维平面进行复合矩阵变换的小程序,包括缩放,平移和旋转的复合变换

代码片段和文件信息
#include
#include
#include
/*Set initial display-window size.*/
GLsizei winWidth=600winHeight=600;
/*Set range for world coordinates.*/
GLfloat xwcMin=0.0xwcMax=225.0;
GLfloat ywcMin=0.0ywcMax=225.0;//10
class wcPt2D{
public:
GLfloat xy;
};
typedef GLfloat Matrix3x3 [3][3];
Matrix3x3 matComposite;
//20
const GLfloat pi=3.14159;
void init (void)
{
/*Set color of display window to white.*/
glClearColor (1.01.01.00.0);
}
/*Constract the 3 by 3 identity matrix.*/
void matrix3x3SetIdentity(Matrix3x3 matIdent3x3)//30
{
GLint rowcol;
for(row=0;row<3;row++)
for(col=0;col<3;col++)
matIdent3x3[row][col]=(row==col);
}
/*Premultiply matrix m1 times m2 store result in m2.*/
void matrix3x3PreMultiply(Matrix3x3 m1Matrix3x3 m2)//40
{
GLint rowcol;
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];
for(row=0;row<3;row++)
for(col=0;col<3;col++)//50
m2[row][col]=matTemp[row][col];
}
void translate2D(GLfloat tx GLfloat ty)
{
Matrix3x3 matTransl;
/*Intialize translation matrix to identity.*/
matrix3x3SetIdentity(matTransl);
//60
matTransl[0][2]=tx;
matTransl[1][2]=ty;
/*Concatenate matTransl with the composite matrix.*/
matrix3x3PreMultiply(matTransl matComposite);
}
void rotate2D(wcPt2D pivotPt GLfloat theta)
{
Matrix3x3 matRot;//70
/*Initialize rotation matrix to identy.*/
matrix3x3SetIdentity(matRot);
matRot[0][0]=cos(theta);
matRot[0][1]=-sin(theta);
matRot[0][2]=pivotPt.x*(1-cos(theta))+pivotPt.y*sin(theta);
matRot[1][0]=sin(theta);
matRot[1][1]=cos(theta);//80
matRot[1][2]=pivotPt.y*(1-cos(theta))-pivotPt.x*sin(theta);
/*Concatenate matRot with the composite matrix.*/
matrix3x3PreMultiply(matRot matComposite);
}
void scale2D(GLfloat sxGLfloat sywcPt2D fixedPt)
{
Matrix3x3 matScale;
//90
/*Initialize scaling matrix to identity.*/
matrix3x3SetIdentity(matScale);
matScale[0][0]=sx;
matScale[0][2]=(1-sx)*fixedPt.x;
matScale[1][1]=-sy;
matScale[1][2]=(1-sy)*fixedPt.y;
/*Concatenate matScale with the composite matrix.*/
matrix3x3PreMultiply(matScale matComposite);//100
}
/*Using the composite matrix calculate transformed coordinates.*/
void transformVerts2D(GLint nVerts wcPt2D *verts)
{
GLint k;
GLfloat temp;
for(k=0;k temp=matComposite[0][0]*verts[k].x+matComposite[0][1]*verts[k].y+matComposite[0][2];//110
verts[k].y=matComposite[1][0]*verts[k].x+matComposite[1][1]*verts[k].y+matComposite[1][2];
verts[k].x=temp;
}
}
void triangle(wcPt2D *verts)
{
GLint k;
glBegin(GL_TRIANGLES);//120
for(k=0;k<3;k++)
glVertex2f(verts[k].xverts[k].y);
glEnd();
}
void displayFcn(void)
{
/*Define initial position for triangle*/
GLint nVerts=3;
wcPt2D verts[3]={{50.025.0}{150.025.0}{100.0100.0}};//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4518 2011-10-15 21:50 5_4_11二维复合矩阵编程实例\5_4_11二维复合矩阵编程实例.dsp
文件 560 2011-10-15 20:25 5_4_11二维复合矩阵编程实例\5_4_11二维复合矩阵编程实例.dsw
文件 41984 2011-10-15 21:51 5_4_11二维复合矩阵编程实例\5_4_11二维复合矩阵编程实例.ncb
文件 53760 2011-10-15 21:51 5_4_11二维复合矩阵编程实例\5_4_11二维复合矩阵编程实例.opt
文件 984 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\5_4_11二维复合矩阵编程实例.plg
文件 204932 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\Debug\5_4_11二维复合矩阵编程实例.exe
文件 221108 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\Debug\5_4_11二维复合矩阵编程实例.ilk
文件 345960 2011-10-15 21:30 5_4_11二维复合矩阵编程实例\Debug\5_4_11二维复合矩阵编程实例.pch
文件 369664 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\Debug\5_4_11二维复合矩阵编程实例.pdb
文件 41984 2011-10-15 21:46 5_4_11二维复合矩阵编程实例\Debug\vc60.idb
文件 45056 2011-10-15 21:43 5_4_11二维复合矩阵编程实例\Debug\vc60.pdb
文件 13507 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\Debug\三角形旋转缩放平移.obj
文件 4737 2011-10-15 21:43 5_4_11二维复合矩阵编程实例\三角形旋转缩放平移.cpp
文件 4737 2011-10-15 21:44 5_4_11二维复合矩阵编程实例\新建 文本文档.txt
目录 0 2011-10-15 21:45 5_4_11二维复合矩阵编程实例\Debug
目录 0 2011-10-15 21:51 5_4_11二维复合矩阵编程实例
----------- --------- ---------- ----- ----
1353491 16
- 上一篇:影碟出租管理系统C语言编写 用于课程设计
- 下一篇:C++的库函数
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 基于STM32F103ZET6控制舵机旋转(ts90a/
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
评论
共有 条评论