1.图形变换
void translate3dMatrix(float Tx, float Ty, float Tz)
{
Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
m_whoObject->transMatrix[3][0] += Tx;
m_whoObject->transMatrix[3][1] += Ty;
m_whoObject->transMatrix[3][2] += Tz;
}
void rotateX3Dmatrix(float S, float C)
{
Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
for (int i = 0; i < 4; i++) {
float temp;
temp = m_whoObject->transMatrix[i][1] * C - m_whoObject->transMatrix[i][2] * S;
m_whoObject->transMatrix[i][2] = m_whoObject->transMatrix[i][1] * S +
m_whoObject->transMatrix[i][2] * C;
m_whoObject->transMatrix[i][1] = temp;
}
}
void rotateY3Dmatrix(float S, float C)
{
Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
for (int i = 0; i < 4; i++) {
float temp;
temp = m_whoObject->transMatrix[i][0] * C + m_whoObject->transMatrix[i][2] * S;
m_whoObject->transMatrix[i][2] = -m_whoObject->transMatrix[i][0] * S +
m_whoObject->transMatrix[i][2] * C;
m_whoObject->transMatrix[i][0] = temp;
}
}
void rotateZ3Dmatrix(float S, float C)
{
Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
for (int i = 0; i < 4; i++) {
float temp;
temp = m_whoObject->transMatrix[i][0] * C - m_whoObject->transMatrix[i][1] * S;
m_whoObject->transMatrix[i][1] = m_whoObject->transMatrix[i][0] * S +
m_whoObject->transMatrix[i][1] * C;
m_whoObject->transMatrix[i][0] = temp;
}
}
2.空间变换
void TransSpaceObject()
{
Ccg3DTransDoc *pDoc = (Ccg3DTransDoc *)m_pView->GetDocument();
// First Trans Object according to its matrix
for (int i = 0; i < m_whoObject->polyCount; i++) {
for (int j = 0; j < m_whoObject->objectSpace[i].polyCount; j++) {
m_whoObject->objectSpace[i].transObject[j].x =
m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][0]+
m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][0]+
m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][0]+
m_whoObject->transMatrix[3][0];
m_whoObject->objectSpace[i].transObject[j].y =
m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][1]+
m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][1]+
m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][1]+
m_whoObject->transMatrix[3][1];
m_whoObject->objectSpace[i].transObject[j].z =
m_whoObject->objectSpace[i].polyObject[j].x * m_whoObject->transMatrix[0][2]+
m_whoObject->objectSpace[i].polyObject[j].y * m_whoObject->transMatrix[1][2]+
m_whoObject->objectSpace[i].polyObject[j].z * m_whoObject->transMatrix[2][2]+
m_whoObject->transMatrix[3][2];
}
}
}