计算机图形学大作业,兔子
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//对模型视图矩阵堆栈应用随后的矩阵操作
glMatrixMode(GL_MODELVIEW);
//重置当前指定的矩阵为单位矩阵
glLoadIdentity();
}
void sPecialkeyFuc(int key,int x,int y){
if(key==GLUT_KEY_UP){
xRotAngle-=20.0f;
//正交投影
if(w<h)
glOrtho(-coordinatesize,coordinatesize,-coordinatesize/ratio,coordinatesize/ratio,-coordinatesize,coordinatesize);
else
glOrtho(-coordinatesize*ratio,coordinatesize*ratio,-coordinatesize,coordinatesize,-coordinatesize,coordinatesize);
glutMainLoop();
return 0;
}
//窗口大小变化时的处理函数
glutReshapeFunc(changSize);
//设置显示回调函数
glutDisplayFunc(renderScreen);
//设置按键输入处理回调函数
glutSpecialFunc(sPecialkeyFuc);
//设置全局渲染参数
setupRederingState();
}
else if(key==GLUT_KEY_DOWN){
xRotAngle+=20.0f;
}
else if(key==GLUT_KEY_LEFT){
yRotAngle-=20.0f;
}
else if(key==GLUT_KEY_RIGHT){
yRotAngle+=20.0f;
}
//重新绘制
glutPostRedisplay();
//获取系统的高像素
SCREEN_HEIGHT=glutGet(GLUT_SCREEN_HEIGHT);
glutCreateWindow("PointsDemo");
//设置窗口大小
glutReshapeWindow(windowWidth,windowHeight);
//窗口居中显示
glutPositionWindow((SCREEN_WIDTH-windowWidth)/2,(SCREEN_HEIGHT-windowHeight)/2);
GLint windowHeight=600;
//绕x轴旋转角度
GLfloat xRotAngle=0.0f;
//绕y轴旋转角度
GLfloat yRotAngle=0.0f;
//显示回调函数
void renderScreen(void){
GLfloat x,y,z,angle;
//把整个窗口清理为当前清理颜色
GLfloat coordinatesize=100.0f;
//设置视口和窗口大小一致
glViewport(0,0,w,h);
//对投影矩阵应用随后的矩阵操作
glMatrixMode(GL_PROJECTION);
//重置当前指定的矩阵为单位矩阵
glLoadIdentity();
ratio=(GLfloat)w/(GLfloat)h;
glClear(GL_COLOR_BUFFER_BIT);
//将当前Matrix状态入栈
glPushMatrix();
//进行矩阵乘变换,实验旋转
glRotatef(xRotAngle,1.0f,0.0f,0.0f);
glRotatef(yRotAngle,0.0f,1.0f,0.0f);
//开始绘点
glVertex3f(6*x,6*y,6*z);
}
fclose(fp);
glEnd(); //结束绘点
//恢复压入栈的Matrix
glPopMatrix();
//交换两个缓冲区的指针
glutSwapBuffers();
}
//设置Redering State
void setupRederingState(void){
glBegin(GL_POINTS);
FILE *fp;
fp=fopen("bunny_iH.ply2","r");
while(!feof(fp))
{ຫໍສະໝຸດ Baidu
GLfloat x,y,z;
x=y=z=0;
fscanf(fp,"%f",&x);
fscanf(fp,"%f",&y);
fscanf(fp,"%f",&z);
}
int main(int argc, char* argv[])
{
//初始化glut
glutInit(&argc,argv);
//使用双缓冲区模式
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
//获取系统的宽像素
SCREEN_WIDTH=glutGet(GLUT_SCREEN_WIDTH);
//设置清理颜色
glClearColor(0.2f,0.3f,0.7f,0.0f);
//设置绘画颜色
glColor3f(1.0f,1.0f,1.0f);
}
//窗口大小变化回调函数
void changSize(GLint w,GLint h){
//横宽比率
GLfloat ratio;
//设置坐标系为x(-100.0f,100.0f)、y(-100.0f,100.0f)、z(-100.0f,100.0f)
#include <gl/glut.h>
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
//获取屏幕的宽度
GLint SCREEN_WIDTH=0;
GLint SCREEN_HEIGHT=0;
//设置程序的窗口大小
GLint windowWidth=800;
glMatrixMode(GL_MODELVIEW);
//重置当前指定的矩阵为单位矩阵
glLoadIdentity();
}
void sPecialkeyFuc(int key,int x,int y){
if(key==GLUT_KEY_UP){
xRotAngle-=20.0f;
//正交投影
if(w<h)
glOrtho(-coordinatesize,coordinatesize,-coordinatesize/ratio,coordinatesize/ratio,-coordinatesize,coordinatesize);
else
glOrtho(-coordinatesize*ratio,coordinatesize*ratio,-coordinatesize,coordinatesize,-coordinatesize,coordinatesize);
glutMainLoop();
return 0;
}
//窗口大小变化时的处理函数
glutReshapeFunc(changSize);
//设置显示回调函数
glutDisplayFunc(renderScreen);
//设置按键输入处理回调函数
glutSpecialFunc(sPecialkeyFuc);
//设置全局渲染参数
setupRederingState();
}
else if(key==GLUT_KEY_DOWN){
xRotAngle+=20.0f;
}
else if(key==GLUT_KEY_LEFT){
yRotAngle-=20.0f;
}
else if(key==GLUT_KEY_RIGHT){
yRotAngle+=20.0f;
}
//重新绘制
glutPostRedisplay();
//获取系统的高像素
SCREEN_HEIGHT=glutGet(GLUT_SCREEN_HEIGHT);
glutCreateWindow("PointsDemo");
//设置窗口大小
glutReshapeWindow(windowWidth,windowHeight);
//窗口居中显示
glutPositionWindow((SCREEN_WIDTH-windowWidth)/2,(SCREEN_HEIGHT-windowHeight)/2);
GLint windowHeight=600;
//绕x轴旋转角度
GLfloat xRotAngle=0.0f;
//绕y轴旋转角度
GLfloat yRotAngle=0.0f;
//显示回调函数
void renderScreen(void){
GLfloat x,y,z,angle;
//把整个窗口清理为当前清理颜色
GLfloat coordinatesize=100.0f;
//设置视口和窗口大小一致
glViewport(0,0,w,h);
//对投影矩阵应用随后的矩阵操作
glMatrixMode(GL_PROJECTION);
//重置当前指定的矩阵为单位矩阵
glLoadIdentity();
ratio=(GLfloat)w/(GLfloat)h;
glClear(GL_COLOR_BUFFER_BIT);
//将当前Matrix状态入栈
glPushMatrix();
//进行矩阵乘变换,实验旋转
glRotatef(xRotAngle,1.0f,0.0f,0.0f);
glRotatef(yRotAngle,0.0f,1.0f,0.0f);
//开始绘点
glVertex3f(6*x,6*y,6*z);
}
fclose(fp);
glEnd(); //结束绘点
//恢复压入栈的Matrix
glPopMatrix();
//交换两个缓冲区的指针
glutSwapBuffers();
}
//设置Redering State
void setupRederingState(void){
glBegin(GL_POINTS);
FILE *fp;
fp=fopen("bunny_iH.ply2","r");
while(!feof(fp))
{ຫໍສະໝຸດ Baidu
GLfloat x,y,z;
x=y=z=0;
fscanf(fp,"%f",&x);
fscanf(fp,"%f",&y);
fscanf(fp,"%f",&z);
}
int main(int argc, char* argv[])
{
//初始化glut
glutInit(&argc,argv);
//使用双缓冲区模式
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
//获取系统的宽像素
SCREEN_WIDTH=glutGet(GLUT_SCREEN_WIDTH);
//设置清理颜色
glClearColor(0.2f,0.3f,0.7f,0.0f);
//设置绘画颜色
glColor3f(1.0f,1.0f,1.0f);
}
//窗口大小变化回调函数
void changSize(GLint w,GLint h){
//横宽比率
GLfloat ratio;
//设置坐标系为x(-100.0f,100.0f)、y(-100.0f,100.0f)、z(-100.0f,100.0f)
#include <gl/glut.h>
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
//获取屏幕的宽度
GLint SCREEN_WIDTH=0;
GLint SCREEN_HEIGHT=0;
//设置程序的窗口大小
GLint windowWidth=800;