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]; }
/*! \details \verbatim upper ul-------ur |\ | l| \ |r e| \ |i f| c |g t| \ |h | \ |t | \| ll-------lr lower \endverbatim This considers a quad for splitting. This is done by looking to see how coplanar the quad is. The elevation of the corners are averaged, and compared to the elevation of the center. The greater the difference between these two values, the more non-coplanar this quad is. */ double ReduceAlgorithmCameraDistance::CalcDelta(unsigned int x1, unsigned int y1, unsigned int uiQuadSize) throw() { unsigned int half = uiQuadSize / 2; unsigned int xc = x1 + half; unsigned int x2 = x1 + uiQuadSize; unsigned int yc = y1 + half; unsigned int y2 = y1 + uiQuadSize; unsigned int uiMapSize = GetSize(); if (x2 > uiMapSize || y2 > uiMapSize) return 0.0; float ul, ur, ll, lr, center; Vector3d pos = MapPoint(x1, y1); ul = (float)pos.Y(); pos = MapPoint(x2, y1); ur = (float)pos.Y(); pos = MapPoint(x1, y2); ll = (float)pos.Y(); pos = MapPoint(x2, y2); lr = (float)pos.Y(); pos = MapPoint(xc, yc); center = (float)pos.Y(); float average = (ul + lr + ll + ur) / 4.0f; // look for a delta between the center point and the average elevation float delta = fabs((average - center)) * 5.0f; // scale the delta based on the size of the quad we are dealing with delta /= (float)uiQuadSize; // scale based on distance float dist = (float)MapDistance(xc, yc); delta *= (1.0f - (dist * 0.85f)); // if the distance is very close, then we want a lot more detail if (dist < 0.15f) delta *= 10.0f; // smaller quads are much less important float size_bias = (float)(uiMapSize + uiQuadSize) / (float)(uiMapSize * 2); delta *= size_bias; return delta; }
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 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; }
void BlockRenderDataTexturedVertexBuffer::UpdateBlocks(const Vector3d& vCamera) { m_blockUpdateInProgress.Set(); unsigned int uiNumZones = m_spZoneManager->NumZones(); unsigned int uiZoneSize = m_spDataBlock->GetElevationData().Size() / uiNumZones; Terrain::Reduce::ZoneDataSource ds(*m_spDataBlock, uiZoneSize); #define USE_ZIGZAG #ifdef USE_ZIGZAG ZigzagSquareIterator iter(uiNumZones); #else for (size_t i=0, iMax=uiNumZones*uiNumZones; i<iMax; i++) #endif do { // check which new level should be calculated for each block #ifdef USE_ZIGZAG // unsigned int xzone = iter.X(), yzone = iter.Y(); unsigned int xzone = uiNumZones - 1 - iter.X(); unsigned int yzone = uiNumZones - 1 - iter.Y(); #else unsigned int xzone, yzone; IndexToZone(i, xzone, yzone); #endif double xmid = (xzone * uiZoneSize) + uiZoneSize/2; double ymid = (yzone * uiZoneSize) + uiZoneSize/2; double dist = (vCamera - Vector3d(xmid, vCamera.Y(), ymid)).Length(); // map distance to level unsigned int uiLevel = MapDistToLevel(dist); unsigned int uiIndex = xzone * uiNumZones + yzone; ATLASSERT(xzone == uiIndex / uiNumZones); ATLASSERT(yzone == uiIndex % uiNumZones); // check if zone needs update m_spZoneManager->IsCurrentLevel(uiIndex, uiLevel); std::shared_ptr<DataBlock> spZoneDataBlock = ds.LoadBlock(xzone * uiZoneSize, yzone * uiZoneSize, uiZoneSize); m_spZoneManager->PrepareZone(xzone, yzone, uiIndex, uiLevel, spZoneDataBlock); #ifdef USE_ZIGZAG } while (iter.Next()); #else }
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()); }