資源簡介
基于C++開發的 opengl從高度圖創建地形三維漫游,有三維模型、廣告牌技術、噴泉、天空等
代碼片段和文件信息
#include?
#include?
#include?
//?lib3ds頭文件
#include?“file.h“
#include?“camera.h“
#include?“mesh.h“
#include?“node.h“
#include?“material.h“
#include?“matrix.h“
#include?“vector.h“
#include?“light.h“
#include?“config.h“
//#define?EXP_NORMAL
void?render_node(Lib3dsNode?*node);
Lib3dsFile?*file;
int?meshnum?=?0;
const?char?*name_out?=?NULL;
int?main(int?argc?char?**argv)
{
if(argc<2)
{
puts(“沒有指定要轉換的文件\n“);
return?0;
}
file=lib3ds_file_load(argv[1]);
name_out?=?argv[1];
if?(!file)
{
printf(“打開?%s?失敗\n“?argv[2]);
return?0;
}
????Lib3dsNode?*p;
????for?(p=file->nodes;?p!=0;?p=p->next)
{
??????render_node(p);
}
lib3ds_file_free(file);
return?0;
}
void?render_node(Lib3dsNode?*node)
{
??ASSERT(file);
??{
????Lib3dsNode?*p;
????for?(p=node->childs;?p!=0;?p=p->next)
{
??????render_node(p);
????}
??}
??if?(node->type==LIB3DS_object_NODE)
??{
????if?(strcmp(node->name“$$$DUMMY“)==0)
{
??????return;
????}
????if?(!node->user.d)
{
??????Lib3dsMesh?*mesh=lib3ds_file_mesh_by_name(file?node->name);
??????ASSERT(mesh);
??????if?(!mesh)
??{
????????return;
??????}
??????{
#ifdef?EXP_NORMAL
????????Lib3dsVector?*normalL?=?(Lib3dsVector*)malloc(3*sizeof(Lib3dsVector)*mesh->faces);
????????lib3ds_mesh_calculate_normals(mesh?normalL);
#endif
ASSERT(mesh->points?==?mesh->texels);
//?輸出到的文件
char?filename[300];
sprintf(filename?“%s_%d.3d“?name_out?++meshnum);
FILE?*out?=?fopen(filename?“wb“);
ASSERT(out);
if(!out)
{
??????????printf(“打開?%s?失敗\n“?filename);
??return;
}
//?頂點數
fwrite(&mesh->points?4?1?out);
//?面數
fwrite(&mesh->faces?4?1?out);
//?頂點數據
for(unsigned?i=0;?ipoints;?++i)
{
??fwrite(mesh->texelL[i]?4*2?1?out);
#ifdef?EXP_NORMAL
??fwrite(normalL[i]?4*3?1?out);
#endif
??fwrite(mesh->pointL[i].pos?4*3?1?out);
}
//?索引數據
????????for(unsigned?p=0;?pfaces;?++p)
{
??????????Lib3dsFace?*f=&mesh->faceL[p];
??/*
??????????Lib3dsMaterial?*mat=0;
??????????if?(f->material[0])
??{
????????????mat=lib3ds_file_material_by_name(file?f->material);
??????????}
??????????if?(mat)
??{
????????????static?GLfloat?a[4]={0001};
????????????float?s;
????????????glMaterialfv(GL_FRONT?GL_AMBIENT?a);
????????????glMaterialfv(GL_FRONT?GL_DIFFUSE?mat->diffuse);
????????????glMaterialfv(GL_FRONT?GL_SPECULAR?mat->specular);
????????????s?=?pow(2?10.0*mat->shininess);
????????????if?(s>128.0)
{
??????????????s=128.0;
????????????}
????????????glMaterialf(GL_FRONT?GL_SHININESS?s);
??????????}
??????????else
??{
????????????Lib3dsRgba?a={0.2?0.2?0.2?1.0};
????????????Lib3dsRgba?d={0.8?0.8?0.8?1.0};
????????????Lib3dsRgba?s={0.0?0.0?0.0?1.0};
????????????glMaterialfv(GL_FRONT?GL_AMBIENT?a);
????????????glMaterialfv(GL_FRONT?GL_DIFFUSE?d);
????????????glMaterialfv(GL_FRONT?GL_SPECULAR?s);
??????????}
??*/
??/*
??????????{
????????????int?i;
????????????glBegin(GL_TRIANGLES);
??????????????glNormal3fv(f->normal);
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4315??2012-04-18?16:42??從高度圖創建地形\3dsExport\3dsExport.vcproj
?????文件???????1413??2011-05-03?20:28??從高度圖創建地形\3dsExport\3dsExport.vcproj.Alana-PC.Alana.user
?????文件???????5219??2018-12-27?19:32??從高度圖創建地形\3dsExport\3dsExport.vcxproj
?????文件????????929??2018-12-27?19:32??從高度圖創建地形\3dsExport\3dsExport.vcxproj.filters
?????文件????????143??2011-05-03?20:29??從高度圖創建地形\3dsExport\3dsExport.vcxproj.user
?????文件???????3926??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\3dsExport.Build.CppClean.log
?????文件????????114??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\3dsExport.lastbuildstate
?????文件???????1983??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\3dsExport.log
?????文件????????862??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\cl.command.1.tlog
?????文件???????2810??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\CL.read.1.tlog
?????文件????????396??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\CL.write.1.tlog
?????文件??????????2??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件??????????2??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件??????????2??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件??????????2??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件???????1440??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件???????2646??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件????????626??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\li
?????文件??????15255??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\main.obj
?????文件?????101376??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\vc110.idb
?????文件??????77824??2018-12-27?19:33??從高度圖創建地形\3dsExport\Debug\vc110.pdb
?????文件???????3361??2007-04-20?13:11??從高度圖創建地形\3dsExport\main.cpp
?????文件???????3640??2012-04-19?11:52??從高度圖創建地形\Backup\opengl.sln
????..A..H.?????52224??2012-11-12?15:34??從高度圖創建地形\Backup\opengl.v11.suo
?????文件?????189440??2018-12-27?19:33??從高度圖創建地形\Debug\3dsExport.exe
?????文件?????463336??2018-12-27?19:33??從高度圖創建地形\Debug\3dsExport.ilk
?????文件?????707584??2018-12-27?19:33??從高度圖創建地形\Debug\3dsExport.pdb
?????文件????????240??2012-04-26?09:46??從高度圖創建地形\Debug\cout.txt
?????文件?????176964??2007-04-18?09:34??從高度圖創建地形\Debug\data\Grass2.jpg
?????文件??????17464??2007-03-01?18:04??從高度圖創建地形\Debug\data\ground.bmp
............此處省略499個文件信息
- 上一篇:深入理解計算機系統CMU官方最新PPT
- 下一篇:牛客網C++ .pdf
評論
共有 條評論