資源簡介
計算機圖形學的作業,內含實驗報告、源代碼以及模型數據,供參考。

代碼片段和文件信息
/*?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??
#include?
#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? {
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
評論
共有 條評論