void InfluenceMap::propagate(const float momentum, const float decay) { float connections_array[InfluenceMap::CONNECTIONS_ARRAY_LENGTH]; size_t x = 0; size_t y = 0; const float edge_distance = 1.0f; const float corner_distance = 1.414f; const float edge = expf(-edge_distance * decay); const float corner = expf(-corner_distance * decay); for (size_t i = 0; i < num_cells(); i++) { connections(x, y, connections_array, 1, 0); // Spread ////////////////////////////////////////////////////// float max_influence = 0; float neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::TopLeft] * corner; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::TopMiddle] * edge; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::TopRight] * corner; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::MiddleRight] * edge; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::BottomRight] * corner; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::BottomMiddle] * edge; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::BottomLeft] * corner; if (neighbour_influence > max_influence) max_influence = neighbour_influence; neighbour_influence = connections_array[ConnectionIndex::MiddleLeft] * edge; if (neighbour_influence > max_influence) max_influence = neighbour_influence; // lerp //////////////////////////////////////////////////////// const float cur_influence = influence(x, y); const float result = (max_influence - cur_influence) * momentum + cur_influence; _copy[i] = clamp_influence(result); // Move on if (++x >= _width) { x = 0; y++; } } // Swap the buffers float * const tmp = _copy; _copy = _data; _data = tmp; }
// transform vertex void Update(const Skin::Vertex &vertex, math::Vec3 &co, math::Vec3 &no) { co = no = 0; float weight = 1.f; for (Skin::Vertex::Influences::const_iterator influence(vertex.influences.begin()); influence != vertex.influences.end(); ++influence) { co += influence->bone->GetSkinMatrix() * vertex.co * influence->weight; no += influence->bone->GetNormSkinMatrix() * vertex.no * influence->weight; weight -= influence->weight; } if (weight > 0.f) { co += vertex.co * weight; no += vertex.no * weight; } }
void disjunctive_polynomial_accelerationt::cone_of_influence( const exprt &target, expr_sett &cone) { cone_of_influencet influence(fixed, symbol_table); influence.cone_of_influence(target, cone); }
bool CalSaver::saveXmlCoreMesh(const std::string& strFilename, CalCoreMesh *pCoreMesh) { std::stringstream str; vsxTiXmlDocument doc(strFilename); vsxTiXmlElement mesh("MESH"); //mesh.SetAttribute("MAGIC",Cal::MESH_XMLFILE_MAGIC); mesh.SetAttribute("VERSION",Cal::LIBRARY_VERSION); mesh.SetAttribute("NUMSUBMESH",pCoreMesh->getCoreSubmeshCount()); // get the submesh vector std::vector<CalCoreSubmesh *>& vectorCoreSubmesh = pCoreMesh->getVectorCoreSubmesh(); // write all core submeshes int submeshId; for(submeshId = 0; submeshId < (int)vectorCoreSubmesh.size(); ++submeshId) { CalCoreSubmesh *pCoreSubmesh=vectorCoreSubmesh[submeshId]; vsxTiXmlElement submesh("SUBMESH"); submesh.SetAttribute("NUMVERTICES",pCoreSubmesh->getVertexCount()); submesh.SetAttribute("NUMFACES",pCoreSubmesh->getFaceCount()); submesh.SetAttribute("MATERIAL",pCoreSubmesh->getCoreMaterialThreadId()); submesh.SetAttribute("NUMLODSTEPS",pCoreSubmesh->getLodCount()); submesh.SetAttribute("NUMSPRINGS",pCoreSubmesh->getSpringCount()); submesh.SetAttribute("NUMTEXCOORDS",pCoreSubmesh->getVectorVectorTextureCoordinate().size()); // get the vertex, face, physical property and spring vector std::vector<CalCoreSubmesh::Vertex>& vectorVertex = pCoreSubmesh->getVectorVertex(); std::vector<CalCoreSubmesh::Face>& vectorFace = pCoreSubmesh->getVectorFace(); std::vector<CalCoreSubmesh::PhysicalProperty>& vectorPhysicalProperty = pCoreSubmesh->getVectorPhysicalProperty(); std::vector<CalCoreSubmesh::Spring>& vectorSpring = pCoreSubmesh->getVectorSpring(); // get the texture coordinate vector vector std::vector<std::vector<CalCoreSubmesh::TextureCoordinate> >& vectorvectorTextureCoordinate = pCoreSubmesh->getVectorVectorTextureCoordinate(); // write all vertices int vertexId; for(vertexId = 0; vertexId < (int)vectorVertex.size(); ++vertexId) { CalCoreSubmesh::Vertex& Vertex = vectorVertex[vertexId]; vsxTiXmlElement vertex("VERTEX"); vertex.SetAttribute("ID",vertexId); vertex.SetAttribute("NUMINFLUENCES",Vertex.vectorInfluence.size()); // write the vertex data vsxTiXmlElement position("POS"); str.str(""); str << Vertex.position.x << " " << Vertex.position.y << " " << Vertex.position.z; vsxTiXmlText positiondata(str.str()); position.InsertEndChild(positiondata); vertex.InsertEndChild(position); vsxTiXmlElement normal("NORM"); str.str(""); str << Vertex.normal.x << " " << Vertex.normal.y << " " << Vertex.normal.z; vsxTiXmlText normaldata(str.str()); normal.InsertEndChild(normaldata); vertex.InsertEndChild(normal); if(Vertex.collapseId!=-1) { vsxTiXmlElement collapse("COLLAPSEID"); str.str(""); str << Vertex.collapseId; vsxTiXmlText collapseid(str.str()); collapse.InsertEndChild(collapseid); vertex.InsertEndChild(collapse); vsxTiXmlElement collapsecount("COLLAPSECOUNT"); str.str(""); str << Vertex.faceCollapseCount; vsxTiXmlText collapsecountdata(str.str()); collapsecount.InsertEndChild(collapsecountdata); vertex.InsertEndChild(collapsecount); } // write all texture coordinates of this vertex int textureCoordinateId; for(textureCoordinateId = 0; textureCoordinateId < (int)vectorvectorTextureCoordinate.size(); ++textureCoordinateId) { CalCoreSubmesh::TextureCoordinate& textureCoordinate = vectorvectorTextureCoordinate[textureCoordinateId][vertexId]; vsxTiXmlElement tex("TEXCOORD"); str.str(""); str << textureCoordinate.u << " " << textureCoordinate.v; vsxTiXmlText texdata(str.str()); tex.InsertEndChild(texdata); vertex.InsertEndChild(tex); } // write all influences of this vertex int influenceId; for(influenceId = 0; influenceId < (int)Vertex.vectorInfluence.size(); ++influenceId) { CalCoreSubmesh::Influence& Influence = Vertex.vectorInfluence[influenceId]; vsxTiXmlElement influence("INFLUENCE"); influence.SetAttribute("ID",Influence.boneId); str.str(""); str << Influence.weight; vsxTiXmlText influencedata(str.str()); influence.InsertEndChild(influencedata); vertex.InsertEndChild(influence); } // save the physical property of the vertex if there are springs in the core submesh if(pCoreSubmesh->getSpringCount() > 0) { // write the physical property of this vertex if there are springs in the core submesh CalCoreSubmesh::PhysicalProperty& physicalProperty = vectorPhysicalProperty[vertexId]; vsxTiXmlElement physique("PHYSIQUE"); str.str(""); str << physicalProperty.weight; vsxTiXmlText physiquedata(str.str()); physique.InsertEndChild(physiquedata); vertex.InsertEndChild(physique); } submesh.InsertEndChild(vertex); } // write all springs int springId; for(springId = 0; springId < (int)pCoreSubmesh->getSpringCount(); ++springId) { CalCoreSubmesh::Spring& Spring = vectorSpring[springId]; vsxTiXmlElement spring("SPRING"); str.str(""); str << Spring.vertexId[0]<< " " << Spring.vertexId[1]; spring.SetAttribute("VERTEXID",str.str()); str.str(""); str << Spring.springCoefficient; spring.SetAttribute("COEF",str.str()); str.str(""); str << Spring.idleLength; spring.SetAttribute("LENGTH",str.str()); submesh.InsertEndChild(spring); } // write all faces int faceId; for(faceId = 0; faceId < (int)vectorFace.size(); ++faceId) { CalCoreSubmesh::Face& Face = vectorFace[faceId]; vsxTiXmlElement face("FACE"); str.str(""); str << Face.vertexId[0]<< " " << Face.vertexId[1]<< " " << Face.vertexId[2]; face.SetAttribute("VERTEXID",str.str()); submesh.InsertEndChild(face); } mesh.InsertEndChild(submesh); } doc.InsertEndChild(mesh); if(!doc.SaveFile()) { CalError::setLastError(CalError::FILE_WRITING_FAILED, __FILE__, __LINE__, strFilename); return false; } return true; }