void CTransform::LookAt(const CVec& cEye, const CVec& cCenter, const CVec& cUp) { CVec cF = cCenter - cEye; cF.Normalize( ); CVec cUpPrime = cUp; cUpPrime.Normalize( ); CVec cS = cF * cUpPrime; CVec cU = cS * cF; CTransform cTemp; cTemp.m_afData[0][0] = cS[0]; cTemp.m_afData[1][0] = cS[1]; cTemp.m_afData[2][0] = cS[2]; cTemp.m_afData[0][1] = cU[0]; cTemp.m_afData[1][1] = cU[1]; cTemp.m_afData[2][1] = cU[2]; cTemp.m_afData[0][2] = -cF[0]; cTemp.m_afData[1][2] = -cF[1]; cTemp.m_afData[2][2] = -cF[2]; *this = cTemp * *this; Translate(-cEye.m_afData[0], -cEye.m_afData[1], -cEye.m_afData[2]); }
void CTransform::RotateAxis(float fAngle, CVec cAxis) { cAxis.Normalize( ); float s = VectorSinD(fAngle); float c = VectorCosD(fAngle); float t = 1.0f - c; float x = cAxis.m_afData[0]; float y = cAxis.m_afData[1]; float z = cAxis.m_afData[2]; CTransform cRotMatrix; cRotMatrix.m_afData[0][0] = t * x * x + c; cRotMatrix.m_afData[0][1] = t * x * y + s * z; cRotMatrix.m_afData[0][2] = t * x * z - s * y; cRotMatrix.m_afData[0][3] = 0.0; cRotMatrix.m_afData[1][0] = t * x * y - s * z; cRotMatrix.m_afData[1][1] = t * y * y + c; cRotMatrix.m_afData[1][2] = t * y * z + s * x; cRotMatrix.m_afData[1][3] = 0.0; cRotMatrix.m_afData[2][0] = t * x * z + s * y; cRotMatrix.m_afData[2][1] = t * y * z - s * x; cRotMatrix.m_afData[2][2] = t * z * z + c; cRotMatrix.m_afData[2][3] = 0.0; cRotMatrix.m_afData[3][0] = 0.0; cRotMatrix.m_afData[3][1] = 0.0; cRotMatrix.m_afData[3][2] = 0.0; cRotMatrix.m_afData[3][3] = 1.0; *this = cRotMatrix * *this; }