資源簡介
opengl加載off格式文件
。
代碼片段和文件信息
//?lab2_sam.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include
#include
#include
using?namespace?std;
//?Windows?include?files?
#ifdef?_WIN32
#include?
#endif
//?OpenGL?include?files?
#include?
#include?
#include?
typedef?struct?Vertex
{
float?xyz;
}Vertex;
typedef?struct?Facep
{
int?num;
int?order[3];
}Facep;
static?char?*filename=“bird.off“;
Vertex?ver[10000];
Facep?fap[20000];
int?ijkn_noden_facen_edge;
float?scale=1spin=0;
static?int?window_height?=?800;
static?int?window_width?=?800;
int?readoff(const?char*?filename)
{
FILE?*fp;
if(!(fp=fopen(filename“r“)))
{
fprintf(stderr“Open?fail“);
return?0;
}
????char?buffer[1024];
if(fgets(buffer1023fp))
{
if(!strstr(buffer“OFF“))
{
printf(“It‘s?not?a?OFF?FILE“);
return?0;
}
if(fgets(buffer1023fp))
{
sscanf(buffer“%d?%d?%d“&n_node&n_face&n_edge);
for(i=0;i {
fgets(buffer1023fp);
sscanf(buffer“%f%f%f“&ver[i].x&ver[i].y&ver[i].z);
}
for(i=0;i {
fgets(buffer1023fp);
int?temp;
sscanf(buffer“%d%d%d%d“&fap[i].num&fap[i].order[0]&fap[i].order[1]&fap[i].order[2]);
}
}
????}
}
void?redraw(void)
{
int?a=clock();
glClearColor(0.0?0.0?0.0?0.0);
????
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(scalescalescale);
glRotatef(spin0.00.01.0);
glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
glColor3f(1.00.00.0);
glBegin(GL_TRIANGLES);
for(i=0;i {
int?count=fap[i].order[0];
glVertex3f(ver[count].xver[count].yver[count].z);
count=fap[i].order[1];
glVertex3f(ver[count].xver[count].yver[count].z);
count=fap[i].order[2];
glVertex3f(ver[count].xver[count].yver[count].z);
}
glEnd();
glFlush();
glutSwapBuffers();
int?b=clock();
a=b-a;
printf(“繪制時間:%d\n“a);
}
void?keyboard(unsigned?char?key?int?x?int?y)
{
switch(key)
{
???case?‘p‘:glPolygonMode(GL_FRONT_AND_BACK?GL_POINT);glutPostRedisplay();break;
???????case?‘l‘:glPolygonMode(GL_FRONT_AND_BACK?GL_LINE);glutPostRedisplay();break;
???????case?‘f‘:glPolygonMode(GL_FRONT_AND_BACK?GL_FILL);glutPostRedisplay();break;
???case?‘q‘:exit(1);
}
}
void?mouse(int?buttonint?stateint?xint?y)
{
if(button==GLUT_LEFT_BUTTON?&&?state==GLUT_DOWN)
{
scale*=1.1;
glutPostRedisplay();
}
if(button==GLUT_RIGHT_BUTTON?&&?state==GLUT_DOWN)
{
for(i=0;i<10;i++)
{
spin=spin+1;
????glutPostRedisplay();
glFlush();
}
}
}
void?init(int?*argc?char?**argv)
{
??//?Open?window?
??glutInit(argc?argv);
??glutInitWindowPosition(100?100);
??glutInitWindowSize(window_width?window_height);
?
??glutCreateWindow(“
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-03-20?14:59??lab2_sam\
?????文件??????336048??2014-03-12?18:39??lab2_sam\bird.off
?????目錄???????????0??2014-03-20?14:54??lab2_sam\Debug\
?????文件??????336048??2014-03-12?18:39??lab2_sam\Debug\bird.off
?????文件???????32256??2014-03-20?14:58??lab2_sam\Debug\lab2_sam.exe
?????文件?????????406??2014-03-20?10:26??lab2_sam\Debug\lab2_sam.exe.manifest
?????文件??????396816??2014-03-20?14:58??lab2_sam\Debug\lab2_sam.ilk
?????文件??????805888??2014-03-20?14:58??lab2_sam\Debug\lab2_sam.pdb
?????目錄???????????0??2014-03-20?11:05??lab2_sam\ipch\
?????目錄???????????0??2014-03-20?13:53??lab2_sam\ipch\lab2_sam-c79e9188\
?????文件?????2359296??2014-03-20?13:53??lab2_sam\ipch\lab2_sam-c79e9188\lab2_sam-3fa8b74d.ipch
?????目錄???????????0??2014-03-20?10:31??lab2_sam\lab2_sam\
?????文件????34426880??2014-03-20?14:59??lab2_sam\lab2_sam.sdf
?????文件?????????891??2014-03-20?09:32??lab2_sam\lab2_sam.sln
?????文件???????19456??2014-03-20?14:59??lab2_sam\lab2_sam.suo
?????文件??????336048??2014-03-12?18:39??lab2_sam\lab2_sam\bird.off
?????目錄???????????0??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\
?????文件??????336048??2014-03-12?18:39??lab2_sam\lab2_sam\Debug\bird.off
?????文件????????1570??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\cl.command.1.tlog
?????文件???????24032??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\CL.read.1.tlog
?????文件?????????984??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\CL.write.1.tlog
?????文件????????1659??2014-03-20?10:24??lab2_sam\lab2_sam\Debug\lab2_sam.Build.CppClean.log
?????文件?????????381??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\lab2_sam.exe.intermediate.manifest
?????文件??????????71??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\lab2_sam.lastbuildstate
?????文件????????4087??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\lab2_sam.log
?????文件???????67475??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\lab2_sam.obj
?????文件?????1179648??2014-03-20?10:24??lab2_sam\lab2_sam\Debug\lab2_sam.pch
?????文件?????????707??2014-03-20?10:26??lab2_sam\lab2_sam\Debug\lab2_sam.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2014-03-20?10:24??lab2_sam\lab2_sam\Debug\lab2_sam.write.1.tlog
?????文件???????????2??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\li
?????文件???????????2??2014-03-20?14:58??lab2_sam\lab2_sam\Debug\li
............此處省略39個文件信息
評論
共有 條評論