• 大小: 992KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: OPENGL  源代码  光盘  

资源简介

《实战OPENGL三维可视化系统开发与源码精解》源代码+光盘数据

资源截图

代码片段和文件信息

// 3DSModel.cpp: implementation of the C3DSModel class.
 
 
 
 
 
 
 

#include “stdafx.h“
#include “3DSModel.h“

 
// Construction/Destruction
 
C3DSModel::C3DSModel()
{
m_sFileName[0]=0;
m_bModelOK=FALSE;

m_3DModel.numOfMaterials=0;
m_3DModel.numOfobjects=0;
m_3DModel.vctMaterials.clear();
m_3DModel.vctobjects.clear();
}
C3DSModel::~C3DSModel()
{

for(int i = 0; i < m_3DModel.numOfobjects; i++)
{

delete [] m_3DModel.vctobjects[i].pFaces;
delete [] m_3DModel.vctobjects[i].pNormals;
delete [] m_3DModel.vctobjects[i].pVerts;
delete [] m_3DModel.vctobjects[i].pTexVerts;
for(int j=0;jjects[i].numOfMaterials;j++)
delete[] m_3DModel.vctobjects[i].pMaterialREFS[j].pFaceIndexs;
delete [] m_3DModel.vctobjects[i].pMaterialREFS;
}

}
 
BOOL C3DSModel::Draw(int m_drawstyledouble *minxdouble *maxxdouble *minydouble *maxydouble *minzdouble *maxz)
{
CLoad3DS::tMatREF *pmatref;
CLoad3DS::tMaterialInfo *pmat;
CLoad3DS::t3Dobject *pobject;

for(int i = 0; i < m_3DModel.numOfobjects; i++) // 遍历模型中所有的对象
{

pobject = &m_3DModel.vctobjects[i];// 获得当前显示的对象

for(int imat=0;imatject->numOfMaterials;imat++)
{

pmatref=&pobject->pMaterialREFS[imat];

pmat=&(m_3DModel.vctMaterials[pmatref->nMaterialID]);

glMaterialfv(GL_FRONT_AND_BACKGL_AMBIENTpmat->ambient);
glMaterialfv(GL_FRONT_AND_BACKGL_DIFFUSEpmat->diffuse);
glMaterialfv(GL_FRONT_AND_BACKGL_SPECULARpmat->specular);
glMaterialfv(GL_FRONT_AND_BACKGL_EMISSIONpmat->emissive);

if(pmatref->bHasTexture) // 判断该对象是否有纹理映射
{
glEnable(GL_TEXTURE_2D);// 打开纹理映射
glEnable(GL_COLOR_MATERIAL); //激活材质颜色(给纹理映射加入颜色。如果不激活材质颜色纹理将一直保持它本来的颜色。函数glColor3f(rgb)将对改变颜色不起任何作用。所以激活他是非常重要的)
glColor3ub(255 255 255);
glBindTexture(GL_TEXTURE_2D m_3DModel.vctMaterials[pmatref->nMaterialID].texureId);

else 
{
glDisable(GL_TEXTURE_2D);// 关闭纹理映射
glDisable(GL_COLOR_MATERIAL);//关闭材质颜色
}

if(m_drawstyle==3)
{
glDisable(GL_TEXTURE_2D); // 关闭纹理映射

}



glBegin(GL_TRIANGLES);// 开始绘制三角形

for(int nfindex = 0j=0; nfindex < pmatref->nFaceNum; nfindex++)// 遍历所有的面
{

j=int(pmatref->pFaceIndexs[nfindex]);// 获得每个面的索引

// 遍历三角形的所有点
for(int whichVertex = 0; whichVertex < 3; whichVertex++)
{

int index = pobject->pFaces[j].vertIndex[whichVertex];// 获得面对每个点的索引
if(pobject->pVerts[ index ].z<=-3)
int uu=0;

// 给出法向量
glNormal3f(pobject->pNormals[ index ].x pobject->pNormals[ index ].y pobject->pNormals[ index ].z);


if(pmatref->bHasTexture) // 如果具有纹理
{
if(pobject->pTexVerts)  // 如果对象具有纹理
{
glTexCoord2f(pobject->pTexVerts[ index ].x pobject->pTexVerts[ index ].y);// 设置纹理坐标
}


if(m_drawstyle==3)
{
GetColorRGB(pobject->m_minYpObje

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5304  2009-01-28 13:04  RailWaySimulate\3DSModel.cpp

     文件        823  2008-05-21 10:05  RailWaySimulate\3DSModel.h

     文件      17792  2009-01-09 09:41  RailWaySimulate\alCulateF.cpp

     文件       1682  2009-01-09 09:41  RailWaySimulate\alCulateF.h

     文件       4159  2008-05-21 09:10  RailWaySimulate\AllocUnAlloc2D3D.cpp

     文件       1519  2008-05-21 10:05  RailWaySimulate\AllocUnAlloc2D3D.h

     文件       5449  2009-01-29 18:26  RailWaySimulate\AVICapture.cpp

     文件       1036  2003-12-24 01:08  RailWaySimulate\AVICapture.h

     文件       3211  2008-09-01 22:30  RailWaySimulate\AviParameter.cpp

     文件       1672  2008-09-01 22:29  RailWaySimulate\AviParameter.h

     文件       3493  2009-01-29 14:41  RailWaySimulate\AviParameter1.cpp

     文件       1673  2009-01-29 14:04  RailWaySimulate\AviParameter1.h

     文件       9488  2009-01-12 15:20  RailWaySimulate\BridgeData.cpp

     文件       1719  2009-01-12 15:20  RailWaySimulate\BridgeData.h

     文件       2433  2009-01-14 15:53  RailWaySimulate\BridgeSet.cpp

     文件       1444  2009-01-14 15:19  RailWaySimulate\BridgeSet.h

     文件       7557  2008-06-10 17:40  RailWaySimulate\CheckComboBox.cpp

     文件       1456  2008-05-21 10:05  RailWaySimulate\CheckComboBox.h

     文件       7282  2009-01-30 12:52  RailWaySimulate\ClientCapture.cpp

     文件       1071  2002-12-14 11:26  RailWaySimulate\ClientCapture.h

     文件       7664  2008-06-10 22:29  RailWaySimulate\Delaunay.cpp

     文件       8293  2008-06-10 22:29  RailWaySimulate\Delaunay.h

     文件      13698  2009-01-03 08:30  RailWaySimulate\DemLoad.cpp

     文件       1950  2008-12-28 10:10  RailWaySimulate\DemLoad.h

     文件     119013  2009-01-21 14:14  RailWaySimulate\DesingScheme.cpp

     文件      11281  2009-01-14 15:59  RailWaySimulate\DesingScheme.h

     文件       1326  2009-01-12 15:22  RailWaySimulate\DialogInputData.cpp

     文件       1296  2009-01-12 15:22  RailWaySimulate\DialogInputData.h

     文件       2348  1998-12-07 09:15  RailWaySimulate\Dib.cpp

     文件        943  2000-10-05 15:34  RailWaySimulate\Dib.h

............此处省略210个文件信息

评论

共有 条评论