資源簡(jiǎn)介
矩陣變換是進(jìn)行視圖操作的必須具備的知識(shí),在MFC,osg,opengGL中是不可或缺的技術(shù),本資源提供了最規(guī)范最健壯的矩陣變換類(lèi)。

代碼片段和文件信息
//?GeMatrix2d.cpp:?implementation?of?the?CGeMatrix2d?class.
//
//////////////////////////////////////////////////////////////////////
#include?“GeMatrix2d.h“
#include?
#include?
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
//?構(gòu)造函數(shù),初始化為單位矩陣
CGeMatrix2d::CGeMatrix2d()
{
memset(m_entry0sizeof(m_entry));
m_entry[0][0]?=?m_entry[1][1]?=?m_entry[2][2]?=?1.0;
}
//?拷貝構(gòu)造函數(shù)
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);
}
//?返回比例系數(shù),為矩陣列線(xiàn)性部分向量中長(zhǎng)度最大的值
double?CGeMatrix2d::scale(void)?const
{
//?上面注釋的部分和下面具有相同的效果,上面思路清晰,但是運(yùn)算中需要多次分配內(nèi)存
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?);
}
//?將矩陣設(shè)置為單位矩陣
CGeMatrix2d&??CGeMatrix2d::setToIdentity(void)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
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)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
setToIdentity();
m_entry[2][0]?=?dx;
m_entry[2][1]=?dy;
return?*this;
}
//?初始化為以坐標(biāo)原點(diǎn)為基點(diǎn)的旋轉(zhuǎn)變換矩陣,單位為弧度
CGeMatrix2d&?CGeMatrix2d::setToRotation?(double?angle)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
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;
}
//?初始化為以坐標(biāo)原點(diǎn)為基點(diǎn)的比例變換矩陣
CGeMatrix2d&?CGeMatrix2d::setToScaling??(double?scaleAll)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
m_entry[0][0]?=?m_entry[1][1]?=?scaleAll;
return?*this;
}
//?初始化為關(guān)于x軸對(duì)稱(chēng)的矩陣
CGeMatrix2d&?CGeMatrix2d::setToMirrorX??(void)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
m_entry[0][0]?=?1;
m_entry[1][1]?=?-1;
return?*this;
}
//?初始化為關(guān)于Y軸對(duì)稱(chēng)的矩陣
CGeMatrix2d&?CGeMatrix2d::setToMirrorY??(void)
{
//?*!*?實(shí)現(xiàn)該函數(shù)
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;
}
//?-----------------------------------------------------------------------------
//
//
//
//?構(gòu)造函數(shù)
CGePoint2d::CGePoint2d()
{
m_dat[0]?=?m_dat[1]?=?0;
}
CGePoint2d::CGePoint2d(double?xdouble?y)
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件??????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
評(píng)論
共有 條評(píng)論