遊戲開發中的數學和物理算法(16):矩陣的乘法

遊戲開發中的數學和物理算法(16):矩陣的乘法

矩陣數乘數學形式:

計算機中矩陣數乘的實現:
矩陣數乘
Matrix3X3 scalarMultiply(Matrix3X3 a, float scale)
{
      Matrix3X3 temp;
      for(int i = 0;i<3;i++)
      {
        for(int j=0;j<3;j++)
        {
           temp.index[i][j] = (a.index[i][j] * scale);
        }
      }
      return temp;
}

矩陣的乘法:

計算機中矩陣乘法的實現:
矩陣乘法
Matrix3X1 multiplyMatrixNxM(Matrix3X3 a, Matrix3X1 b)
{
        Matrix3X1 temp;
        temp.index[0] = 0.0f;
        temp.index[1] = 0.0f;
        temp.index[2] = 0.0f;
        for(int i=0;i<3;i++)
        {
              for(int j=0;j<3;j++)
              {
                 temp.index[i] += (a.index[i][j] * b.index[j]);
              }
        }
        return temp;
}


發佈了7 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章