资源简介
计算机图形学的作业,内含实验报告、源代码以及模型数据,供参考。
![](http://www.nz998.com/pic/31344.jpg)
代码片段和文件信息
/* Rotating cube with viewer movement from Chapter 5 */
/* Cube definition and display similar to rotating--cube program */
/* We use the Lookat function in the display callback to point
the viewer whose position can be altered by the xXyYz and Z keys.
The perspective view is set in the reshape callback */
#include
#ifdef __APPLE__
#include
#else
#include
#include < fstream >
#include < string>
#endif
#define N 2000
GLfloat vertices[N][3];
GLfloat normals[N][3];
GLfloat colors[N][3] = { { 1.00.00.0 }{ 1.0 0.5 0.0 }{ 1.00.01.0 }
{ 0.01.00.0 }{ 1.01.00.0 }{ 0.01.01.0 }
};
GLint nFaces = 0 nVertices = 0 nEdges = 0;
GLint c = 2;
void drawHorse(int n)//绘图函数
{
for (int a = 0; a < n; a++)
{
int point1 = normals[a][0];
int point2 = normals[a][1];
int point3 = normals[a][2];
glShadeModel(GL_SMOOTH);
glBegin(GL_POLYGON);//画出一个像素片
glColor3fv(colors[point1]);
glVertex3fv(vertices[point1]);
glColor3fv(colors[point2]);
glVertex3fv(vertices[point2]);
glColor3fv(colors[point3]);
glVertex3fv(vertices[point3]);
glEnd();
}
}
void load_off(char* filename)
{
std::ifstream fin;
fin.open(filename);
std::string off;
std::getline(fin off);//读入首行字符串“OFF“
fin >> nVertices >> nFaces >> nEdges; //读入点、面、边数目
double x y z;
for (int i = 0; i {
fin >> x >> y >> z; //逐行读入顶点坐标;
vertices[i][0] = x; /*修改此处代码,将坐标保存到外部变量中*/
vertices[i][1] = y;
vertices[i][2] = z;
colors[i][0] = colors[i % 6][0];
colors[i][1] = colors[i % 6][1];
colors[i][2] = colors[i % 6][2];
}
int n vid1 vid2 vid3;
for (int i = 0; i {
fin >> n >> vid1 >> vid2 >> vid3; //逐行读入面的顶点序列;
normals[i][0] = vid1; /*修改此处代码,将面列表保存到外部变量中*/
normals[i][1] = vid2;
normals[i][2] = vid3;
}
fin.close();
}
static GLfloat theta[] = {0.00.00.0};
static GLdouble viewer[] = { 0.0 0.0 -10.0 }; /* initial viewer location */
static GLint axis = 0;
static GLfloat X = 1.0 Y = 1.0 Z = 1.0;
static GLfloat level = 0 vertical = 0;
int xRotate yRotate zRotate;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Update viewer position in modelview matrix */
glLoadIdentity();//放到原点
glPushMatrix();
gluLookAt(viewer[0] viewer[1] viewer[2] 0.0 0.0 0.0 0.0 1.0 -1.0);//相机位置
glTranslatef(level vertical 0.0);
glScalef(XYZ);
if(xRotate = 1)
glRotatef(theta[0] 1.0 0.0 0.0);//绕x轴旋转
// drawHorse(nFaces);
glRotatef(theta[1] 0.0 1.0 0.0);//绕y轴旋转
// drawHorse(nFaces);
glRotatef(theta[2] 0.0 0.0 1.0);//绕z轴旋转
drawHorse(nFaces);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void mouse(int btn int state int x int y)
{
if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
;
if (btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
;
if (btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN);
exit(0);
display();
}
void Specia
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5188 2016-04-04 22:49 【图形学第二次作业】22920142203912_檀锦彬_上机作业2\Source.cpp
文件 39433 2016-03-24 20:14 【图形学第二次作业】22920142203912_檀锦彬_上机作业2\horse.off
文件 673878 2016-05-28 15:45 【图形学第二次作业】22920142203912_檀锦彬_上机作业2\实验报告.docx
目录 0 2016-05-28 15:46 【图形学第二次作业】22920142203912_檀锦彬_上机作业2\
- 上一篇:关于抽象数据类型--有理数数据结构
- 下一篇:CustomPlotTest.zip
相关资源
- 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室内场景的绘制,包括碰撞检测
评论
共有 条评论