-
大小: 19KB文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-05-09
- 語言: C/C++
- 標(biāo)簽: 山東大學(xué)??圖形學(xué)??openmesh??半邊結(jié)構(gòu)??網(wǎng)格細(xì)分??
資源簡介
自己構(gòu)建的半邊結(jié)構(gòu),并實(shí)現(xiàn)了loop細(xì)分算法,并實(shí)現(xiàn)了3d模型的縮放等
代碼片段和文件信息
#include?“stdafx.h“
#include???
#include?“GL\glut.h“
#include?
#include?
#include?
#include?
#include
#include
using?namespace?std;
//用于點(diǎn)線面的個(gè)數(shù)
int?numofvertex?=?0;
int?numofface?=?0;
int?numofline?=?0;
//定義窗口大小
int?WIDTH?=?600;
int?HEIGHT?=?600;
float?maxx?=?-1;
float?maxy?=?-1;
float?maxz?=?-1;
float?minx?=?1;
float?miny?=?1;
float?minz?=?1;
//定義攝像機(jī)位置和方向
GLfloat?ShootPosition[]?=?{?000?};
GLfloat?ShootDirect[]?=?{?000?};
//與實(shí)現(xiàn)旋轉(zhuǎn)角度大小相關(guān)的參數(shù),只需要兩個(gè)就可以完成
float?scale?=?1.0;
float?px;
float?py;
float?theta1?=?0;
float?theta2?=?0;
float?radius?=?0;
int?displaystate?=?0;
float?PI?=?3.1415926;
//定義點(diǎn)、面、邊等結(jié)構(gòu)
struct?vertex;
struct?face;
struct?halfedge;
struct?he_face;
struct?normalVec;
struct?iedge;
vertex*?vertexs;
face*?faces;
he_face**?hefaces;
normalVec*?normalvectors;
iedge**?iedges;
//定義半邊結(jié)構(gòu)
struct?halfedge?{
halfedge*?next;//下一條半邊
halfedge*?opposite;//與其相反的半邊
int?end;//所指的點(diǎn)
bool?visit;//是否被訪問過
he_face*?face;//所屬的面
//定義構(gòu)造函數(shù)并初始化
halfedge()?{
next?=?NULL;
opposite?=?NULL;
end?=?-1;
face?=?NULL;
visit?=?false;
}
};
//定義半邊結(jié)構(gòu)中的點(diǎn)結(jié)構(gòu)
struct?vertex?{
//點(diǎn)坐標(biāo)
float?x;
float?y;
float?z;
//指向該點(diǎn)的半邊
halfedge*?edge;
//是否被訪問過
bool?visit;
//空構(gòu)造函數(shù),初始化
vertex()?{
visit?=?false;
}
//構(gòu)造函數(shù)
vertex(float?a?float?b?float?c)?{
x?=?a;
y?=?b;
z?=?c;
edge?=?NULL;
visit?=?false;
}
};
//定義正常的點(diǎn)的結(jié)構(gòu)或者成為向量
struct?normalVec?{
//點(diǎn)坐標(biāo)
float?x;
float?y;
float?z;
normalVec()?{
}
normalVec(float?a?float?b?float?c)?{
x?=?a;
y?=?b;
z?=?c;
}
};
//定義半邊中面的結(jié)構(gòu)
struct?he_face?{
//包含的半邊
halfedge*?edge;
//是否被訪問過
bool?visit;
he_face()?{
edge?=?NULL;
visit?=?false;
}
};
//定義正常的面的結(jié)構(gòu)
struct?face?{
//構(gòu)成該面的點(diǎn)的數(shù)量
int?numofv;
//構(gòu)成該面的點(diǎn)
int*?vertexs;
face()?{
}
face(int?nv)?{
numofv?=?nv;
vertexs?=?new?int[nv];
}
};
//定義自己的邊結(jié)構(gòu)
struct?iedge?{
//起點(diǎn)
int?start;
//在loop細(xì)分中的中間點(diǎn)
int?middle;
//所含半邊(兩條)
halfedge*?he;
iedge*?next;
iedge()?{
start?=?-1;
he?=?NULL;
next?=?NULL;
middle?=?-1;
}
};
//讀取3d文件,off格式?
void?readFile()?{
char?data[100];
ifstream?infile;
infile.open(“bunny.off“);
//讀取“off”字符
infile?>>?data;
//讀取點(diǎn)、面、邊的數(shù)量
infile?>>?numofvertex;
infile?>>?numofface;
infile?>>?numofline;
vertexs?=?new?vertex[numofvertex];
faces?=?new?face[numofface];
int?vnum?=?0;
int?fnum?=?0;
//構(gòu)建“點(diǎn)”集
while?(vnum? float?x;
float?y;
float?z;
infile?>>?x;
infile?>>?y;
infile?>>?z;
vertexs[vnum]?=?vertex(x?y?z);
vnum++;
}
//構(gòu)建“面”集
while?(fnum {
int?numofv;
infile?>>?numofv;
face?f?=?face(numofv);
for?(int?i?=?0;?i? {
int?v;
infile?>>?v;
f.vertexs[i]?=?v;
}
faces[fnum]?=?f;
fnum++;
}
infile.close();
}
int?getMiddle(int?start?int?end?iedge**?iedges)?{
iedge*?temp?=?iedges[start];
評論
共有 條評論