⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsp1.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    ScreenX = Op02FX + ViewerX1 * (Op02LES - Op02LFE);    ScreenY = Op02FY + ViewerY1 * (Op02LES - Op02LFE);    ScreenZ = Op02FZ + ViewerZ1 * (Op02LES - Op02LFE);    if (ViewerZ1 == 0)	ViewerZ1++;    NumberOfSlope = ViewerZ / -ViewerZ1;    Op02CX = int16(ViewerX + ViewerX1 * NumberOfSlope);    Op02CY = int16(ViewerY + ViewerY1 * NumberOfSlope);    Op02CXF = int16(ViewerX + ViewerX1 * NumberOfSlope);    Op02CYF = int16(ViewerY + ViewerY1 * NumberOfSlope);    Op02VOF = 0x0000;    if (Op02LFE == 0x2200)	Op02VVA = (int16) 0xFECD;    else	Op02VVA = (int16) 0xFFB2;}#if 0void DSPOp0A (){    if (Op0AVS == 0)	Op0AVS++;// The view angle with a rotation of 3/4 (pointing up screen i think)    ViewerAY = ((128 + (Op02AZS / 256) + 192)) & 255;	// X/Z    ViewerAZ = ((128 + (Op02AAS / 256))) & 255;		// X/Y    ViewerX0 = (-SinTable[(int32) ViewerAY]);    ScreenLX1 = (ViewerX0 * -SinTable[ViewerAZ]) / 65536;    ScreenLY1 = (ViewerX0 * CosTable[ViewerAZ]) / 65536;    ScreenLZ1 = (CosTable[ViewerAY]);// The left/right points after the up/down move    RasterRX = RasterLX = ScreenX + (Op0AVS) * ScreenLX1 / 65536;    RasterRY = RasterLY = ScreenY + (Op0AVS) * ScreenLY1 / 65536;    RasterRZ = RasterLZ = ScreenZ + (Op0AVS) * ScreenLZ1 / 65536;// The angle to move right    ViewerAZ = (128 + (Op02AAS / 256) + 64) & 255;	// X/Y    ScreenLX1 = (-SinTable[ViewerAZ]);    ScreenLY1 = (CosTable[ViewerAZ]);// (move left, -112 in the right direction)    RasterLX = RasterLX - 112 * ScreenLX1 / 65536;    RasterLY = RasterLY - 112 * ScreenLY1 / 65536;// move right, 112 in the right direction)    RasterRX = RasterRX + 112 * ScreenLX1 / 65536;    RasterRY = RasterRY + 112 * ScreenLY1 / 65536;// The left/right point on the screen after going right/left    Distance = Op02LFE;    if (Distance == 0)	Distance = 1;// The slope to go to the ground (the R/L were on the screen)    RasterLSlopeX = 65536 * (RasterLX - ViewerX) / Distance;    RasterLSlopeY = 65536 * (RasterLY - ViewerY) / Distance;    RasterLSlopeZ = 65536 * (RasterLZ - ViewerZ) / Distance;    RasterRSlopeX = 65536 * (RasterRX - ViewerX) / Distance;    RasterRSlopeY = 65536 * (RasterRY - ViewerY) / Distance;    RasterRSlopeZ = 65536 * (RasterRZ - ViewerZ) / Distance;    if (RasterLSlopeZ == 0)	RasterLSlopeZ++;    NumberOfSlope = ViewerZ * 65536 / -RasterLSlopeZ;    GroundLX = ViewerX * 65536 + RasterLSlopeX * NumberOfSlope;    GroundLY = ViewerY * 65536 + RasterLSlopeY * NumberOfSlope;    if (RasterRSlopeZ == 0)	RasterRSlopeZ++;    NumberOfSlope = ViewerZ * 65536 / -RasterRSlopeZ;// The position of the left/right point on the ground    GroundRX = ViewerX * 65536 + RasterRSlopeX * NumberOfSlope;    GroundRY = ViewerY * 65536 + RasterRSlopeY * NumberOfSlope;    Op0AA = (int16) ((GroundRX - GroundLX) / 65536); // / 2    Op0AB = (int16) ((GroundRY - GroundLY) / 65536 / 2);    Op0AC = (int16) ((((Op02CXF * 65536) - (GroundRX + GroundLX) / 2)) / (-(Op0AVS) * 256));    Op0AD = (int16) ((((Op02CYF * 65536) - (GroundRY + GroundLY) / 2)) / (-(Op0AVS) * 256));    Op0AVS += 1;}#elsevoid DSPOp0A (){    if (Op0AVS == 0)	Op0AVS = 1;    ScreenLZ1 = -cos ((Op02AZS - 16384.0) * 6.2832 / 65536.0);    ScreenLX1 = sin ((Op02AZS - 16384.0) * 6.2832 / 65536.0) *	       -sin (Op02AAS * 6.2832 / 65536.0);    ScreenLY1 = -sin ((Op02AZS - 16384.0) * 6.2832 / 65536.0) *	        -cos (-Op02AAS * 6.2832 / 65536.0);    RasterRX = RasterLX = ScreenX + Op0AVS * ScreenLX1;    RasterRY = RasterLY = ScreenY + Op0AVS * ScreenLY1;    RasterRZ = RasterLZ = ScreenZ + Op0AVS * ScreenLZ1;    ScreenLX1 = sin ((Op02AAS + 16384.0) * 6.2832 / 65536);    ScreenLY1 = cos (-(Op02AAS + 16384.0) * 6.2832 / 65536);    RasterLX = RasterLX - 128 * ScreenLX1;    RasterLY = RasterLY - 128 * ScreenLY1;    RasterRX = RasterRX + 128 * ScreenLX1;    RasterRY = RasterRY + 128 * ScreenLY1;    Distance = Op02LFE;    if (Distance == 0)	Distance = 1;    RasterLSlopeX = (RasterLX - ViewerX) / Distance;    RasterLSlopeY = (RasterLY - ViewerY) / Distance;    RasterLSlopeZ = (RasterLZ - ViewerZ) / Distance;    RasterRSlopeX = (RasterRX - ViewerX) / Distance;    RasterRSlopeY = (RasterRY - ViewerY) / Distance;    RasterRSlopeZ = (RasterRZ - ViewerZ) / Distance;    if (RasterLSlopeZ == 0)	RasterLSlopeZ++;    NumberOfSlope = ViewerZ / -RasterLSlopeZ;    GroundLX = ViewerX + RasterLSlopeX * NumberOfSlope;    GroundLY = ViewerY + RasterLSlopeY * NumberOfSlope;    if (RasterRSlopeZ == 0)	RasterRSlopeZ++;    NumberOfSlope = ViewerZ / -RasterRSlopeZ;    GroundRX = ViewerX + RasterRSlopeX * NumberOfSlope;    GroundRY = ViewerY + RasterRSlopeY * NumberOfSlope;    if (Op02LES == 0)	Op02LES = 1;    Op0AA = int16(GroundRX - GroundLX);    Op0AB = int16(GroundRY - GroundLY);    if (Op0AVS != 0)    {	Op0AC = int16((((Op02CXF - ((GroundRX + GroundLX) / 2.0))) / Op0AVS) * 256.0);	Op0AD = int16((((Op02CYF - ((GroundRY + GroundLY) / 2.0))) / Op0AVS) * 256.0);    }    else    {	Op0AC = 256;	Op0AD = 256;    }    Op0AVS += 1;}#endifDSP1_Project::DSP1_Project (int16 x, int16 y, int16 z){    double X = double(x) - Op02CXF;    double Y = double(y) - Op02CYF;    double Z = double(z);    double X1;    double Y1;    double Z1;    double X2;    double Y2;    double Z2;    double tempA;     double cx;    double sx;    // AAS rotate around Z    tempA = (-Op02AAS + 32768) / 65536.0 * 6.2832;    cx = cos (tempA);    sx = sin (tempA);    X1 = (X * cx + Y * -sx);    Y1 = (X * sx + Y * cx);    Z1 = Z;    tempA = (-Op02AZS) / 65536.0 * 6.2832;    cx = cos (tempA);    sx = sin (tempA);    // AZS rotate around X    X2 = X1;    Y2 = (Y1 * cx +Z1 * -sx);    Z2 = (Y1 * sx +Z1 * cx);    Z2 = Z2 - Op02LFE;    if (Z2<0)    {	H = int16(-X2 * Op02LES / -(Z2));	V = int16(-Y2 * Op02LES / -(Z2));	M = int32(256.0 * Op02LES / -Z2);    }    else    {	H = 0;	V = 224;    } }void DSPOp1C(){    // rotate around Y    uint32 a = Op1CAY >> 8;    Op1CX1 = (Op1CX * CosTable2 [a] + Op1CZ * SinTable2 [a]) / 65536;    Op1CY1 = Op1CY;    Op1CZ1 = (Op1CX * -SinTable2 [a] + Op1CZ * CosTable2 [a]) / 65536;    // rotate around X    a = Op1CAX >> 8;    Op1CX2 = Op1CX1;    Op1CY2 = (Op1CY1 * CosTable2 [a] + Op1CZ1 * -SinTable2 [a]) / 65536;    Op1CZ2 = (Op1CY1 * SinTable2 [a] + Op1CZ1 * CosTable2[a]) / 65536;    // rotate around Z    a = Op1CAZ >> 8;    Op1CX3 = (Op1CX2 * CosTable2 [a] + Op1CY2 * -SinTable2 [a]) / 65536;    Op1CY3 = (Op1CX2 * SinTable2 [a] + Op1CY2 * CosTable2 [a]) / 65536;    Op1CZ3 = Op1CZ2;}static void InitMatrix (){    matrix[0][0]=1; matrix[0][1]=0; matrix[0][2]=0; matrix[0][3]=0;    matrix[1][0]=0; matrix[1][1]=1; matrix[1][2]=0; matrix[1][3]=0;    matrix[2][0]=0; matrix[2][1]=0; matrix[2][2]=1; matrix[2][3]=0;    matrix[3][0]=0; matrix[3][1]=0; matrix[3][2]=0; matrix[3][3]=1;}static void MultMatrix(double result[4][4],double mat1[4][4],double mat2[4][4]){    result[0][0]=0;    result[0][0]+=(mat1[0][0]*mat2[0][0]+mat1[0][1]*mat2[1][0]+mat1[0][2]*mat2[2][0]+mat1[0][3]*mat2[3][0]);    result[0][1]=0;    result[0][1]+=(mat1[0][0]*mat2[0][1]+mat1[0][1]*mat2[1][1]+mat1[0][2]*mat2[2][1]+mat1[0][3]*mat2[3][1]);    result[0][2]=0;    result[0][2]+=(mat1[0][0]*mat2[0][2]+mat1[0][1]*mat2[1][2]+mat1[0][2]*mat2[2][2]+mat1[0][3]*mat2[3][2]);    result[0][3]=0;    result[0][3]+=(mat1[0][0]*mat2[0][3]+mat1[0][1]*mat2[1][3]+mat1[0][2]*mat2[2][3]+mat1[0][3]*mat2[3][3]);    result[1][0]=0;    result[1][0]+=(mat1[1][0]*mat2[0][0]+mat1[1][1]*mat2[1][0]+mat1[1][2]*mat2[2][0]+mat1[1][3]*mat2[3][0]);    result[1][1]=0;    result[1][1]+=(mat1[1][0]*mat2[0][1]+mat1[1][1]*mat2[1][1]+mat1[1][2]*mat2[2][1]+mat1[1][3]*mat2[3][1]);    result[1][2]=0;    result[1][2]+=(mat1[1][0]*mat2[0][2]+mat1[1][1]*mat2[1][2]+mat1[1][2]*mat2[2][2]+mat1[1][3]*mat2[3][2]);    result[1][3]=0;    result[1][3]+=(mat1[1][0]*mat2[0][3]+mat1[1][1]*mat2[1][3]+mat1[1][2]*mat2[2][3]+mat1[1][3]*mat2[3][3]);    result[2][0]=0;    result[2][0]+=(mat1[2][0]*mat2[0][0]+mat1[2][1]*mat2[1][0]+mat1[2][2]*mat2[2][0]+mat1[2][3]*mat2[3][0]);    result[2][1]=0;    result[2][1]+=(mat1[2][0]*mat2[0][1]+mat1[2][1]*mat2[1][1]+mat1[2][2]*mat2[2][1]+mat1[2][3]*mat2[3][1]);    result[2][2]=0;    result[2][2]+=(mat1[2][0]*mat2[0][2]+mat1[2][1]*mat2[1][2]+mat1[2][2]*mat2[2][2]+mat1[2][3]*mat2[3][2]);    result[2][3]=0;                        result[2][3]+=(mat1[2][0]*mat2[0][3]+mat1[2][1]*mat2[1][3]+mat1[2][2]*mat2[2][3]+mat1[2][3]*mat2[3][3]);    result[3][0]=0;    result[3][0]+=(mat1[3][0]*mat2[0][0]+mat1[3][1]*mat2[1][0]+mat1[3][2]*mat2[2][0]+mat1[3][3]*mat2[3][0]);    result[3][1]=0;    result[3][1]+=(mat1[3][0]*mat2[0][1]+mat1[3][1]*mat2[1][1]+mat1[3][2]*mat2[2][1]+mat1[3][3]*mat2[3][1]);    result[3][2]=0;    result[3][2]+=(mat1[3][0]*mat2[0][2]+mat1[3][1]*mat2[1][2]+mat1[3][2]*mat2[2][2]+mat1[3][3]*mat2[3][2]);    result[3][3]=0;    result[3][3]+=(mat1[3][0]*mat2[0][3]+mat1[3][1]*mat2[1][3]+mat1[3][2]*mat2[2][3]+mat1[3][3]*mat2[3][3]);}static void CopyMatrix(double dest[4][4],double source[4][4]){    dest[0][0]=source[0][0];    dest[0][1]=source[0][1];    dest[0][2]=source[0][2];    dest[0][3]=source[0][3];    dest[1][0]=source[1][0];    dest[1][1]=source[1][1];    dest[1][2]=source[1][2];    dest[1][3]=source[1][3];    dest[2][0]=source[2][0];    dest[2][1]=source[2][1];    dest[2][2]=source[2][2];    dest[2][3]=source[2][3];    dest[3][0]=source[3][0];    dest[3][1]=source[3][1];    dest[3][2]=source[3][2];    dest[3][3]=source[3][3];}static void scale(double sf){    double mat[4][4];    smat[0][0]=sf; smat[0][1]=0; smat[0][2]=0; smat[0][3]=0;    smat[1][0]=0; smat[1][1]=sf; smat[1][2]=0; smat[1][3]=0;    smat[2][0]=0; smat[2][1]=0; smat[2][2]=sf; smat[2][3]=0;    smat[3][0]=0; smat[3][1]=0; smat[3][2]=0; smat[3][3]=1;    MultMatrix(mat,smat,matrix);    CopyMatrix(matrix,mat);}static void translate(double xt,double yt,double zt){    double mat[4][4];    tmat[0][0]=1; tmat[0][1]=0; tmat[0][2]=0; tmat[0][3]=0;    tmat[1][0]=0; tmat[1][1]=1; tmat[1][2]=0; tmat[1][3]=0;    tmat[2][0]=0; tmat[2][1]=0; tmat[2][2]=1; tmat[2][3]=0;    tmat[3][0]=xt; tmat[3][1]=yt; tmat[3][2]=zt; tmat[3][3]=1;    MultMatrix(mat,matrix,tmat);    CopyMatrix(matrix,mat);}static void rotate(double ax,double ay,double az){    double mat1[4][4];    double mat2[4][4];    xmat[0][0]=1; xmat[0][1]=0; xmat[0][2]=0; xmat[0][3]=0;    xmat[1][0]=0; xmat[1][1]=cos(ax); xmat[1][2]=sin(ax); xmat[1][3]=0;    xmat[2][0]=0; xmat[2][1]=-(sin(ax)); xmat[2][2]=cos(ax); xmat[2][3]=0;    xmat[3][0]=0; xmat[3][1]=0; xmat[3][2]=0; xmat[3][3]=1;    MultMatrix(mat1,xmat,matrix);    ymat[0][0]=cos(ay); ymat[0][1]=0; ymat[0][2]=-(sin(ay)); ymat[0][3]=0;    ymat[1][0]=0; ymat[1][1]=1; ymat[1][2]=0; ymat[1][3]=0;    ymat[2][0]=sin(ay); ymat[2][1]=0; ymat[2][2]=cos(ay); ymat[2][3]=0;    ymat[3][0]=0; ymat[3][1]=0; ymat[3][2]=0; ymat[3][3]=1;    MultMatrix(mat2,ymat,mat1);    zmat[0][0]=cos(az); zmat[0][1]=sin(az); zmat[0][2]=0; zmat[0][3]=0;    zmat[1][0]=-(sin(az)); zmat[1][1]=cos(az); zmat[1][2]=0; zmat[1][3]=0;    zmat[2][0]=0; zmat[2][1]=0; zmat[2][2]=1; zmat[2][3]=0;    zmat[3][0]=0; zmat[3][1]=0; zmat[3][2]=0; zmat[3][3]=1;    MultMatrix(matrix,zmat,mat2);}void DSPOp01(){    InitMatrix();    rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832);    CopyMatrix(matrix0,matrix);    InitMatrix();    rotate(0,0,Op01Zr/65536.0*6.2832);    rotate(Op01Xr/65536.0*6.2832,0,0);    rotate(0,Op01Yr/65536.0*6.2832,0);    CopyMatrix(matrixI0,matrix);}void DSPOp11 (){    InitMatrix();    rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832);    CopyMatrix(matrix1,matrix);    InitMatrix();    rotate(0,0,Op01Zr/65536.0*6.2832);    rotate(Op01Xr/65536.0*6.2832,0,0);    rotate(0,Op01Yr/65536.0*6.2832,0);    CopyMatrix(matrixI1,matrix);}void DSPOp21 (){    InitMatrix();    rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832);    CopyMatrix(matrix2,matrix);    InitMatrix();    rotate(0,0,Op01Zr/65536.0*6.2832);    rotate(Op01Xr/65536.0*6.2832,0,0);    rotate(0,Op01Yr/65536.0*6.2832,0);    CopyMatrix(matrixI2,matrix);}void DSPOp0D (){    Op0DF=(int32)((Op0DX*matrixI0[0][0]+Op0DY*matrixI0[1][0]+Op0DZ*matrixI0[2][0]+matrixI0[3][0]) / 2);    Op0DL=(int32)((Op0DX*matrixI0[0][1]+Op0DY*matrixI0[1][1]+Op0DZ*matrixI0[2][1]+matrixI0[3][1]) / 2);    Op0DU=(int32)((Op0DX*matrixI0[0][2]+Op0DY*matrixI0[1][2]+Op0DZ*matrixI0[2][2]+matrixI0[3][2]) / 2);}void DSPOp1D (){    Op0DF=(int32)((Op0DX*matrixI1[0][0]+Op0DY*matrixI1[1][0]+Op0DZ*matrixI1[2][0]+matrixI1[3][0]) / 2);    Op0DL=(int32)((Op0DX*matrixI1[0][1]+Op0DY*matrixI1[1][1]+Op0DZ*matrixI1[2][1]+matrixI1[3][1]) / 2);    Op0DU=(int32)((Op0DX*matrixI1[0][2]+Op0DY*matrixI1[1][2]+Op0DZ*matrixI1[2][2]+matrixI1[3][2]) / 2);}void DSPOp2D (){    Op0DF=(int32)((Op0DX*matrixI2[0][0]+Op0DY*matrixI2[1][0]+Op0DZ*matrixI2[2][0]+matrixI2[3][0]) / 2);    Op0DL=(int32)((Op0DX*matrixI2[0][1]+Op0DY*matrixI2[1][1]+Op0DZ*matrixI2[2][1]+matrixI2[3][1]) / 2);    Op0DU=(int32)((Op0DX*matrixI2[0][2]+Op0DY*matrixI2[1][2]+Op0DZ*matrixI2[2][2]+matrixI2[3][2]) / 2);}void DSPOp03 (){    Op03X=(int32)(Op03F*matrix0[0][0]+Op03L*matrix0[1][0]+Op03U*matrix0[2][0]+matrix0[3][0]);    Op03Y=(int32)(Op03F*matrix0[0][1]+Op03L*matrix0[1][1]+Op03U*matrix0[2][1]+matrix0[3][1]);    Op03Z=(int32)(Op03F*matrix0[0][2]+Op03L*matrix0[1][2]+Op03U*matrix0[2][2]+matrix0[3][2]);}void DSPOp13 (){    Op03X=(int32)(Op03F*matrix1[0][0]+Op03L*matrix1[1][0]+Op03U*matrix1[2][0]+matrix1[3][0]);    Op03Y=(int32)(Op03F*matrix1[0][1]+Op03L*matrix1[1][1]+Op03U*matrix1[2][1]+matrix1[3][1]);    Op03Z=(int32)(Op03F*matrix1[0][2]+Op03L*matrix1[1][2]+Op03U*matrix1[2][2]+matrix1[3][2]);}void DSPOp23 (){    Op03X=(int32)(Op03F*matrix2[0][0]+Op03L*matrix2[1][0]+Op03U*matrix2[2][0]+matrix2[3][0]);    Op03Y=(int32)(Op03F*matrix2[0][1]+Op03L*matrix2[1][1]+Op03U*matrix2[2][1]+matrix2[3][1]);    Op03Z=(int32)(Op03F*matrix2[0][2]+Op03L*matrix2[1][2]+Op03U*matrix2[2][2]+matrix2[3][2]);}void DSPOp14 (){    double tmp;    tmp = (Op14Zr * 6.2832 / 65536.0) + 	   (1 / cos (Op14Xr * 6.2832 / 65536.0)) * 	  ((Op14U * 6.2832 / 65536.0) * 	   cos (Op14Yr * 6.2832 / 65536.0) - 	   (Op14F * 6.2832 / 65536.0) *	   sin (Op14Yr * 6.2832 / 65536.0));    Op14Zrr = (int32) (tmp*65536.0/6.2832);    tmp = (Op14Xr * 6.2832 / 65536.0) + 	  ((Op14U * 6.2832 /65536.0) * sin (Op14Yr * 6.2832 / 65536.0) +	   (Op14F * 6.2832 / 65536.0) * cos (Op14Yr * 6.2832 / 65536.0));    Op14Xrr = (int32) (tmp * 65536.0 / 6.2832);    tmp = (Op14Yr * 6.2832 / 65536.0) - 		tan (Op14Xr * 6.2832 / 65536.0) * 		((Op14U * 6.2832 / 65536.0) * 		 cos (Op14Yr * 6.2832 / 65536.0) +		 (Op14F * 6.2832 / 65536.0) *		 sin (Op14Yr * 6.2832 / 65536.0)) + (Op14L * 6.2832 / 65536.0);    Op14Yrr = (int32) (tmp * 65536.0 / 6.2832);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -