资源简介
基于OpenGL的Loop网格细分,有算法实现源码和试例obj文件
代码片段和文件信息
#include
#include
#include
#include
#include
#include “loop.h“
#define ALPHA_MAX 20
#define ALPHA_LIMIT 0.469 /* converges to ~ 0.469 */
GLfloat ALPHA[] = {1.13333 -0.358974 -0.333333 0.129032 0.945783 2.0
3.19889 4.47885 5.79946 7.13634 8.47535 9.80865
11.1322 12.4441 13.7439 15.0317 16.3082 17.574
18.83 20.0769};
#define BETA_MAX 20
#define BETA_LIMIT 0.469 /* converges to ~ 0.469 */
GLfloat BETA[] = {0.46875 1.21875 1.125 0.96875 0.840932 0.75 0.686349
0.641085 0.60813 0.583555 0.564816 0.55024 0.5387
0.529419 0.52185 0.515601 0.510385 0.505987 0.502247 0.49904 };
#define NEWVERTEX 123.0
GLfloat alpha(GLuint n);
GLfloat beta(GLuint n);
long writeOBJ(WingedEdge* we char* filename) {
FILE* file;
Face* face;
Vertex* vertex;
GLfloat counter;
long lines = 0;
file = fopen(filename “w“);
if (!file) {
fprintf(stderr “writeOBJ() failed: can‘t open data file \“%s\“.\n“
filename);
// Modified by owada
return 0;
}
counter = 1.0;
vertex = we->vertices;
while (vertex) {
fprintf(file “v %f %f %f\n“ vertex->x vertex->y vertex->z);
lines++;
vertex->averaged = new Vertex ;
vertex->averaged->x = counter;
counter += 1.0;
vertex = vertex->next;
}
face = we->faces;
while (face) {
fprintf(file “f %d %d %d\n“
(int)(face->edge->head->averaged->x)
(int)(face->edge->prev->head->averaged->x)
(int)(face->edge->prev->prev->head->averaged->x));
lines++;
face = face->next;
}
fclose(file);
return lines;
}
WingedEdge* readOBJ(char* filename) {
FILE* file;
Model* model;
WingedEdge* we;
/* open the file */
file = fopen(filename “r“);
if (!file) {
fprintf(stderr “readOBJ() failed: can‘t open data file \“%s\“.\n“
filename);
exit(1);
}
/* allocate a new model */
model = new Model ;
model->position = new Vertex ;
model->position->x = 0.0;
model->position->y = 0.0;
model->position->z = 0.0;
firstPass(model file);
rewind(file);
we = secondPass(model file);
return we;
}
GLvoid firstPass(Model* model FILE* file) {
GLuint numVertices;
GLuint numFaces;
char buf[128];
numVertices = numFaces = 0;
while (fscanf(file “%s“ buf) != EOF) {
switch (buf[0]) {
case ‘#‘: /* comments*/
/* eat up the rest of the line */
fgets(buf sizeof(buf) file);
break;
case ‘v‘: /* a vertex! */
/* ignore all but the simple case */
numVertices++;
fgets(buf sizeof(buf) file);
break;
case ‘f‘: /* a face! */
numFaces++;
fgets(buf sizeof(buf) file);
break;
default: /* I don‘t care about the other cases! */
fgets(buf sizeof(buf) file);
break;
}
}
model->numFaces = numFaces;
model->numVertices = numVertices;
/* Our work here is done. */
}
WingedEdge* secondPass(Model*
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-16 12:13 Loop2\
目录 0 2018-05-08 09:12 Loop2\.vs\
目录 0 2018-05-08 09:12 Loop2\.vs\Loop2\
目录 0 2018-05-08 09:12 Loop2\.vs\Loop2\v15\
文件 35840 2018-05-08 09:13 Loop2\.vs\Loop2\v15\.suo
目录 0 2018-04-10 19:43 Loop2\Debug\
文件 68096 2018-04-16 17:55 Loop2\Debug\Loop2.exe
文件 392736 2018-04-16 17:55 Loop2\Debug\Loop2.ilk
文件 708608 2018-04-16 17:55 Loop2\Debug\Loop2.pdb
文件 1386496 1997-11-25 17:11 Loop2\Debug\glaux.dll
文件 121856 2008-04-14 12:00 Loop2\Debug\glu32.dll
文件 169984 1998-08-18 16:25 Loop2\Debug\glut.dll
文件 169984 1998-08-18 16:25 Loop2\Debug\glut32.dll
文件 713728 2008-04-14 12:00 Loop2\Debug\opengl32.dll
目录 0 2014-12-01 21:59 Loop2\Loop2\
目录 0 2018-04-16 17:55 Loop2\Loop2\Debug\
文件 932 2018-04-10 19:43 Loop2\Loop2\Debug\Loop2.Build.CppClean.log
文件 83 2014-12-01 21:59 Loop2\Loop2\Debug\Loop2.lastbuildstate
文件 2623 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.log
目录 0 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\
文件 6854 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\CL.read.1.tlog
文件 1784 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\CL.write.1.tlog
文件 170 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\Loop2.lastbuildstate
文件 1862 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\cl.command.1.tlog
文件 1582 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\li
文件 3250 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\li
文件 684 2018-04-16 17:55 Loop2\Loop2\Debug\Loop2.tlog\li
文件 68432 2018-04-10 19:43 Loop2\Loop2\Debug\loop.obj
文件 30998 2018-04-16 17:55 Loop2\Loop2\Debug\ob
文件 7400 2018-04-10 19:43 Loop2\Loop2\Debug\print.obj
文件 84992 2018-04-16 17:55 Loop2\Loop2\Debug\vc120.idb
............此处省略34个文件信息
评论
共有 条评论