资源简介
实现读取obj文件并创建显示列表绘制图像,键盘可控制旋转、缩放图像功能

代码片段和文件信息
// lesson12_suchunyin.cpp : 此文件包含 “main“ 函数。程序执行将在此处开始并结束。
//
#include
#include
#include
#include
#include
#include
using namespace std;
int n = 30; //每一次转动30°
GLdouble view[2] = { 08 }; //设置旋转观察点初始位置
int i = 0; //旋转次数控制
GLdouble r = view[1]; //观察点旋转半径
float t = 0.5; //拉近拉远的距离
vector>vSets; //存放顶点(xyz)坐标
vector>fSets; //存放面的三个顶点索引
vector>lSets; //存放线的顶点索引
vector>cSets; //存放颜色
vector name; //存放每一部分名称
GLint part = -1; //每一部分的编号
string filePath = “D://计算机图形学//Squirtle.obj“;
void ObjLoader(string filename)
{
ifstream file(filename);
string line;
while (getline(file line))
{
if (line.substr(0 1) == “o“)
{
string str;
istringstream on(line.substr(2));
on >> str;
name.push_back(str);
part++;
}
else if (line.substr(0 1) == “c“)
{
vector color; //记录面对应的颜色
GLfloat R G B A;
istringstream cl(line.substr(2));
cl >> R; cl >> G; cl >> B; cl >> A;
color.push_back(R);
color.push_back(G);
color.push_back(B);
color.push_back(A);
cSets.push_back(color);
}
else if (line.substr(0 1) == “v“)
{
vector Point;
GLfloat x y z;
istringstream s(line.substr(2));
s >> x; s >> y; s >> z;
Point.push_back(x);
Point.push_back(y);
Point.push_back(z);
vSets.push_back(Point);
}
else if (line.substr(0 1) == “f“)
{
vector vIndexSets(4);
GLint u;
GLint v;
GLint w;
istringstream vtns(line.substr(2));
vtns >> u;
vtns >> v;
vtns >> w;
vIndexSets[0] = u - 1;
vIndexSets[1] = v - 1;
vIndexSets[2] = w - 1;
vIndexSets[3] = part;
fSets.push_back(vIndexSets);
}
else if (line.substr(0 1) == “l“)
{
vector lIndexSets;
GLint s t;
istringstream vt(line.substr(2));
vt >> s; vt >> t;
lIndexSets.push_back(s - 1);
lIndexSets.push_back(t - 1);
lSets.push_back(lIndexSets);
}
}
file.close();
}
GLint Squirtle = 1;
GLint MatrixMode = 2;
GLint VIEW = 3;
void createList() {
glNewList(Squirtle GL_COMPILE); //杰尼龟的显示列表
glBegin(GL_TRIANGLES); //开始绘制面
for (int i = 0; i < fSets.size(); i++) {
GLfloat VN[3];
//三个顶点
GLfloat SV1[3];
GLfloat SV2[3];
GLfloat SV3[3];
if ((fSets[i]).size() != 4) {
cout << “面顶点数组有误!“ << endl;
}
else {
//配置颜色:壳一个颜色,身体和尾巴一个颜色
glColor4f(cSets[fSets[i][3]][0] cSets[fSets[i][3]][1] cSets[fSets[i][3]][2] cSets[fSets[i][3]][3]);
GLint firstVertexIndex = (fSets[i])[0];//取出顶点索引
GLint secondVertexIndex = (fSets[i])[1];
GLint thirdVertexIndex = (fSets[i])[2];
SV1[0] = (vSets[firstVertexIndex])[0];//第一个顶点
SV1[1] = (vSets[firstVertexIndex])[1];
SV1[2] = (vSets[firstVertexIndex])[2];
SV2[0] = (vSets[secondVertexIndex])[0]; //第二个
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 156861 2020-05-11 00:02 ziyuan2\Squirtle.obj
文件 7791 2020-06-17 11:27 ziyuan2\ziyuan2.cpp
目录 0 2020-06-17 11:29 ziyuan2\
相关资源
- OpenGL参考手册
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- OPENGL实现世界上最小的3D游戏
- VS2012OpenGL配置所需要的全部libdllh文件
- 基于OpenGL的仿蝗虫机器人三维动态仿
- 图形学 - OpenGL实现3种三维茶壶显示源
- opengl程序-会跳舞的骷髅
- opengl实现三维网格光顺Laplacian算法
- opengl——爆炸
- OpenGL三维地形建模
- opengl游戏编程徐明亮版(含源码)
- 用OPENGL画的一个简单的直升飞机
- opengl完美天空盒
- 3D绘图程序设计:使用Direct3D 10/9和Ope
- OpenGL绘制可运动自行车源程序.zip
- OpenGL实现飘动效果
- opengl室内场景的绘制,包括碰撞检测
评论
共有 条评论