Vector4d Triangle::normal_vector(const Vector4d &surface) const { double u, v; std::tie(u, v) = uvCoords(surface); Vector4d normal = (1 - u - v) * n1 + u * n2 + v * n3; normal.normalize(); return normal; }
void CSimuVertexRingObj::_computeElasticForcesNew( const unsigned int timeid, const bool isStatic, const bool needjacobian) { //compute the rotation for each vertex const bool bRecompRot = (timeid%2 == 1); if (timeid<=1 || bRecompRot){ const bool needquat = false; updateRotationQuaternionForAllElements(timeid, needquat); } else{ //use central difference to update the quaternions for (int i=0; i<m_nVRingElementCount; i++){ CVertexRingElement &e = m_pVRingElement[i]; Vector4d quat = e.m_quat + e.m_quat - e.m_quat0; quat.normalize(); e.m_quat0 = e.m_quat; e.m_quat = quat; //convert quat to matrix Quaternion *pquat = (Quaternion*)&e.m_quat.x; typedef double M33[3][3]; pquat->getRotationMatrix(*((M33*)&e.m_R.x)); } } //call the old alg. const int SKIPSTEP = m_nRotationSkipStep; m_nRotationSkipStep = INT_MAX-1; _computeElasticForces(timeid, isStatic, needjacobian); m_nRotationSkipStep = SKIPSTEP; /* //compute forces using the rotation Vector3d force; double3x3 jacobian, *pjac=NULL; const bool FASTSTIFF = (this->m_mtl.getMaterialType()==0); if (needjacobian) pjac = &jacobian; for (int i=0; i<m_nEdge; i++){ CSimuEdgeInput& edge = m_pEdge[i]; const int v0=edge.v0, v1=edge.v1; if (bRecompRot){ //computer averaged rotation of the rod, then save it const Quaternion *q0 = (const Quaternion *)(&m_pVRingElement[v0].m_quat); const Quaternion *q1 = (const Quaternion *)(&m_pVRingElement[v1].m_quat); const Quaternion q = Quaternion::slerp_midpoint(*q0, *q1); q.getRotationMatrix(*((double(*)[3][3])(&edge.mat))); } //apply the rotation for the rod element const Vector3d& p0 = m_pVertInfo[v0].m_pos; const Vector3d& p1 = m_pVertInfo[v1].m_pos; m_pGyrod[i].computeNodalForce(p0, p1, edge.mat, *edge.pMaterial, force, pjac); //accumulate the force and stiffness m_pVertInfo[v0].m_force+=force; m_pVertInfo[v1].m_force-=force; if (needjacobian) saveVertSitffMatrixIntoSparseMatrix(v0, v1, *pjac, FASTSTIFF); } */ }
TEST(cam_loader, loadCameraFromFile) { Camera c = loadCameraFromFile("cam_file.cam"); // location EXPECT_FLOAT_EQ(c.position.orig[0], 4.0); EXPECT_FLOAT_EQ(c.position.orig[1], 5.0); EXPECT_FLOAT_EQ(c.position.orig[2], 6.0); // direction Vector4d expected = Vector4d(1.0, 0.5, 1.1, 0.0); expected.normalize(); EXPECT_LT((c.position.dir - expected).norm(), 0.00001) << "direction vector"; // up direction Vector4d expected_up = Vector4d(1, 2, 3, 0).normalized(); EXPECT_FLOAT_EQ((c.up - expected_up).norm(), 0.0) << "up vector"; // dimensions EXPECT_DOUBLE_EQ(c.worldWidth, 10) << "world width"; EXPECT_DOUBLE_EQ(c.worldHeight, 20) << "world height"; }