void PerspectiveCamera::SetPositionLookAt(const Vector3d& vPos, const Vector3d& vLookAt) { Vector3d vDir = vLookAt - vPos; if (vDir.Length() < 1e-6) vDir = Vector3d(0.0, 0.0, 1.0); double dAngleDirection = Rad2Deg(atan2(vDir.X(), -vDir.Z())); double dAngleUp = Rad2Deg(atan2(vDir.Y(), -vDir.Z())); SetPosition(vPos, dAngleDirection, dAngleUp); }
bool Animation::LoadFoot(const QString &pathdir) { // load node coord tifstream ifStr; ifStr.open((pathdir+ "Model/footCoord.txt").utf16()); Vector3d tmpCoord; while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { footCoord.push_back(tmpCoord); std::cout << "body coord: " << footCoord.size() << " " << footCoord[footCoord.size()-1].X() << " " << footCoord[footCoord.size()-1].Y() << " " << footCoord[footCoord.size()-1].Z() << " " << std::endl; } ifStr.close(); // load node coord ifStr.open((pathdir+ "Model/footNode.txt").utf16()); int tmpNode; while (ifStr >> tmpNode) { footNode.push_back(tmpNode); std::cout << "body node: " << footNode.size() << " " << footNode[footNode.size()-1] << " "; } std::cout << std::endl; ifStr.close(); // load node mode ifStr.open((pathdir+ "Model/mode_3.txt").utf16()); while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { footMode.push_back(tmpCoord); //std::cout << "body coord: " << footMode.size() << " " << footMode[footMode.size()-1].X() << " " << footMode[footMode.size()-1].Y() // << " " << footMode[footMode.size()-1].Z() << " " << std::endl; } ifStr.close(); // load ref shape ifStr.open((pathdir+ "Model/rot_curve_cushion.vert").utf16()); int idex; while (ifStr >> idex >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { refShape.push_back(tmpCoord); //std::cout << "body coord: " << footMode.size() << " " << footMode[footMode.size()-1].X() << " " << footMode[footMode.size()-1].Y() // << " " << footMode[footMode.size()-1].Z() << " " << std::endl; } ifStr.close(); return true; }
Vector3d CSkeleton::fitToLocation(Joint_handle hJoint, Vector3d target_loc) { Joint_handle hRoot = rootOf(hJoint); updateGlobalPostures(hRoot); if(hRoot == parents[hJoint]) { joints[hJoint].setOffset(target_loc); updateGlobalPostures(hRoot); return globals[hJoint].getOffset(); } //updateGlobalPostures(0); Joint_handle hParent = parents[hJoint]; Vector3d dJoint, dTarget; Vector3d pJoint, pParent; pJoint = getGlobalPosition(hJoint); pParent = getGlobalPosition(hParent); dJoint = (pJoint - pParent).Normalize(); dTarget = (target_loc - pParent).Normalize(); Quaterniond qParent = getGlobalRotation(hParent); // dJoint = cast_to_vector(!qParent*dJoint*qParent); // dTarget = cast_to_vector(!qParent*dTarget*qParent); Vector3d axis = Vector3d::Cross(dJoint, dTarget); double dot = Vector3d::Dot(dJoint, dTarget); double angle = acos(Vector3d::Dot(dJoint, dTarget)); Quaterniond qtemp = !qParent*Quaterniond(0, axis.X(), axis.Y(), axis.Z())*qParent; axis = Vector3d(qtemp.X(), qtemp.Y(), qtemp.Z()); Quaterniond rot; rot.FromAxisAngle(angle, axis.X(), axis.Y(), axis.Z()); qtemp = rot*Quaterniond(0, dJoint.X(), dJoint.Y(), dJoint.Z())*!rot; Vector3d pos(qtemp.X(), qtemp.Y(), qtemp.Z()); Vector3d err = pos - dTarget; if( angle == 0.f || (axis.X() == 0 && axis.Y() == 0 && axis.Z() ==0) || dJoint == dTarget) return globals[hJoint].getOffset(); joints[hParent].Rotate(rot); //rotateJoint(hParent, rot); updateGlobalPostures(hParent); //updateGlobalPostures(0); return globals[hJoint].getOffset(); }
bool Animation::LoadBody(const QString &pathdir) { // load node coord tifstream ifStr; ifStr.open((pathdir+ "Model/bodyCoord.txt").utf16()); Vector3d tmpCoord; while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { bodyCoord.push_back(tmpCoord); std::cout << "body coord: " << bodyCoord.size() << " " << bodyCoord[bodyCoord.size()-1].X() << " " << bodyCoord[bodyCoord.size()-1].Y() << " " << bodyCoord[bodyCoord.size()-1].Z() << " " << std::endl; } ifStr.close(); // load node coord ifStr.open((pathdir+ "Model/bodyNode.txt").utf16()); int tmpNode; while (ifStr >> tmpNode) { bodyNode.push_back(tmpNode); std::cout << "body node: " << bodyNode.size() << " " << bodyNode[bodyNode.size()-1] << " "; } std::cout << std::endl; ifStr.close(); // load frame coord ifStr.open((pathdir+ "Model/bodyFrame.txt").utf16()); ifStr >> bodyFrame.X() >> bodyFrame.Y() >> bodyFrame.Z(); std::cout << "body frame: " << bodyFrame.X() << " " << bodyFrame.Y() << " " << bodyFrame.Z() << " " << std::endl; ifStr.close(); return true; }
void ModelRenderInstance::Render(RenderOptions& renderOptions) { m_spDisplayState->Tick(); OpenGL::PushedAttributes attrib(GL_POLYGON_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT); if (renderOptions.Get(RenderOptions::optionModelFilled)) glPolygonMode(GL_FRONT, GL_FILL); else glPolygonMode(GL_FRONT, GL_LINE); glPushMatrix(); // position model Vector3d vPos = CalculatedPos(); glTranslated(vPos.X(), vPos.Y(), vPos.Z()); glRotated(m_dViewAngle, 0.0, 1.0, 0.0); double dTransparency = CalcPlayerTransparency(); // blend model if (dTransparency < 1.0) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } double dLuminance = m_bSelected ? 1.2 : 1.0; glColor4d(dLuminance, dLuminance, dLuminance, dTransparency); m_spDisplayState->Render(renderOptions); glPopMatrix(); }
/// ctor VertexBufferEntry(const Vector3d& vVertex, const Vector3d& vNormal, const TexCoord2f& texCoord, const Color& c) { vertex[0] = static_cast<GLfloat>(vVertex.X()); vertex[1] = static_cast<GLfloat>(vVertex.Y()); vertex[2] = static_cast<GLfloat>(vVertex.Z()); normal[0] = static_cast<GLfloat>(vNormal.X()); normal[1] = static_cast<GLfloat>(vNormal.Y()); normal[2] = static_cast<GLfloat>(vNormal.Z()); texcoords[0] = static_cast<GLfloat>(texCoord.U()); texcoords[1] = static_cast<GLfloat>(texCoord.V()); color[0] = c.m_color[0]; color[1] = c.m_color[1]; color[2] = c.m_color[2]; color[3] = c.m_color[3]; }
bool HangerAnimation::LoadAnimData(const QString &pathdir) { // load node coord tifstream ifStr; ifStr.open((pathdir+ "Model/traj.txt").utf16()); Vector3d tmpCoord; while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { motionData.push_back(tmpCoord); } ifStr.close(); ifStr.open((pathdir+ "Model/trajOrientation.txt").utf16()); while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) orientData.push_back(tmpCoord); ifStr.close(); return true; }
bool HangerAnimation::LoadCtrlPoint(const QString &pathdir) { // load node coord tifstream ifStr; ifStr.open((pathdir+ "Model/ctrlNode.txt").utf16()); Vector3d tmpCoord; while (ifStr >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) ctrlPoint.push_back(tmpCoord); ifStr.close(); return true; }
void ModelDisplayState::PrepareTriangle(const AnimatedModel3d& model, const Data& data, const Triangle& t, VertexBufferEntry* pEntries, bool bOnlyUpdate) { for (unsigned int uiVertex = 0; uiVertex < 3; uiVertex++) { size_t uiVertexIndex = t.auiVertexIndices[uiVertex]; ATLASSERT(uiVertexIndex < data.m_vecVertices.size()); const Vertex& v = data.m_vecVertices[uiVertexIndex]; Vector3d vPos = v.m_vPos; model.TransformVertex(v, m_vecJointRenderData, vPos); Vector3d vNormal = t.aNormals[uiVertex]; model.TransformNormal(v, m_vecJointRenderData, vNormal); VertexBufferEntry& e = pEntries[uiVertex]; e.vertex[0] = static_cast<float>(vPos.X()); e.vertex[1] = static_cast<float>(vPos.Y()); e.vertex[2] = static_cast<float>(vPos.Z()); e.normal[0] = static_cast<float>(vNormal.X()); e.normal[1] = static_cast<float>(vNormal.Y()); e.normal[2] = static_cast<float>(vNormal.Z()); if (!bOnlyUpdate) { e.texcoords[0] = t.aTex[uiVertex].U(); e.texcoords[1] = t.aTex[uiVertex].V(); e.color[0] = e.color[1] = e.color[2] = 255; e.color[3] = 0; } } }
bool HangerAnimation::LoadRefShape(const QString &pathdir) { // load ref shape tifstream ifStr; ifStr.open((pathdir+ "Model/hanger_scale_stand.vert").utf16()); Vector3d tmpCoord; int idex; while (ifStr >> idex >> tmpCoord.X() >> tmpCoord.Y() >> tmpCoord.Z()) { refShape.push_back(tmpCoord); //std::cout << "body coord: " << footMode.size() << " " << footMode[footMode.size()-1].X() << " " << footMode[footMode.size()-1].Y() // << " " << footMode[footMode.size()-1].Z() << " " << std::endl; } ifStr.close(); return true; }
void CSkeleton::drawSkeleton(void) { for(size_t i = 0; i < joints.size(); i++) if(isRoot(i)) updateGlobalPostures(i); size_t n = joints.size(); Quaterniond rot, a; Vector3d pos; for(size_t i = 1; i < n; i++) { rot = getGlobalRotation( i ); pos = getGlobalPosition( i ); a = rot.Log(); glPushMatrix(); glTranslated(pos.X(), pos.Y(), pos.Z()); glRotated(a.W()*180/M_PI, a.X(), a.Y(), a.Z()); glColor3ub(255, 255, 0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(0, 0, joints[i].getScale().Z()); glEnd(); glBegin(GL_LINES); glColor3ub(255, 0, 0); glVertex3f(0, 0, 0); glVertex3f(0.1, 0, 0); glColor3ub(0, 255, 0); glVertex3f(0, 0, 0); glVertex3f(0, 0.1, 0); glColor3ub(0, 0, 255); glVertex3f(0, 0, 0); glVertex3f(0, 0, 0.1); glEnd(); glPopMatrix(); } }
void CSkeleton::updateGlobalPostures(Joint_handle hJoint) { if(isRoot(hJoint)) globals[hJoint] = joints[hJoint]; else { size_t parent_idx = parents[hJoint]; globals[hJoint].setOffset(globals[parent_idx].getOffset()); Quaterniond q = globals[parent_idx].getRotation(); Vector3d offset = joints[hJoint].getOffset(); Quaterniond qtemp = q*Quaterniond(0, offset.X(), offset.Y(), offset.Z())*!q; Vector3d pos(qtemp.X(), qtemp.Y(), qtemp.Z()); globals[hJoint].Translate(pos); globals[hJoint].setRotation(q*joints[hJoint].getRotation()); } Joint_handle_iterator jh_it, jh_end = children[hJoint].end(); for(jh_it = children[hJoint].begin(); jh_it != jh_end; ++jh_it) { updateGlobalPostures(*jh_it); } }
/// writes vector void WriteVector(const Vector3d& vec) { WriteDouble(vec.X()); WriteDouble(vec.Y()); WriteDouble(vec.Z()); }