|
|
想自己写矩阵旋转,可是比dx的相差了一倍,为什么啊??能不能帮忙看看差别:
//定义SinCos函数: 同时计算sin(Angle)和cos(Angle)的内嵌x86汇编函数
void __declspec(naked) __stdcall SinCos(const double Angle,double& sina,double& cosa)
{
asm
{
fld qword ptr [esp+4]//Angle
mov eax,[esp+12]//&sina
mov edx,[esp+16]//&cosa
fsincos
fstp qword ptr [edx]
fstp qword ptr [eax]
ret 16
}
}
//这个是结构,省略了些
struct XMatrix44
{
union{
struct {
float _00, _01, _02, _03;
float _10, _11, _12, _13;
float _20, _21, _22, _23;
float _30, _31, _32, _33;
};
float x[4][4];
};
void rotateX(double rad)
{
double s,c;
SinCos(rad,s,c);
_11=(float)s;
_12=(float)c;
_21=-_12;
_22=_11;
_00=_33=1;
}
};
void testd3d()
{
D3DXVECTOR3 vec(1,1,1),vec1;
D3DXMATRIX mx;
for (int i=0;i<2000000;i++)
{
D3DXMatrixRotationX(&mx,i*X_ONERAD);
}
}
void test3dx()
{
XVec3 vec(1,1,1),vec1(vec);
XMatrix44 mxz;
float ss;
for (int i=0;i<2000000;i++)
{
mxz.rotateX(i*X_ONERAD);
}
}
void main()
{
testd3d();
test3dx();
}
|
|