📄 corebone.cpp
字号:
{ m_pCoreSkeleton = pCoreSkeleton;} /*****************************************************************************//** Sets the parent ID. * * This function sets the parent ID of the core bone instance. * * @param parentId The ID of the parent that should be set. *****************************************************************************/void CalCoreBone::setParentId(int parentId){ m_parentId = parentId;}/*****************************************************************************//** Provides access to the core skeleton. * * This function returns the core skeleton. * * @return One of the following values: * \li a pointer to the core skeleton * \li \b 0 if an error happend *****************************************************************************/CalCoreSkeleton *CalCoreBone::getCoreSkeleton(){ return m_pCoreSkeleton;} /*****************************************************************************//** Sets the rotation. * * This function sets the relative rotation of the core bone instance. * * @param rotation The relative rotation to the parent as quaternion. *****************************************************************************/void CalCoreBone::setRotation(const CalQuaternion& rotation){ m_rotation = rotation;} /*****************************************************************************//** Sets the bone space rotation. * * This function sets the rotation that brings a point into the core bone * instance space. * * @param rotation The rotation that brings a point into bone space. *****************************************************************************/void CalCoreBone::setRotationBoneSpace(const CalQuaternion& rotation){ m_rotationBoneSpace = rotation;} /*****************************************************************************//** Sets the translation. * * This function sets the relative translation of the core bone instance. * * @param translation The relative translation to the parent as vector. *****************************************************************************/void CalCoreBone::setTranslation(const CalVector& translation){ m_translation = translation;} /*****************************************************************************//** Sets the bone space translation. * * This function sets the translation that brings a point into the core bone * instance space. * * @param translation The translation that brings a point into bone space. *****************************************************************************/void CalCoreBone::setTranslationBoneSpace(const CalVector& translation){ m_translationBoneSpace = translation;} /*****************************************************************************//** Stores user data. * * This function stores user data in the core bone instance. * * @param userData The user data that should be stored. *****************************************************************************/void CalCoreBone::setUserData(Cal::UserData userData){ m_userData = userData;} /*****************************************************************************//** Calculates the bounding box. * * This function Calculates the bounding box of the core bone instance. * * @param pCoreModel The coreModel (needed for vertices data. *****************************************************************************/void CalCoreBone::calculateBoundingBox(CalCoreModel * pCoreModel){ int boneId = m_pCoreSkeleton->getCoreBoneId(m_strName); bool bBoundsComputed=false; int planeId; CalQuaternion rot; rot=m_rotationBoneSpace; rot.invert(); CalVector dir = CalVector(1.0f,0.0f,0.0f); dir*=rot; m_boundingBox.plane[0].setNormal(dir); dir = CalVector(-1.0f,0.0f,0.0f); dir*=rot; m_boundingBox.plane[1].setNormal(dir); dir = CalVector(0.0f,1.0f,0.0f); dir*=rot; m_boundingBox.plane[2].setNormal(dir); dir = CalVector(0.0f,-1.0f,0.0f); dir*=rot; m_boundingBox.plane[3].setNormal(dir); dir = CalVector(0.0f,0.0f,1.0f); dir*=rot; m_boundingBox.plane[4].setNormal(dir); dir = CalVector(0.0f,0.0f,-1.0f); dir*=rot; m_boundingBox.plane[5].setNormal(dir); int meshId; for(meshId=0; meshId < pCoreModel->getCoreMeshCount(); ++meshId) { CalCoreMesh * pCoreMesh = pCoreModel->getCoreMesh(meshId); int submeshId; for(submeshId=0;submeshId<pCoreMesh->getCoreSubmeshCount();submeshId++) { CalCoreSubmesh *pCoreSubmesh = pCoreMesh->getCoreSubmesh(submeshId); if(pCoreSubmesh->getSpringCount()==0) { std::vector<CalCoreSubmesh::Vertex>& vectorVertex = pCoreSubmesh->getVectorVertex(); for(size_t vertexId=0;vertexId <vectorVertex.size(); ++vertexId) { for(size_t influenceId=0;influenceId<vectorVertex[vertexId].vectorInfluence.size();++influenceId) { if(vectorVertex[vertexId].vectorInfluence[influenceId].boneId == boneId && vectorVertex[vertexId].vectorInfluence[influenceId].weight > 0.5f) { for(planeId = 0; planeId < 6; ++planeId) { if(m_boundingBox.plane[planeId].eval(vectorVertex[vertexId].position) < 0.0f) { m_boundingBox.plane[planeId].setPosition(vectorVertex[vertexId].position); m_boundingPosition[planeId]=vectorVertex[vertexId].position; bBoundsComputed=true; } } } } } } } } // To handle bones with no vertices assigned if(!bBoundsComputed) { for(planeId = 0; planeId < 6; ++planeId) { m_boundingBox.plane[planeId].setPosition(m_translation); m_boundingPosition[planeId] = m_translation; } } m_boundingBoxPrecomputed = true;} /*****************************************************************************//** Returns the current bounding box. * * This function returns the current bounding box of the core bone instance. * * @return bounding box. *****************************************************************************/CalBoundingBox & CalCoreBone::getBoundingBox(){ return m_boundingBox;}void CalCoreBone::getBoundingData(int planeId,CalVector & position){ position = m_boundingPosition[planeId];}bool CalCoreBone::isBoundingBoxPrecomputed(){ return m_boundingBoxPrecomputed;} /*****************************************************************************//** Scale the core bone. * * This function rescale all the data that are in the core bone instance and * in his childs. * * @param factor A float with the scale factor * *****************************************************************************/void CalCoreBone::scale(float factor){ m_translation*=factor; m_translationAbsolute*=factor; m_translationBoneSpace*=factor; // calculate all child bones std::list<int>::iterator iteratorChildId; for(iteratorChildId = m_listChildId.begin(); iteratorChildId != m_listChildId.end(); ++iteratorChildId) { m_pCoreSkeleton->getCoreBone(*iteratorChildId)->scale(factor); }}//****************************************************************************//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -