資源簡介
This program implements four different mesh simplification algorithms. After loading a mesh, the user can easily remove triangles from the mesh and the results are displayed in real time. The mesh can also be rotated and moved closer to or farther away from the viewer.
The goal of mesh simplification is to display a 3D polygonal mesh with fewer triangles while retaining the same shape. In the example above, the original cow model (upper left) is made up of over 5800 triangles. We can easily remove thousands of triangles from this mesh and still display a very similar cow model. While the 500 triangle cow is a cruder representation, this may not make a difference if the cow is far away from the viewer.

代碼片段和文件信息
#include?“glmodelwin.h“
#include?“pmesh.h“
extern?PMesh*?g_pProgMesh;?
extern?Mesh*?g_pMesh;
extern?HINSTANCE?g_hInstance;
extern?char?g_filename[];
LRESULT CALLBACK?wndProc(HWND?UINT?WPARAM?LPARAM);
//?Display?title?text?for?window
void?glModelWindow::displayWindowtitle()
{
assert(g_pProgMesh);
char?temp[1024]?=?{‘\0‘};
sprintf(temp?“Jeff?Somers?Mesh?Simplification?Viewer?-?%s?#?Tris:?%d?%s“
g_pProgMesh->getEdgeCostDesc()?g_pProgMesh->numVisTris()?g_filename);
SetWindowText(getHWnd()?temp);
}
//?Resize?the?OpenGL?window
GLvoid?glModelWindow::reSizeScene(GLsizei?width?GLsizei?height)
{
if?(height==0)?height?=?1;?//?height?==?0?not?allowed
glViewport(00widthheight);
width_?=?width;
height_?=?height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//?Calculate?The?Perspective?of?the?winodw
gluPerspective(45.0f(GLfloat)width/(GLfloat)heightMIN_DISTANCEMAX_DISTANCE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//?Initialize?OpenGL
int?glModelWindow::initOpenGL(GLvoid)
{
glShadeModel(GL_SMOOTH);?//?Gouraud?shading
glClearColor(0.0f?0.0f?0.0f?0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT?GL_NICEST);
//?Enable?lights?and?lighting
glEnable(GL_LIGHT0);?//?default?value?is?(1.0?1.0?1.0?1.0)
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);?//?backface?culling
return?true;
}
//?Display?the?mesh
bool?glModelWindow::displayMesh()
{
glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
//?Set?lookat?point
????glLoadIdentity();
gluLookAt(00dist_?000?010);
????glRotatef(elevation_100);
????glRotatef(azimuth_010);
if?(bSmooth_)
{
glShadeModel(GL_SMOOTH);?//?already?defined?in?initOpenGL
}
else?
{
glShadeModel(GL_FLAT);
}
if?(bFill_)?//?fill?in?triangles?or?just?display?outlines?
{
glPolygonMode(?GL_FRONT?GL_FILL?);
}
else
{
glPolygonMode(?GL_FRONT?GL_LINE?);
}
//?NOTE:?we?could?use?display?lists?here.??That?would?speed?things
//?up?which?the?user?is?rotating?the?mesh.??However?since?speed?isn‘t
//?a?bit?issue?I?didn‘t?use?them.
if?(g_pProgMesh)
{
//?Make?everything?grey
glColor3ub(128?128?128);
glBegin(GL_TRIANGLES);
for?(int?i=0;?inumTris();?i++)
{
triangle?t;
float?a[3];
if?(g_pProgMesh->getTri(i?t)?&&?t.isActive())
{
if?(bSmooth_)
{
const?vertex&?v1?=?t.getVert1vertex();
const?float*?pFltV1Norm?=?v1.getArrayVertNorms();
glNormal3fv(pFltV1Norm);
const?float*?pFltArray1?=?v1.getArrayVerts();
glVertex3fv(pFltArray1);
const?vertex&?v2?=?t.getVert2vertex();
const?float*?pFltV2Norm?=?v2.getArrayVertNorms();
glNormal3fv(pFltV2Norm);
const?float*?pFltArray2?=?v2.getArrayVerts();
glVertex3fv(pFltArray2);
const?vertex&?v3?=?t.getVert3ver
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????50262??1998-09-08?22:26??網格簡化源碼\jmspmesh\apple.ply
?????文件?????323275??1998-09-08?22:26??網格簡化源碼\jmspmesh\big_porsche.ply
?????文件??????16668??1998-09-08?22:53??網格簡化源碼\jmspmesh\cat.ply
?????文件?????177472??1998-09-08?22:53??網格簡化源碼\jmspmesh\cow.ply
?????文件??????28104??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\BuildLog.htm
?????文件??????91914??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\glmodelwin.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\glmodelwin.sbr
?????文件?????201310??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\main.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\main.sbr
?????文件?????708997??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\mesh.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\mesh.sbr
?????文件?????????67??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\mt.dep
?????文件????4705280??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.bsc
?????文件?????895488??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.exe
?????文件????????406??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.exe.em
?????文件????????472??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.exe.em
?????文件????????381??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.exe.intermediate.manifest
?????文件????2202748??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.ilk
?????文件????4254720??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\oglpmesh.pdb
?????文件????1018004??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\pmesh.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\pmesh.sbr
?????文件???????4804??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\polydemo.res
?????文件?????284908??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\triangle.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\triangle.sbr
?????文件?????205824??2009-01-06?10:16??網格簡化源碼\jmspmesh\Debug\vc60.idb
?????文件?????167936??2009-01-06?10:06??網格簡化源碼\jmspmesh\Debug\vc60.pdb
?????文件?????674816??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\vc90.idb
?????文件?????413696??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\vc90.pdb
?????文件?????243535??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\vec3.obj
?????文件??????????0??2009-03-06?15:15??網格簡化源碼\jmspmesh\Debug\vec3.sbr
............此處省略59個文件信息
評論
共有 條評論