资源简介
矩阵变换是进行视图操作的必须具备的知识,在MFC,osg,opengGL中是不可或缺的技术,本资源提供了最规范最健壮的矩阵变换类。

代码片段和文件信息
// GeMatrix2d.cpp: implementation of the CGeMatrix2d class.
//
//////////////////////////////////////////////////////////////////////
#include “GeMatrix2d.h“
#include
#include
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// 构造函数,初始化为单位矩阵
CGeMatrix2d::CGeMatrix2d()
{
memset(m_entry0sizeof(m_entry));
m_entry[0][0] = m_entry[1][1] = m_entry[2][2] = 1.0;
}
// 拷贝构造函数
CGeMatrix2d::CGeMatrix2d(const CGeMatrix2d& src)
{
int i = 0;
int j = 0;
for(i = 0; i<3; i++)
{
for(j = 0; j<3;j++)
{
m_entry[i][j] = src.m_entry[i][j];
}
}
}
CGeMatrix2d::~CGeMatrix2d()
{
}
// 矩阵乘法
CGeMatrix2d CGeMatrix2d::operator * (const CGeMatrix2d& mat) const
{
int ijk;
CGeMatrix2d m;
for(i=0; i<3;i++)
{
for(j=0; j<3; j++)
{
m.m_entry[i][j] = 0;
for(k=0;k<3;k++)
{
m.m_entry[i][j] = m.m_entry[i][j] + m_entry[i][k]*mat.m_entry[k][j];
}
}
}
return m;
}
CGeMatrix2d& CGeMatrix2d::operator *= (const CGeMatrix2d& mat)
{
(*this) = (*this) * mat;
return (*this);
}
// 返回比例系数,为矩阵列线性部分向量中长度最大的值
double CGeMatrix2d::scale(void) const
{
// 上面注释的部分和下面具有相同的效果,上面思路清晰,但是运算中需要多次分配内存
double len1 = sqrt(m_entry[0][0]*m_entry[0][0] + m_entry[0][1]*m_entry[0][1] );
double len2 = sqrt(m_entry[1][0]*m_entry[1][0] + m_entry[1][1]*m_entry[1][1] );
return ( (len1>len2)? len1 : len2 );
}
// 将矩阵设置为单位矩阵
CGeMatrix2d& CGeMatrix2d::setToIdentity(void)
{
// *!* 实现该函数
memset(m_entry0sizeof(m_entry));
m_entry[0][0] = m_entry[1][1] = m_entry[2][2] = 1.0;
return *this;
}
// 初始化为平移变换矩阵
CGeMatrix2d& CGeMatrix2d::setToTranslation(double dx double dy)
{
// *!* 实现该函数
setToIdentity();
m_entry[2][0] = dx;
m_entry[2][1]= dy;
return *this;
}
// 初始化为以坐标原点为基点的旋转变换矩阵,单位为弧度
CGeMatrix2d& CGeMatrix2d::setToRotation (double angle)
{
// *!* 实现该函数
m_entry[0][0] = cos(angle);
m_entry[0][1] = sin(angle);
m_entry[1][0] = -sin(angle);
m_entry[1][1] = cos(angle);
return *this;
}
// 初始化为以坐标原点为基点的比例变换矩阵
CGeMatrix2d& CGeMatrix2d::setToScaling (double scaleAll)
{
// *!* 实现该函数
m_entry[0][0] = m_entry[1][1] = scaleAll;
return *this;
}
// 初始化为关于x轴对称的矩阵
CGeMatrix2d& CGeMatrix2d::setToMirrorX (void)
{
// *!* 实现该函数
m_entry[0][0] = 1;
m_entry[1][1] = -1;
return *this;
}
// 初始化为关于Y轴对称的矩阵
CGeMatrix2d& CGeMatrix2d::setToMirrorY (void)
{
// *!* 实现该函数
m_entry[0][0] = -1;
m_entry[1][1] = 1;
return *this;
}
const CGeMatrix2d & CGeMatrix2d::operator =(const CGeMatrix2d &t)
{
if(this == &t) { return *this;}
memcpy(this->m_entry t.m_entry sizeof(m_entry));
return *this;
}
// -----------------------------------------------------------------------------
//
//
//
// 构造函数
CGePoint2d::CGePoint2d()
{
m_dat[0] = m_dat[1] = 0;
}
CGePoint2d::CGePoint2d(double xdouble y)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17917 2010-04-03 21:38 test_matrix\Debug\GeMatrix2d.obj
文件 5556 2010-04-03 21:44 test_matrix\Debug\main.obj
文件 225362 2010-04-03 21:44 test_matrix\Debug\test_matrix.exe
文件 240632 2010-04-03 21:44 test_matrix\Debug\test_matrix.ilk
文件 206804 2010-04-03 21:39 test_matrix\Debug\test_matrix.pch
文件 500736 2010-04-03 21:44 test_matrix\Debug\test_matrix.pdb
文件 41984 2010-02-11 18:50 test_matrix\Debug\vc60.idb
文件 53248 2010-04-03 21:44 test_matrix\Debug\vc60.pdb
文件 4495 2010-04-03 21:38 test_matrix\GeMatrix2d.cpp
文件 2133 2006-10-23 16:01 test_matrix\GeMatrix2d.h
文件 816 2010-04-03 21:44 test_matrix\main.cpp
文件 4469 2006-10-23 10:52 test_matrix\test_matrix.dsp
文件 545 2006-10-23 09:21 test_matrix\test_matrix.dsw
文件 50176 2010-03-14 15:52 test_matrix\test_matrix.ncb
文件 53760 2010-03-14 15:52 test_matrix\test_matrix.opt
文件 256 2010-02-11 18:50 test_matrix\test_matrix.plg
文件 258 2010-03-14 15:52 test_matrix\test_matrix.positions
文件 2560 2010-03-18 09:23 test_matrix\test_matrix.suo
目录 0 2011-01-05 18:52 test_matrix\Debug
目录 0 2011-01-05 18:52 test_matrix
----------- --------- ---------- ----- ----
1411707 20
相关资源
- 基于STM32F103ZET6控制舵机旋转(ts90a/
- MFC实现简易画图程序
- MFC 单文档 实现opengl 三维旋转 缩放
- MFC绘制的移动小车,包含了图形的平
- 24位BMP图像用C++实现平移、旋转、镜像
- MFC 图像处理之几何运算 图像平移旋转
- 图像按任意角度旋转C++
- C语言实现图像的旋转缩放裁切
- VC C++数字图像处理实验程序
- 3D图形旋转
- MFC制作的风车可以控制叶片大小和旋
- mfc 实现画矩形、椭圆等 并可对其进行
- OpenGL实现鼠标绕任意轴旋转/平移/缩放
- opengl光照旋转交互
- mfc 二维图形的变换 旋转 平移 比例
- 计算机图形学实验代码包括图形旋转
- 数字图像处理实习程序
- 旋转和移动的三维sierpinski镂垫
- GDI+绘制矩形,并且实现可旋转、缩放
- opengl在MFC平台上绘制三维图形并实现
- 基于mfc中opengl鼠标控制视图旋转缩放
- opengl实现导入正方体obj文件+旋转+平移
- c++ 旋转的圆柱
- c++ 图像处理(旋转、水平镜像等)
- OpenGL+MFC实现旋转、缩放、平移
- C++方式实现stl、obj、3DS三种3D模型加载
- DX绘制三维旋转的立方体
- 程序:四元数欧拉角旋转向量旋转矩
- c语言实现图像的旋转与平移
- 模拟卫星旋转和地球自转
评论
共有 条评论