📄 model.cpp
字号:
* * \b pMixer will be deallocated by cal3d if and only if the * CalModel::destroy function is called. * * The \b create method of pMixer is called. * * pMixer may be null. After setting a null pointer, the caller MUST * call CalModel::create or CalModel::setAbstractMixer with a non-null * pointer before any other method is called. * * @param pMixer is a pointer to a CalAbstractMixer subclass instance. * *****************************************************************************/void CalModel::setAbstractMixer(CalAbstractMixer* pMixer){ m_pMixer = pMixer;}/*****************************************************************************//** Provides access to the morph target mixer. * * This function returns the morph target mixer. * * @return One of the following values: * \li a pointer to the morph target mixer * \li \b 0 if an error happend *****************************************************************************/CalMorphTargetMixer *CalModel::getMorphTargetMixer() const{ return m_pMorphTargetMixer;} /*****************************************************************************//** Provides access to the physique. * * This function returns the physique. * * @return One of the following values: * \li a pointer to the physique * \li \b 0 if an error happend *****************************************************************************/CalPhysique *CalModel::getPhysique() const{ return m_pPhysique;} /*****************************************************************************//** Provides access to the renderer. * * This function returns the renderer. * * @return One of the following values: * \li a pointer to the renderer * \li \b 0 if an error happend *****************************************************************************/CalRenderer *CalModel::getRenderer() const{ return m_pRenderer;} /*****************************************************************************//** Provides access to the skeleton. * * This function returns the skeleton. * * @return One of the following values: * \li a pointer to the skeleton * \li \b 0 if an error happend *****************************************************************************/CalSkeleton *CalModel::getSkeleton() const{ return m_pSkeleton;} /*****************************************************************************//** Provides access to the spring system. * * This function returns the spring system. * * @return One of the following values: * \li a pointer to the spring system * \li \b 0 if an error happend *****************************************************************************/CalSpringSystem *CalModel::getSpringSystem() const{ return m_pSpringSystem;} /*****************************************************************************//** Returns the global bounding box of the model. * * This function returns the global bounding box of the model. * * @param precision : indicate if the function need to compute a * correct bounding box * * @return bounding box. *****************************************************************************/CalBoundingBox & CalModel::getBoundingBox(bool precision){ CalVector v; v = CalVector(1.0f,0.0f,0.0f); m_boundingBox.plane[0].setNormal(v); v = CalVector(-1.0f,0.0f,0.0f); m_boundingBox.plane[1].setNormal(v); v = CalVector(0.0f,1.0f,0.0f); m_boundingBox.plane[2].setNormal(v); v = CalVector(0.0f,-1.0f,0.0f); m_boundingBox.plane[3].setNormal(v); v = CalVector(0.0f,0.0f,1.0f); m_boundingBox.plane[4].setNormal(v); v = CalVector(0.0f,0.0f,-1.0f); m_boundingBox.plane[5].setNormal(v); if(precision) m_pSkeleton->calculateBoundingBoxes(); std::vector<CalBone *> & vectorBone = m_pSkeleton->getVectorBone(); std::vector<CalBone *>::iterator iteratorBone; for(iteratorBone = vectorBone.begin(); iteratorBone != vectorBone.end(); ++iteratorBone) { // If it's just an approximation that are needed then // we just compute the bounding box from the skeleton if(!precision || !(*iteratorBone)->getCoreBone()->isBoundingBoxPrecomputed()) { CalVector translation = (*iteratorBone)->getTranslationAbsolute(); int planeId; for(planeId = 0; planeId < 6; ++planeId) { if(m_boundingBox.plane[planeId].eval(translation) < 0.0f) { m_boundingBox.plane[planeId].setPosition(translation); } } } else { CalBoundingBox localBoundingBox = (*iteratorBone)->getBoundingBox(); CalVector points[8]; localBoundingBox.computePoints(points); for(int i=0; i < 8; i++) { int planeId; for(planeId = 0; planeId < 6; ++planeId) { if(m_boundingBox.plane[planeId].eval(points[i]) < 0.0f) { m_boundingBox.plane[planeId].setPosition(points[i]); } } } } } return m_boundingBox;} /*****************************************************************************//** Provides access to the user data. * * This function returns the user data stored in the model instance. * * @return The user data stored in the model instance. *****************************************************************************/Cal::UserData CalModel::getUserData() const{ return m_userData;} /*****************************************************************************//** Returns the mesh vector. * * This function returns the vector that contains all attached meshes of the * model instance. * * @return A reference to the mesh vector. *****************************************************************************/std::vector<CalMesh *>& CalModel::getVectorMesh(){ return m_vectorMesh;} /*****************************************************************************//** Sets the LOD level. * * This function sets the LOD level of all attached meshes. * * @param lodLevel The LOD level in the range [0.0, 1.0]. *****************************************************************************/void CalModel::setLodLevel(float lodLevel){ // set the lod level in all meshes std::vector<CalMesh *>::iterator iteratorMesh; for(iteratorMesh = m_vectorMesh.begin(); iteratorMesh != m_vectorMesh.end(); ++iteratorMesh) { // set the lod level in the mesh (*iteratorMesh)->setLodLevel(lodLevel); }} /*****************************************************************************//** Sets the material set. * * This function sets the material set of all attached meshes. * * @param setId The ID of the material set. *****************************************************************************/void CalModel::setMaterialSet(int setId){ // set the lod level in all meshes std::vector<CalMesh *>::iterator iteratorMesh; for(iteratorMesh = m_vectorMesh.begin(); iteratorMesh != m_vectorMesh.end(); ++iteratorMesh) { // set the material set in the mesh (*iteratorMesh)->setMaterialSet(setId); }} /*****************************************************************************//** Stores user data. * * This function stores user data in the model instance. * * @param userData The user data that should be stored. *****************************************************************************/void CalModel::setUserData(Cal::UserData userData){ m_userData = userData;} /*****************************************************************************//** Updates the model instance. * * This function updates the model instance for a given amount of time. * * @param deltaTime The elapsed time in seconds since the last update. *****************************************************************************/void CalModel::update(float deltaTime){ m_pMixer->updateAnimation(deltaTime); m_pMixer->updateSkeleton(); // m_pMorpher->update(...); m_pMorphTargetMixer->update(deltaTime); m_pPhysique->update(); m_pSpringSystem->update(deltaTime);}/*****************************************************************************//** Disable internal data (and thus springs system) * *****************************************************************************/void CalModel::disableInternalData(){ // Disable internal data in all meshes std::vector<CalMesh *>::iterator iteratorMesh; for(iteratorMesh = m_vectorMesh.begin(); iteratorMesh != m_vectorMesh.end(); ++iteratorMesh) { // Disable internal data in the mesh (*iteratorMesh)->disableInternalData(); }}//****************************************************************************//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -