排版不好,我在贴一份 //get the file sizeof the file in bytes
//struct stat sbuf;
// fstat((int)stream,&sbuf);
//int length = _filelength((int)stream);
fseek(stream, 0L, SEEK_END);
int filelength =ftell(stream);
fseek(stream,0L,SEEK_SET);
//create a heap for the model
t3dmodel.hHeapHandle = HeapCreate(NULL,filelength*2,0);
if(t3dmodel.hHeapHandle == NULL)
{
SetLastError(8);
return false;
} if(stream == NULL)
{
//set the error that ERROR_PATH_NOT_FOUND
SetLastError(2);
return false;
}
//specify whether it's the correct format
int format = 0;
read+=4*fread(&format,sizeof(int),1,stream);
if(format != 4520)
{
//An attempt was made to load a program with an incorrect forma
SetLastError(11);
fclose(stream);
return false;
}//#ifdef _debug
HANDLE hHeap[25];
DWORD dwNumHeaps = GetProcessHeaps(25,hHeap);
//#endif
//Now load the file's object
read += 4*fread(&t3dmodel.numOfObjects ,sizeof(int),1,stream);
for(int i = 0; i < t3dmodel.numOfObjects ;i++)
{ //specify the memory to be alloc
int len = 0;
t3DObject t3dobject;
read += 4*fread(&t3dobject.numOfVerts,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numOfFaces,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numTexVertex,sizeof(int),1,stream);
read += 4*fread(&t3dobject.materialID,sizeof(int),1,stream);
read += sizeof(bool)*fread(&t3dobject.bHasTexture,sizeof(bool),1,stream);
read += sizeof(char)*fread(t3dobject.strName,sizeof(char),255,stream);
//alloc the memory for the pVerts
//t3dobject.pVerts = new tVector3[t3dobject.numOfVerts];
if(t3dobject.numOfVerts >0)
{
len = sizeof(tVector3)*t3dobject.numOfVerts;
t3dobject.pVerts =(tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS,len);
if(t3dobject.pVerts == NULL) goto END;
read += sizeof(tVector3)*fread(t3dobject.pVerts,sizeof(tVector3),t3dobject.numOfVerts,stream);
}
//alloc the memory for the pNormals
//t3dobject.pNormals = new tVector3[t3dobject.numOfFaces];
if(t3dobject.numOfFaces >0)
{
len = sizeof(tVector3)*t3dobject.numOfFaces;
t3dobject.pNormals = (tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pNormals ==NULL) goto END;
//memset(t3dobject.pNormals,0,sizeof(tVector3)*t3dobject.numOfFaces);
read += sizeof(tVector3)*fread(t3dobject.pNormals,sizeof(tVector3),t3dobject.numOfFaces,stream);
}
//allox the memory for teh pTexVerts
//t3dobject.pTexVerts = new tVector2[t3dobject.numTexVertex];
if(t3dobject.numTexVertex>0)
{
len = sizeof(tVector2)*t3dobject.numTexVertex;
t3dobject.pTexVerts = (tVector2 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pTexVerts == NULL) goto END;
read += sizeof(tVector2)*fread(t3dobject.pTexVerts,sizeof(tVector2),t3dobject.numTexVertex,stream);
}
//alloc the memory for the pFace
//t3dobject.pFaces = new tFace[t3dobject.numOfFaces];
if(t3dobject.numOfFaces > 0)
{
len = sizeof(tVector2)*t3dobject.numOfFaces;
t3dobject.pFaces = (tFace *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pFaces == NULL) goto END;
read += sizeof(tFace)*fread(t3dobject.pFaces,sizeof(tFace),t3dobject.numOfFaces,stream);
}
ATLTRACE2(" read value: %f\n",read);
//push the object to the vecot
t3dmodel.pObject.push_back(t3dobject);
}
//struct stat sbuf;
// fstat((int)stream,&sbuf);
//int length = _filelength((int)stream);
fseek(stream, 0L, SEEK_END);
int filelength =ftell(stream);
fseek(stream,0L,SEEK_SET);
//create a heap for the model
t3dmodel.hHeapHandle = HeapCreate(NULL,filelength*2,0);
if(t3dmodel.hHeapHandle == NULL)
{
SetLastError(8);
return false;
} if(stream == NULL)
{
//set the error that ERROR_PATH_NOT_FOUND
SetLastError(2);
return false;
}
//specify whether it's the correct format
int format = 0;
read+=4*fread(&format,sizeof(int),1,stream);
if(format != 4520)
{
//An attempt was made to load a program with an incorrect forma
SetLastError(11);
fclose(stream);
return false;
}//#ifdef _debug
HANDLE hHeap[25];
DWORD dwNumHeaps = GetProcessHeaps(25,hHeap);
//#endif
//Now load the file's object
read += 4*fread(&t3dmodel.numOfObjects ,sizeof(int),1,stream);
for(int i = 0; i < t3dmodel.numOfObjects ;i++)
{ //specify the memory to be alloc
int len = 0;
t3DObject t3dobject;
read += 4*fread(&t3dobject.numOfVerts,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numOfFaces,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numTexVertex,sizeof(int),1,stream);
read += 4*fread(&t3dobject.materialID,sizeof(int),1,stream);
read += sizeof(bool)*fread(&t3dobject.bHasTexture,sizeof(bool),1,stream);
read += sizeof(char)*fread(t3dobject.strName,sizeof(char),255,stream);
//alloc the memory for the pVerts
//t3dobject.pVerts = new tVector3[t3dobject.numOfVerts];
if(t3dobject.numOfVerts >0)
{
len = sizeof(tVector3)*t3dobject.numOfVerts;
t3dobject.pVerts =(tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS,len);
if(t3dobject.pVerts == NULL) goto END;
read += sizeof(tVector3)*fread(t3dobject.pVerts,sizeof(tVector3),t3dobject.numOfVerts,stream);
}
//alloc the memory for the pNormals
//t3dobject.pNormals = new tVector3[t3dobject.numOfFaces];
if(t3dobject.numOfFaces >0)
{
len = sizeof(tVector3)*t3dobject.numOfFaces;
t3dobject.pNormals = (tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pNormals ==NULL) goto END;
//memset(t3dobject.pNormals,0,sizeof(tVector3)*t3dobject.numOfFaces);
read += sizeof(tVector3)*fread(t3dobject.pNormals,sizeof(tVector3),t3dobject.numOfFaces,stream);
}
//allox the memory for teh pTexVerts
//t3dobject.pTexVerts = new tVector2[t3dobject.numTexVertex];
if(t3dobject.numTexVertex>0)
{
len = sizeof(tVector2)*t3dobject.numTexVertex;
t3dobject.pTexVerts = (tVector2 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pTexVerts == NULL) goto END;
read += sizeof(tVector2)*fread(t3dobject.pTexVerts,sizeof(tVector2),t3dobject.numTexVertex,stream);
}
//alloc the memory for the pFace
//t3dobject.pFaces = new tFace[t3dobject.numOfFaces];
if(t3dobject.numOfFaces > 0)
{
len = sizeof(tVector2)*t3dobject.numOfFaces;
t3dobject.pFaces = (tFace *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pFaces == NULL) goto END;
read += sizeof(tFace)*fread(t3dobject.pFaces,sizeof(tFace),t3dobject.numOfFaces,stream);
}
ATLTRACE2(" read value: %f\n",read);
//push the object to the vecot
t3dmodel.pObject.push_back(t3dobject);
}
解决方案 »
- 关于VC+mapx的问题
- 请教用vc++做图像采集,并简单处理
- 急求实现从JPEG文件到BMP文件转换的源码!!!
- 使用SetImageList函数,Attach函数动态改变工具栏,图标变灰色时显示不正常
- 请问我要在Dialog上用代码生成一系列的CheckBox控件,该怎么弄?初学者,多谢。
- 请教:如何将自己做的一个对话框作为单文档的视图?
- 怎么样才能让Picture Ctrl接收鼠标的击键事件?
- 关于多线程中socket缓存的清除
- 我用OpenGL写了一套3d游戏引擎,游说想要,给我mail..
- 菜鸟求救:如何改变对话框各种控件的字体大小呢?各位帮帮忙吧!
- 怎么得到CPU的ID号?(内空)
- 绝对的运行时难题,100分不够,还加100分。请帮忙!
fseek(stream, 0L, SEEK_END);
int filelength =ftell(stream);
fseek(stream,0L,SEEK_SET);
fseek(stream, 0L, SEEK_END);
int filelength =ftell(stream);
fseek(stream,0L,SEEK_SET);
filelength存放文件的大小。