📄 matrix.cpp
字号:
// Matrix.cpp : implementation file
//
#include "stdafx.h"
#include "PlayDraw.h"
#include "Matrix.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMatrix
CMatrix::~CMatrix()
{
}
//构造函数
//参数:二维矩阵数组
CMatrix::CMatrix(float x, float y)
{
Matrix[0][0]=x;
Matrix[1][0]=y;
Matrix[2][0]=1.0;
}
//旋转
//参数:int ox, int oy 旋转点, int ct 旋转角度
POINT CMatrix::Roat(float ox, float oy, float ct)
{
float r[3][3]={
{cos(ct),-sin(ct),0},
{sin(ct),cos(ct),0},
{0,0,1}
};
float result[3][1]={0,0,0};
Matrix[0][0]-=ox;
Matrix[1][0]-=oy;
MatMultiply( (float**)r, 3, 3, (float**)Matrix, 1, (float**)result );
Matrix[0][0]=result[0][0];
Matrix[1][0]=result[0][1];
Matrix[0][0]+=ox;
Matrix[1][0]+=oy;
POINT p;
p.x=Matrix[0][0];
p.y=Matrix[1][0];
return p;
}
//比例变换
//参数:int sx x轴比例系数, int sy y轴比例系数
POINT CMatrix::Resize(float sx, float sy)
{
Matrix[0][0]*=sx;
Matrix[1][0]*=sy;
POINT p;
p.x=Matrix[0][0];
p.y=Matrix[1][0];
return p;
}
//平移
//参数:int dx x轴偏移量, int dy y轴偏移量
POINT CMatrix::Move(float dx, float dy)
{
Matrix[0][0]+=dx;
Matrix[1][0]+=dy;
POINT p;
p.x=Matrix[0][0];
p.y=Matrix[1][0];
return p;
}
//对称
POINT CMatrix::Symmetry(float x, float y)
{
Matrix[0][0]=2*x-Matrix[0][0];
Matrix[1][0]=2*y-Matrix[1][0];
POINT p;
p.x=Matrix[0][0];
p.y=Matrix[1][0];
return p;
}
//矩阵相乘函数
void CMatrix::MatMultiply(float **a, int ay, int ax, float **b, int bx, float **c)
{
int i,j,k;
for(i=0;i<ay;++i)
{
for(j=0;j<bx;++j)
{
for(k=0;k<ax;++k)
{
*((float*)c + bx*i + j)+=(*((float*)a + ax*i + k))*(*((float*)b + bx*k + j));
}
}
}
}
BEGIN_MESSAGE_MAP(CMatrix, CEdit)
//{{AFX_MSG_MAP(CMatrix)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMatrix message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -