Matrix44f LookAt(Vector3f eye, Vector3f center, Vector3f up) { Matrix44f modelview; Vector3f z = (eye - center).Normalize(); Vector3f x = CrossProduction(up, z).Normalize(); Vector3f y = CrossProduction(z, x).Normalize(); Matrix44f Minv = Matrix44f::Identity(); Matrix44f Tr = Matrix44f::Identity(); for (int i = 0; i < 3; i++) { Minv[0][i] = x[i]; Minv[1][i] = y[i]; Minv[2][i] = z[i]; Tr[i][3] = -center[i]; } modelview = Minv*Tr; return modelview; }
/************************************************************************** MSHLib-Method: Task: Programing: 06/2005 WW Implementation **************************************************************************/ void CElem::FillTransformMatrix() { if(transform_tensor) return; double xx[3]; double yy[3]; double zz[3]; transform_tensor = new Math_Group::Matrix(3,3); if (geo_type == MshElemType::LINE) { // x"_vec double const* const pnt0(nodes[0]->getData()); double const* const pnt1(nodes[1]->getData()); xx[0] = pnt1[0] - pnt0[0]; xx[1] = pnt1[1] - pnt0[1]; xx[2] = pnt1[2] - pnt0[2]; NormalizeVector(xx, 3); // an arbitrary vector for (size_t i = 0; i < 3; i++) yy[i] = 0.0; //WW. 06.11.2007 if (fabs(xx[0]) > 0.0 && fabs(xx[1]) + fabs(xx[2]) < DBL_MIN) yy[2] = 1.0; else if (fabs(xx[1]) > 0.0 && fabs(xx[0]) + fabs(xx[2]) < DBL_MIN) yy[0] = 1.0; else if (fabs(xx[2]) > 0.0 && fabs(xx[0]) + fabs(xx[1]) < DBL_MIN) yy[1] = 1.0; else { for (size_t i = 0; i < 3; i++) if (fabs(xx[i]) > 0.0) { yy[i] = -xx[i]; break; } } // z"_vec CrossProduction(xx, yy, zz); NormalizeVector(zz, 3); // y"_vec CrossProduction(zz, xx, yy); NormalizeVector(yy, 3); } else if (geo_type == MshElemType::QUAD || geo_type == MshElemType::TRIANGLE) { // x"_vec // xx[0] = nodes[1]->X() - nodes[0]->X(); // xx[1] = nodes[1]->Y() - nodes[0]->Y(); // xx[2] = nodes[1]->Z() - nodes[0]->Z(); double const* const pnt0(nodes[0]->getData()); double const* const pnt1(nodes[1]->getData()); xx[0] = pnt1[0] - pnt0[0]; xx[1] = pnt1[1] - pnt0[1]; xx[2] = pnt1[2] - pnt0[2]; NormalizeVector(xx, 3); // a vector on the plane // yy[0] = nodes[2]->X() - nodes[1]->X(); // yy[1] = nodes[2]->Y() - nodes[1]->Y(); // yy[2] = nodes[2]->Z() - nodes[1]->Z(); double const* const pnt2(nodes[2]->getData()); yy[0] = pnt2[0] - pnt1[0]; yy[1] = pnt2[1] - pnt1[1]; yy[2] = pnt2[2] - pnt1[2]; // z"_vec. off plane CrossProduction(xx, yy, zz); NormalizeVector(zz, 3); // y"_vec CrossProduction(zz, xx, yy); NormalizeVector(yy, 3); } for (size_t i = 0; i < 3; i++) { (*transform_tensor)(i, 0) = xx[i]; (*transform_tensor)(i, 1) = yy[i]; (*transform_tensor)(i, 2) = zz[i]; } }