1.图形变换

  1. void translate3dMatrix(float Tx, float Ty, float Tz)
  2. {
  3. Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
  4. m_whoObject->transMatrix[3][0] += Tx;
  5. m_whoObject->transMatrix[3][1] += Ty;
  6. m_whoObject->transMatrix[3][2] += Tz;
  7. }
  1. void rotateX3Dmatrix(float S, float C)
  2. {
  3. Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
  4. for (int i = 0; i < 4; i++) {
  5. float temp;
  6. temp = m_whoObject->transMatrix[i][1] * C - m_whoObject->transMatrix[i][2] * S;
  7. m_whoObject->transMatrix[i][2] = m_whoObject->transMatrix[i][1] * S +
  8. m_whoObject->transMatrix[i][2] * C;
  9. m_whoObject->transMatrix[i][1] = temp;
  10. }
  11. }
  1. void rotateY3Dmatrix(float S, float C)
  2. {
  3. Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
  4. for (int i = 0; i < 4; i++) {
  5. float temp;
  6. temp = m_whoObject->transMatrix[i][0] * C + m_whoObject->transMatrix[i][2] * S;
  7. m_whoObject->transMatrix[i][2] = -m_whoObject->transMatrix[i][0] * S +
  8. m_whoObject->transMatrix[i][2] * C;
  9. m_whoObject->transMatrix[i][0] = temp;
  10. }
  11. }
  1. void rotateZ3Dmatrix(float S, float C)
  2. {
  3. Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
  4. for (int i = 0; i < 4; i++) {
  5. float temp;
  6. temp = m_whoObject->transMatrix[i][0] * C - m_whoObject->transMatrix[i][1] * S;
  7. m_whoObject->transMatrix[i][1] = m_whoObject->transMatrix[i][0] * S +
  8. m_whoObject->transMatrix[i][1] * C;
  9. m_whoObject->transMatrix[i][0] = temp;
  10. }
  11. }

2.空间变换

  1. void TransSpaceObject()
  2. {
  3. Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
  4. // First Trans Object according to its matrix
  5. for (int i = 0; i < m_whoObject->polyCount; i++) {
  6. for (int j = 0; j < m_whoObject->objectSpace[i].polyCount; j++) {
  7. m_whoObject->objectSpace[i].transObject[j].x =
  8. m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][0]+
  9. m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][0]+
  10. m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][0]+
  11. m_whoObject->transMatrix[3][0];
  12. m_whoObject->objectSpace[i].transObject[j].y =
  13. m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][1]+
  14. m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][1]+
  15. m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][1]+
  16. m_whoObject->transMatrix[3][1];
  17. m_whoObject->objectSpace[i].transObject[j].z =
  18. m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][2]+
  19. m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][2]+
  20. m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][2]+
  21. m_whoObject->transMatrix[3][2];
  22. }
  23. }
  24. }