OpenGL 3D场景绘制 SiriusPrx 荒岛古堡.rar
该压缩包为OpenGL的3D场景绘制源代码,需要进一步学习的同学可翻阅博主的博客进行对照学习,文中有对源代码以及实现过程的详细解释。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1524 2019-12-18 17:32 loadTexture.cpp
文件 307 2019-12-17 20:15 loadTexture.h
文件 13126 2020-01-08 20:42 main.cpp
文件 5647872 2015-03-15 22:48 FreeImage所需文件FreeImage.dll
文件 67932 2015-03-15 22:48 FreeImage所需文件FreeImage.lib
文件 69 2020-01-08 22:31 FreeImage所需文件FreeImage导入说明书.txt
文件 2176 2016-08-19 01:50 includeAngel.h
文件 1290 2013-04-03 12:41 includeCheckError.h
文件 18165 2013-04-03 12:42 includemat.h
文件 2158 2016-08-19 10:50 includemesh.h
文件 785 2016-08-16 19:00 includeMesh_Painter.h
文件 1841 2016-10-17 15:45 includeTriMesh.h
文件 10441 2018-11-02 11:18 includevec.h
文件 844529 2018-11-09 16:46 textureall.png
文件 288221 2018-11-09 16:35 textureall_low.obj
文件 726351 2008-11-30 15:51 texturecartooncastle.jpg
文件 1051853 2008-11-30 16:11 texturecartooncastle.obj
文件 1172841 2019-12-20 00:04 texturedusk.jpg
文件 187855 2017-09-01 10:13 texturejianke.obj
文件 155452 2019-12-19 19:09 texturemoon.jpeg
文件 11575264 2016-11-21 15:26 textureMountains.jpg
文件 462 2017-04-07 09:45 textureMountains.mtl
文件 4755602 2017-04-07 09:45 textureMountains.obj
文件 2488142 2019-12-19 21:00 texture
ight.jpeg
文件 284749 2019-12-19 20:52 texturesky.obj
文件 71161 2019-12-19 19:02 texturesun.jpg
文件 98201 2019-12-19 23:40 texturesunny.jpeg
文件 57726 2019-11-28 20:53 FreeImage.h
文件 6653 2019-12-22 04:10 loadObj.cpp
文件 1469 2019-12-22 04:10 loadObj.h
............此处省略6个文件信息
#include “loadObj.h“
#include
using namespace std;
ObjLoader::ObjLoader()
{}
ObjLoader::~ObjLoader()
{}
vector split(string s char delim) {
vector v;
stringstream stringstream1(s);
string tmp;
while (getline(stringstream1 tmp delim)) {
v.push_back(tmp);
}
return v;
}
//读取obj文件
void ObjLoader::loadObjFile(std::string filename)
{
if (filename.empty())
return;
std::ifstream fin;
fin.open(filename);
if (!fin)
{
printf(“文件有误!“);
return;
}
else
{
std::string off;
while (getline(fin off))//每次读取一行
{
//读取法线
if (off[0] == ‘v‘ && off[1] == ‘n‘)
{
istringstream sin(off);
std::string s;
float x y z;
//依次读取vn以及法线的x、y、z坐标
sin >> s >> x >> y >> z;
Point3 point(x y z);
normals.push_back(point);
}
//读取纹理坐标
else if (off[0] == ‘v‘ && off[1] == ‘t‘)
{
istringstream sin(off);
std::string s;
float tmp x y z;
//读取掉前面的vt
sin >> s;
int j = 0;//j用来判断obj文件的纹理坐标是否有z坐标
//依次读取纹理坐标的x、y、z坐标
while (sin >> tmp)
{
if (j == 0)
x = tmp;
else if (j == 1)
y = tmp;
else if (j == 2)
z = tmp;
j++;
}
//当j为2时,表示无z坐标,此时默认z坐标为0
if (j == 2)
{
Point3 point(x y 0.0);
textures.push_back(point);
}
//当j为3时,表示有z坐标
else if (j == 3)
{
Point3 point(x y z);
textures.push_back(point);
}
}
//读取顶点坐标
else if (off[0] == ‘v‘)
{
istringstream sin(off);
std::string s;
float x y z;
//依次读取v以及顶点坐标的x、y、z坐标
sin >> s >> x >> y >> z;
Point3 point(x y z);
vertexs.push_back(point);
}
//读取顶点、UV坐标、法线索引
else if (off[0] == ‘f‘)
{
istringstream sin(off);
std::string s;
sin >> s;//去掉‘f‘
//读取3次,每次读取一组顶点、UV坐标、法线索引
int groupNum=0;
while(sin>>s)
{
groupNum++;
//sin >> s;
int index;
//根据‘/‘拆分读取的一组顶点、UV坐标、法线索引
vector v = split(s ‘/‘);
int j = 0;
for (string tmp : v)
{
istringstream cin(tmp);
cin >> index;
if (j == 0)
vertexsList.push_back(index);
else if (j == 1)
texturesList.push_back(index);
else if (j == 2)
normalsList.push_back(index);
j++;
}
}
//当一个面有3组索引时,表示这是一个三角面,将其存在对应三角数组中
if (groupNum == 3)
{
for (int k = 0; k < groupNum; k++)
{
trivertexsList.push_back(vertexsList[k]);
tritexturesList.push_back(texturesList[k]);
trinormalsList.push_back(normalsList[k]);
}
}
//当一个面有3组索引时,表示这是一个四角面,将其存在对应四角数组中
else if (groupNum == 4)
{
for (int k = 0; k < groupNum; k++)
{
quadvertexsList.push_back(vertexsList[k]);
quadtexturesList.push_back(texturesList[k]);
quadnormalsList.push_back(normalsList[k]);
}
}
vertexsList.clear();
texturesList.clear();
n
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1524 2019-12-18 17:32 loadTexture.cpp
文件 307 2019-12-17 20:15 loadTexture.h
文件 13126 2020-01-08 20:42 main.cpp
文件 5647872 2015-03-15 22:48 FreeImage所需文件FreeImage.dll
文件 67932 2015-03-15 22:48 FreeImage所需文件FreeImage.lib
文件 69 2020-01-08 22:31 FreeImage所需文件FreeImage导入说明书.txt
文件 2176 2016-08-19 01:50 includeAngel.h
文件 1290 2013-04-03 12:41 includeCheckError.h
文件 18165 2013-04-03 12:42 includemat.h
文件 2158 2016-08-19 10:50 includemesh.h
文件 785 2016-08-16 19:00 includeMesh_Painter.h
文件 1841 2016-10-17 15:45 includeTriMesh.h
文件 10441 2018-11-02 11:18 includevec.h
文件 844529 2018-11-09 16:46 textureall.png
文件 288221 2018-11-09 16:35 textureall_low.obj
文件 726351 2008-11-30 15:51 texturecartooncastle.jpg
文件 1051853 2008-11-30 16:11 texturecartooncastle.obj
文件 1172841 2019-12-20 00:04 texturedusk.jpg
文件 187855 2017-09-01 10:13 texturejianke.obj
文件 155452 2019-12-19 19:09 texturemoon.jpeg
文件 11575264 2016-11-21 15:26 textureMountains.jpg
文件 462 2017-04-07 09:45 textureMountains.mtl
文件 4755602 2017-04-07 09:45 textureMountains.obj
文件 2488142 2019-12-19 21:00 texture
ight.jpeg
文件 284749 2019-12-19 20:52 texturesky.obj
文件 71161 2019-12-19 19:02 texturesun.jpg
文件 98201 2019-12-19 23:40 texturesunny.jpeg
文件 57726 2019-11-28 20:53 FreeImage.h
文件 6653 2019-12-22 04:10 loadObj.cpp
文件 1469 2019-12-22 04:10 loadObj.h
............此处省略6个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)