⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hardwaremodel.cpp

📁 Cal3D实现虚拟角色 Cal3D实现虚拟角色
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************//// hardwaremodel.cpp                                                       //// Copyright (C) 2004 Desmecht Laurent                                        ////****************************************************************************//// This library is free software; you can redistribute it and/or modify it    //// under the terms of the GNU Lesser General Public License as published by   //// the Free Software Foundation; either version 2.1 of the License, or (at    //// your option) any later version.                                            ////****************************************************************************//#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "cal3d/error.h"#include "cal3d/hardwaremodel.h"#include "cal3d/coremodel.h"#include "cal3d/model.h"#include "cal3d/coremesh.h"#include "cal3d/bone.h"#include "cal3d/corematerial.h"#include "cal3d/coresubmesh.h"#include "cal3d/coreskeleton.h"#include "cal3d/skeleton.h" /*****************************************************************************//** Constructs the hardware model instance.  *  * This function is the default constructor of the hardware model instance.  *****************************************************************************/CalHardwareModel::CalHardwareModel(CalCoreModel* pCoreModel): m_selectedHardwareMesh(-1){  assert(pCoreModel);  m_pCoreModel = pCoreModel;  m_pVertexBuffer = NULL;  m_pIndexBuffer = NULL;  m_pNormalBuffer = NULL;  m_pWeightBuffer = NULL;  m_pMatrixIndexBuffer = NULL;  int i;  for( i = 0 ; i < 8 ; i++)    m_pTextureCoordBuffer[i]=NULL;  m_textureCoordNum=0;    for( i = 0 ; i < 8 ; i++)    m_pTangentSpaceBuffer [i]=NULL;   m_totalFaceCount=0;  m_totalVertexCount=0;}/*****************************************************************************//** Set the vertex (position) buffer of the hardware model instance.  *  * This function set the vertex (position) buffer the hardware model instance.  *  * @param pVertexBuffer A pointer to the vertex buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setVertexBuffer( char * pVertexBuffer, int stride){  m_pVertexBuffer = pVertexBuffer;  m_vertexStride = stride;} /*****************************************************************************//** Set the index buffer of the hardware model instance.  *  * This function set the index buffer the hardware model instance.  *  * @param pIndexBuffer A pointer to the index buffer.  *  *****************************************************************************/void CalHardwareModel::setIndexBuffer( CalIndex * pIndexBuffer){  m_pIndexBuffer= pIndexBuffer;} /*****************************************************************************//** Set the normal buffer of the hardware model instance.  *  * This function set the normal buffer the hardware model instance.  *  * @param pNormalBuffer A pointer to the normal buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setNormalBuffer( char * pNormalBuffer, int stride){  m_pNormalBuffer = pNormalBuffer;  m_normalStride = stride;} /*****************************************************************************//** Set the weight buffer of the hardware model instance.  *  * This function set the weight buffer the hardware model instance.  *  * @param pWeightBuffer A pointer to the weight buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setWeightBuffer( char * pWeightBuffer, int stride){  m_pWeightBuffer = pWeightBuffer;  m_weightStride = stride;} /*****************************************************************************//** Set the matrix index buffer of the hardware model instance.  *  * This function set the matrix index buffer the hardware model instance.  *  * @param pMatrixIndexBuffer A pointer to the matrix index buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setMatrixIndexBuffer( char * pMatrixIndexBuffer, int stride){  m_pMatrixIndexBuffer = pMatrixIndexBuffer;  m_matrixIndexStride = stride;} /*****************************************************************************//** Set the number the texture coordinate of the hardware model instance.  *  * This function set the number the texture coordinate the hardware model instance.  *  * @param textureCoordNum A integer with the number the texture coordinate.  *  *****************************************************************************/void CalHardwareModel::setTextureCoordNum(int textureCoordNum){  if( 0<= textureCoordNum && textureCoordNum < 8)  {    m_textureCoordNum=textureCoordNum;         }      } /*****************************************************************************//** Set the texture coordinate buffer of the hardware model instance.  *  * This function set the texture coordinate buffer the hardware model instance.  *  * @param mapId A integer to the texture stage  * @param pTextureCoordBuffer A pointer to the texture coord buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setTextureCoordBuffer(int mapId, char * pTextureCoordBuffer, int stride){  if( 0 <= mapId && mapId < 8)  {    m_pTextureCoordBuffer[mapId] = pTextureCoordBuffer;    m_textureCoordStride[mapId] = stride;     } } /*****************************************************************************//** Set the tangent space buffer of the hardware model instance.  *  * This function set the tangent space buffer the hardware model instance.  *  * @param mapId A integer to the texture stage  * @param pTangentSpaceBuffer A pointer to the tangent space buffer.  * @param stride  The number of byte to add to find the next element  *  *****************************************************************************/void CalHardwareModel::setTangentSpaceBuffer(int mapId, char * pTangentSpaceBuffer, int stride){  if( 0 <= mapId && mapId < 8)  {    m_pTangentSpaceBuffer[mapId] = pTangentSpaceBuffer;    m_tangentSpaceStride[mapId] = stride;     } } /*****************************************************************************//** Set the list of core mesh ids to use for building the hardware model instance.  * setCoreMeshIds must be called before the load method otherwise it will have  * no effect. If setCoreMeshIds is not called, the hardware model instance will  * use all the core mesh ids from the core model.  *  * @param coreMeshIds a vector of core mesh ids  *  *****************************************************************************/void CalHardwareModel::setCoreMeshIds(const std::vector<int>& coreMeshIds){  m_coreMeshIds = coreMeshIds;} /*****************************************************************************//** Returns the hardware mesh vector.  *  * This function returns the vector that contains all hardware mesh of the  * core mesh instance.  *  * @return A reference to the hardware mesh vector.  *****************************************************************************/std::vector<CalHardwareModel::CalHardwareMesh> & CalHardwareModel::getVectorHardwareMesh(){  return m_vectorHardwareMesh;} /*****************************************************************************//** Provides access to the ambient color.  *  * This function returns the ambient color of the material of the selected  * hardware mesh.  *  * @param pColorBuffer A pointer to the user-provided buffer where the color  *                     data is written to.  *****************************************************************************/void CalHardwareModel::getAmbientColor(unsigned char *pColorBuffer){    if( m_selectedHardwareMesh >= 0 && m_selectedHardwareMesh < int(m_vectorHardwareMesh.size())     && m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial!=0)  {    CalCoreMaterial::Color& color = m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial->getAmbientColor();    pColorBuffer[0] = color.red;    pColorBuffer[1] = color.green;    pColorBuffer[2] = color.blue;    pColorBuffer[3] = color.alpha;  }  else  {    pColorBuffer[0] = 0;    pColorBuffer[1] = 0;    pColorBuffer[2] = 0;    pColorBuffer[3] = 0;      } } /*****************************************************************************//** Provides access to the diffuse color.  *  * This function returns the diffuse color of the material of the selected  * hardware mesh.  *  * @param pColorBuffer A pointer to the user-provided buffer where the color  *                     data is written to.  *****************************************************************************/void CalHardwareModel::getDiffuseColor(unsigned char *pColorBuffer){    if( m_selectedHardwareMesh >= 0 && m_selectedHardwareMesh < int(m_vectorHardwareMesh.size())    && m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial!=0)  {    CalCoreMaterial::Color& color = m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial->getDiffuseColor();    pColorBuffer[0] = color.red;    pColorBuffer[1] = color.green;    pColorBuffer[2] = color.blue;    pColorBuffer[3] = color.alpha;  }  else  {    pColorBuffer[0] = 0;    pColorBuffer[1] = 0;    pColorBuffer[2] = 0;    pColorBuffer[3] = 0;      } } /*****************************************************************************//** Provides access to the specular color.  *  * This function returns the specular color of the material of the selected  * hardware.  *  * @param pColorBuffer A pointer to the user-provided buffer where the color  *                     data is written to.  *****************************************************************************/void CalHardwareModel::getSpecularColor(unsigned char *pColorBuffer){    if( m_selectedHardwareMesh >= 0 && m_selectedHardwareMesh < int(m_vectorHardwareMesh.size())    && m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial!=0)  {    CalCoreMaterial::Color& color = m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial->getSpecularColor();    pColorBuffer[0] = color.red;    pColorBuffer[1] = color.green;    pColorBuffer[2] = color.blue;    pColorBuffer[3] = color.alpha;  }  else  {    pColorBuffer[0] = 0;    pColorBuffer[1] = 0;    pColorBuffer[2] = 0;    pColorBuffer[3] = 0;      } }/*****************************************************************************//** Returns the shininess factor.  *  * This function returns the shininess factor of the material of the selected  * hardware mesh..  *  * @return The shininess factor.  *****************************************************************************/float CalHardwareModel::getShininess(){    if( m_selectedHardwareMesh >= 0 && m_selectedHardwareMesh < int(m_vectorHardwareMesh.size())    && m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial!=0)  {    return m_vectorHardwareMesh[m_selectedHardwareMesh].pCoreMaterial->getShininess();  }  else  {    return 50.0f;  } } /*****************************************************************************//** Returns the bone space rotation of the bone boneId.  *  * This function returns the rotation to bring a point into the  *bone instance space of the bone boneId of the selected hardware mesh.  *  * @param boneId A integer with the bone number  * @return The rotation to bring a point into bone space.  *****************************************************************************/const CalQuaternion & CalHardwareModel::getRotationBoneSpace(int boneId, CalSkeleton *pSkeleton){  const std::vector<CalBone *>& vectorBone = pSkeleton->getVectorBone();  return vectorBone[m_vectorHardwareMesh[m_selectedHardwareMesh].m_vectorBonesIndices[boneId]]->getRotationBoneSpace();} /*****************************************************************************//** Returns the bone space translation of the bone boneId.  *  * This function returns the translation to bring a point into the  *bone instance space of the bone boneId of the selected hardware mesh.  *  * @param boneId A integer with the bone number  * @return The translation to bring a point into bone space.  *****************************************************************************/const CalVector & CalHardwareModel::getTranslationBoneSpace(int boneId, CalSkeleton *pSkeleton){  const std::vector<CalBone *>& vectorBone = pSkeleton->getVectorBone();  return vectorBone[m_vectorHardwareMesh[m_selectedHardwareMesh].m_vectorBonesIndices[boneId]]->getTranslationBoneSpace();} /*****************************************************************************//** Returns the number of hardware meshes.  *  * This function returns the number of hardware meshes in the hardware model  * instance.  *  * @return The number of hardware meshes.  *****************************************************************************/int CalHardwareModel::getHardwareMeshCount(){  return m_vectorHardwareMesh.size();} /*****************************************************************************//** Returns the number of faces.  *  * This function returns the number of faces in the selected hardware mesh instance.  *  * @return The number of faces.  *****************************************************************************/int CalHardwareModel::getFaceCount(){    if( m_selectedHardwareMesh >= 0 && m_selectedHardwareMesh < int(m_vectorHardwareMesh.size()))  {    return m_vectorHardwareMesh[m_selectedHardwareMesh].faceCount;  }  return 0;   }/*****************************************************************************//** Returns the number of vertex.  *  * This function returns the number of vertex in the selected hardware mesh instance.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -