点的平移,可以通过矩阵相加相乘来模拟。

游戏开发中的数学和物理算法(17):平移

2D加法平移:

游戏开发中的数学和物理算法(17):平移

例如:
点A(20,30),向右移50个像素,向下移100个像素,得到A'。
游戏开发中的数学和物理算法(17):平移
那么A'(70,-70)。

3D加法平移:
游戏开发中的数学和物理算法(17):平移

例如:
游戏开发中的数学和物理算法(17):平移

计算机中实现:

Matrix3X1 translate3DByAddition(Matrix3X1 start, Matrix3X1 trans)
{
      Matrix3X1 temp;
      temp = addMatrices(start,trans);
      
return temp;
}

 

2D乘法平移:

游戏开发中的数学和物理算法(17):平移

例如:
游戏开发中的数学和物理算法(17):平移

计算机中的实现:

 dy)
{
         Matrix3X3 temp;
         Matrix3X1 result;

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

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

         
//put in the translation amount
         temp.index[0][2= dx;
         temp.index[
1][2= dy;

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

 

3D乘法平移:

游戏开发中的数学和物理算法(17):平移

例如:
游戏开发中的数学和物理算法(17):平移

计算机中的实现:

 dz)
{

         Matrix4X4 temp;
         Matrix4X1 result;

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

         
//setup the 4X4 for multiplication;
         temp.index[0][0= 1;
         temp.index[
1][1= 1;
         temp.index[
2][2= 1;
         temp.index[
3][3= 1;

         
//put in the translation amount
         temp.index[0][3= dx;
         temp.index[
1][3= dy;
         temp.index[
2][3= dz;

         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
相关资源
相似解决方案