2D缩放的数学形式

游戏开发中的数学和物理算法(18):缩放
Sx代表x方向的缩放量,Sy代表y方向的缩放量。当Sx=Sy代表等比例缩放。

例如:将下图的矩形ABCD放大3倍。
游戏开发中的数学和物理算法(18):缩放
设A(10,10),那么缩放后的A',将通过下列计算获得A'(30,30)。
游戏开发中的数学和物理算法(18):缩放
同理可以计算出缩放后的B'(150,30), C'(150,120),和 D'(30,120)。如图:
游戏开发中的数学和物理算法(18):缩放
虚线框表示的为缩放前的图形,实线框表示为缩放后的图形。

2D缩放在计算机中的实现:

 dy)
{
         Matrix3X3 temp;
         Matrix3X1 result;

         //Zero out the matrix.
         temp = createFixed3X3Matrix(0);

         
//setup the 3x3 for multiplication;
         temp.index[0][0= dx;
         temp.index[
1][1= dy;
         temp.index[
2][2= 1;

         result 
= multiplyMatrixNxM(temp,start);
         
return result;
}

 

3D缩放的数学形式:

游戏开发中的数学和物理算法(18):缩放

3D缩放在计算机中的实现:

 dz)
{
         Matrix4X4 temp;
         Matrix4X1 result;

         //Zero out the matrix to make sure nothing is left uninitialized.
         temp = createFixed4X4Matrix(0);

         
//setup the 3x3 for multiplication;
         temp.index[0][0= dx;
         temp.index[
1][1= dy;
         temp.index[
2][2= dz;
         temp.index[
3][3= 1;

         result 
= multiplyMatrixNxM(temp,start);
         
return result;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案