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

📄 renderer.cpp

📁 Cal3D实现虚拟角色 Cal3D实现虚拟角色
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  *****************************************************************************/float CalRenderer::getShininess(){  // get the core material  CalCoreMaterial *pCoreMaterial;  pCoreMaterial = m_pModel->getCoreModel()->getCoreMaterial(m_pSelectedSubmesh->getCoreMaterialId());  if(pCoreMaterial == 0) return 50.0f;  return pCoreMaterial->getShininess();} /*****************************************************************************//** Provides access to the specular color.  *  * This function returns the specular color of the material of the selected  * mesh/submesh.  *  * @param pColorBuffer A pointer to the user-provided buffer where the color  *                     data is written to.  *****************************************************************************/void CalRenderer::getSpecularColor(unsigned char *pColorBuffer){  // get the core material  CalCoreMaterial *pCoreMaterial;  pCoreMaterial = m_pModel->getCoreModel()->getCoreMaterial(m_pSelectedSubmesh->getCoreMaterialId());  if(pCoreMaterial == 0)  {    // write default values to the color buffer    pColorBuffer[0] = 255;    pColorBuffer[1] = 255;    pColorBuffer[2] = 255;    pColorBuffer[3] = 0;    return;  }  // get the specular color of the material  CalCoreMaterial::Color& color = pCoreMaterial->getSpecularColor();  // write it to the color buffer  pColorBuffer[0] = color.red;  pColorBuffer[1] = color.green;  pColorBuffer[2] = color.blue;  pColorBuffer[3] = color.alpha;} /*****************************************************************************//** Returns the number of submeshes.  *  * This function returns the number of submeshes in a given mesh.  *  * @param meshId The ID of the mesh for which the number of submeshes should  *               be returned..  *  * @return The number of submeshes.  *****************************************************************************/int CalRenderer::getSubmeshCount(int meshId){  // get the attached meshes vector  std::vector<CalMesh *>& vectorMesh = m_pModel->getVectorMesh();  // check if the mesh id is valid  if((meshId < 0) || (meshId >= (int)vectorMesh.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return 0;  }  return vectorMesh[meshId]->getSubmeshCount();} /*****************************************************************************//** Provides access to the texture coordinate data.  *  * This function returns the texture coordinate data for a given map of the  * selected mesh/submesh.  *  * @param mapId The ID of the map to get the texture coordinate data from.  * @param pTextureCoordinateBuffer A pointer to the user-provided buffer where  *                    the texture coordinate data is written to.  *  * @return The number of texture coordinates written to the buffer.  *****************************************************************************/int CalRenderer::getTextureCoordinates(int mapId, float *pTextureCoordinateBuffer, int stride){  // get the texture coordinate vector vector  std::vector<std::vector<CalCoreSubmesh::TextureCoordinate> >& vectorvectorTextureCoordinate = m_pSelectedSubmesh->getCoreSubmesh()->getVectorVectorTextureCoordinate();  // check if the map id is valid  if((mapId < 0) || (mapId >= (int)vectorvectorTextureCoordinate.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return -1;  }  // get the number of texture coordinates to return  int textureCoordinateCount;  textureCoordinateCount = m_pSelectedSubmesh->getVertexCount();  // copy the texture coordinate vector to the face buffer  if(stride == sizeof(CalCoreSubmesh::TextureCoordinate) || stride <= 0)  {	  memcpy(pTextureCoordinateBuffer, &vectorvectorTextureCoordinate[mapId][0], textureCoordinateCount * sizeof(CalCoreSubmesh::TextureCoordinate));  }  else  {	  char * pBuffer = (char*) pTextureCoordinateBuffer;	  for(int i=0; i < textureCoordinateCount; ++i)	  {		  memcpy(&pBuffer[0], &vectorvectorTextureCoordinate[mapId][i], sizeof(CalCoreSubmesh::TextureCoordinate));		  pBuffer+=stride;	  }	    }  return textureCoordinateCount;} /*****************************************************************************//** Returns the number of vertices.  *  * This function returns the number of vertices in the selected mesh/submesh.  *  * @return The number of vertices.  *****************************************************************************/int CalRenderer::getVertexCount(){  return m_pSelectedSubmesh->getVertexCount();} /*****************************************************************************//** Returns if tangent are enabled.  *  * This function returns if tangent of the current submesh are enabled  *  * @return True is tangent is enabled.  *****************************************************************************/bool CalRenderer::isTangentsEnabled(int mapId){	return m_pSelectedSubmesh->isTangentsEnabled(mapId);} /*****************************************************************************//** Provides access to the vertex data.  *  * This function returns the vertex data of the selected mesh/submesh.  *  * @param pVertexBuffer A pointer to the user-provided buffer where the vertex  *                      data is written to.  *  * @return The number of vertices written to the buffer.  *****************************************************************************/int CalRenderer::getVertices(float *pVertexBuffer, int stride){  // check if the submesh handles vertex data internally  if(m_pSelectedSubmesh->hasInternalData())  {    // get the vertex vector of the submesh    std::vector<CalVector>& vectorVertex = m_pSelectedSubmesh->getVectorVertex();    // get the number of vertices in the submesh    int vertexCount;    vertexCount = m_pSelectedSubmesh->getVertexCount();    // copy the internal vertex data to the provided vertex buffer	if(stride == sizeof(CalVector) || stride <= 0)	{		memcpy(pVertexBuffer, &vectorVertex[0], vertexCount * sizeof(CalVector));	}	else	{		char * pBuffer = (char*) pVertexBuffer;		for(int i=0; i < vertexCount; ++i)		{			memcpy(&pBuffer[0], &vectorVertex[i], sizeof(CalVector));			pBuffer+=stride;		}	}    return vertexCount;  }  // submesh does not handle the vertex data internally, so let the physique calculate it now  return m_pModel->getPhysique()->calculateVertices(m_pSelectedSubmesh, pVertexBuffer, stride);} /*****************************************************************************//** Provides access to the submesh data.  *  * This function returns the vertex and normal data of the selected mesh/submesh.  *  * @param pVertexBuffer A pointer to the user-provided buffer where the vertex  *                      and normal data is written to.  *  * @return The number of vertex written to the buffer.  *****************************************************************************/int CalRenderer::getVerticesAndNormals(float *pVertexBuffer, int stride){  // check if the submesh handles vertex data internally  if(m_pSelectedSubmesh->hasInternalData())  {    // get the vertex vector of the submesh    std::vector<CalVector>& vectorVertex = m_pSelectedSubmesh->getVectorVertex();	// get the normal vector of the submesh    std::vector<CalVector>& vectorNormal = m_pSelectedSubmesh->getVectorNormal();    // get the number of vertices in the submesh    int vertexCount;    vertexCount = m_pSelectedSubmesh->getVertexCount();	if(stride <= 0)	{		stride = 6*sizeof(float);	}	    // copy the internal vertex data to the provided vertex buffer	char * pBuffer = (char*) pVertexBuffer;	for(int i=0; i < vertexCount; ++i)	{		memcpy(&pBuffer[0], &vectorVertex[i], sizeof(CalVector));				memcpy(&pBuffer[sizeof(CalVector)], &vectorNormal[i], sizeof(CalVector));		pBuffer+=stride;	}    return vertexCount;  }  // submesh does not handle the vertex data internally, so let the physique calculate it now  return m_pModel->getPhysique()->calculateVerticesAndNormals(m_pSelectedSubmesh, pVertexBuffer, stride);} /*****************************************************************************//** Provides access to the submesh data.  *  * This function returns the vertex and normal data of the selected mesh/submesh.  *  * @param pVertexBuffer A pointer to the user-provided buffer where the vertex  *                      and normal data is written to.  *  * @return The number of vertex written to the buffer.  *****************************************************************************/int CalRenderer::getVerticesNormalsAndTexCoords(float *pVertexBuffer,int NumTexCoords){    // check if the submesh handles vertex data internally  if(m_pSelectedSubmesh->hasInternalData())  {    // get the vertex vector of the submesh    std::vector<CalVector>& vectorVertex = m_pSelectedSubmesh->getVectorVertex();	// get the normal vector of the submesh    std::vector<CalVector>& vectorNormal = m_pSelectedSubmesh->getVectorNormal();		// get the texture coordinate vector vector    std::vector<std::vector<CalCoreSubmesh::TextureCoordinate> >& vectorvectorTextureCoordinate = m_pSelectedSubmesh->getCoreSubmesh()->getVectorVectorTextureCoordinate();	int TextureCoordinateCount =(int)vectorvectorTextureCoordinate.size();		// check if the map id is valid    if((NumTexCoords < 0) || (NumTexCoords > TextureCoordinateCount))	{	   if(TextureCoordinateCount!=0)	   {		   CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);		   return -1;	   }	}    // get the number of vertices in the submesh    int vertexCount;    vertexCount = m_pSelectedSubmesh->getVertexCount();    // copy the internal vertex data to the provided vertex buffer		if(TextureCoordinateCount==0)	{		for(int vertexId=0; vertexId < vertexCount; ++vertexId)		{			memcpy(&pVertexBuffer[0], &vectorVertex[vertexId], sizeof(CalVector));			memcpy(&pVertexBuffer[3], &vectorNormal[vertexId], sizeof(CalVector));			pVertexBuffer+=6+2*NumTexCoords;					}	}	else	{		if(NumTexCoords==1)		{			for(int vertexId=0; vertexId < vertexCount; ++vertexId)			{				memcpy(&pVertexBuffer[0], &vectorVertex[vertexId], sizeof(CalVector));				memcpy(&pVertexBuffer[3], &vectorNormal[vertexId], sizeof(CalVector));				memcpy(&pVertexBuffer[6], &vectorvectorTextureCoordinate[0][vertexId], sizeof(CalCoreSubmesh::TextureCoordinate));				pVertexBuffer+=8;			}		}	    else		{			for(int vertexId=0; vertexId < vertexCount; ++vertexId)			{				memcpy(&pVertexBuffer[0], &vectorVertex[vertexId], sizeof(CalVector));							memcpy(&pVertexBuffer[3], &vectorNormal[vertexId], sizeof(CalVector));			    pVertexBuffer+=6;				for(int mapId=0; mapId < NumTexCoords; ++mapId)				{					memcpy(&pVertexBuffer[0], &vectorvectorTextureCoordinate[mapId][vertexId], sizeof(CalCoreSubmesh::TextureCoordinate));					pVertexBuffer+=2;				}			}		}			}    return vertexCount;  }  // submesh does not handle the vertex data internally, so let the physique calculate it now  return m_pModel->getPhysique()->calculateVerticesNormalsAndTexCoords(m_pSelectedSubmesh, pVertexBuffer, NumTexCoords);} /*****************************************************************************//** Selects a mesh/submesh for rendering data queries.  *  * This function selects a mesh/submesh for further rendering data queries.  *  * @param meshId The ID of the mesh that should be used for further rendering  *               data queries.  * @param submeshId The ID of the submesh that should be used for further  *                  rendering data queries.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalRenderer::selectMeshSubmesh(int meshId, int submeshId){  // get the attached meshes vector  std::vector<CalMesh *>& vectorMesh = m_pModel->getVectorMesh();  // check if the mesh id is valid  if((meshId < 0) || (meshId >= (int)vectorMesh.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  // get the core submesh  m_pSelectedSubmesh = vectorMesh[meshId]->getSubmesh(submeshId);  if(m_pSelectedSubmesh == 0) return false;  return true;} /*****************************************************************************//** Sets the normalization flag to true or false.  *  * This function sets the normalization flag on or off. If off, the normals  * calculated by Cal3D will not be normalized. Instead, this transform is left  * up to the user.  *****************************************************************************/void CalRenderer::setNormalization(bool normalize){ 	m_pModel->getPhysique()->setNormalization(normalize); }//****************************************************************************//

⌨️ 快捷键说明

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