資源簡介
visual studio C++ 讀取PLY文件,通用性較好,并使用OpenGL對模型進行顯示。
代碼片段和文件信息
#include?
#include?“ply.h“
plyloaddraw?mesh;
???#define?M_PI??3.14159265358979323846
???????static??int?wy=0;
???static?int?sy=0;
???static?int?ay=0;
???static?int?dy=0;
???static?int?zz=0;
???static?int?xz=0;
???static?int?q=0;
???static?int?e=0;
???static?int?r=0;
???static?int?f=0;
static?float?c=M_PI/180.0f;?//弧度和角度轉換參數??
static?int?du=90oldmy=-1oldmx=-1;?//du是視點繞y軸的角度
static?float?rad=1.5fh=0.0f;?//r是視點繞y軸的半徑h是視點高度即在y軸上的坐標??
void?setLight()
{
?static?const?GLfloat?light_position[]?=?{3.0f10.0f10.0f0.0f};??
?static?const?GLfloat?light_ambient[]?=?{1.0f1.0f1.0f1.0f};
?static?const?GLfloat?light_diffuse[]?=?{0.2f0.5f0.5f1.0f};
?static?const?GLfloat?light_specular[]?=?{1.0f1.0f1.0f1.0f};
??//??static?const?GLfloat?light_direction[]?=?{0.0f0.0f-1.0f};
??static?const?GLfloat?light1_position[]?=?{-3.0f2.0f-10.0f0.0f};?
??static?const?GLfloat?light1_ambient[]?=?{1.0f1.0f1.0f1.0f};
??static?const?GLfloat?light1_diffuse[]?=?{1.0f1.0f1.0f1.0f};
??static?const?GLfloat?light1_specular[]?=?{1.0f1.0f1.0f1.0f};
?glLightfv(GL_LIGHT0GL_POSITIONlight_position);
?glLightfv(GL_LIGHT0GL_AMBIENTlight_ambient);
?glLightfv(GL_LIGHT0GL_DIFFUSElight_diffuse);
?glLightfv(GL_LIGHT0GL_SPECULARlight_specular);
?glLightfv(GL_LIGHT1GL_POSITIONlight1_position);
?glLightfv(GL_LIGHT1GL_AMBIENTlight1_ambient);
?glLightfv(GL_LIGHT1GL_DIFFUSElight1_diffuse);
?glLightfv(GL_LIGHT1GL_SPECULARlight1_specular);
?
?glEnable(GL_LIGHT0);
?//glEnable(GL_LIGHT1);
?glEnable(GL_LIGHTING);
?//glEnable(GL_DEPTH_TEST);
}
void?Mouse(int?button?int?state?int?x?int?y)?//處理鼠標點擊??
{??
????if(state==GLUT_DOWN)?//第一次鼠標按下時記錄鼠標在窗口中的初始坐標??
????????oldmx=xoldmy=y;??
}??
void?onmousemove(int?xint?y)?//處理鼠標拖動??
{??
????//printf(“%d\n“du);??
????du+=x-oldmx;?//鼠標在窗口x軸方向上的增量加到視點繞y軸的角度上
????h?+=0.03f*(y-oldmy);?//鼠標在窗口y軸方向上的改變加到視點的y坐標上
???//?if(h>1.0f)?h=1.0f;?
???//?else?if(h<-1.0f)?
????oldmx=xoldmy=y;?//此時的鼠標坐標作為舊值,為下一次計算增量做準備??
}???
void?key(unsigned?char?keyint?xint?y)
{
switch(key)
{
???case?‘w‘:
??wy+=1;
???break;
???case?‘s‘:
??sy-=1;
???break;
???case?‘a‘:
??ay-=1;
???break;
???case?‘d‘:
??dy+=1;
???break;
???case?‘q‘:
??q+=1;
???break;
???case?‘e‘:
??e+=3;
???break;
???case?‘r‘:
??r+=2;
???break;
???case?‘z‘:
??zz-=1;
???break;
???case?‘x‘:
??xz+=1;
???break;
???case?‘f‘:
??wy=0;
???sy=0;
???ay=0;
???dy=0;
???q=0;
???e=0;
???r=0;
???zz=0;
????xz=0;
???break;
???default:
???break;
}
glutPostRedisplay();
}
void?display(void)
{
??glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
?????glTranslatef(0wy0);
?????glTranslatef(0sy0);
?????glTranslatef(ay00);
?????glTranslatef(dy00);
?glTranslatef(00zz);
?????glTranslatef(00xz);
?glRotatef(q100);
?glRotatef(e010);
?glRotatef(r001);
?mesh.draw(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????87552??2015-10-16?16:43??ply_loader\Debug\openglstudy_readply.exe
?????文件?????590720??2015-10-16?16:43??ply_loader\Debug\openglstudy_readply.ilk
?????文件????1289216??2015-10-16?16:43??ply_loader\Debug\openglstudy_readply.pdb
?????文件???73728000??2015-11-11?20:17??ply_loader\ipch\openglstudy_readply-6125de76\openglstudy_readply-17744fba.ipch
?????文件????3033195??1996-08-05?08:00??ply_loader\openglstudy_readply\bunny.ply
?????文件?????172791??2006-02-27?20:48??ply_loader\openglstudy_readply\cow.ply
?????文件???????6202??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\cl.command.1.tlog
?????文件?????142280??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\CL.read.1.tlog
?????文件???????7396??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\CL.write.1.tlog
?????文件???????3294??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\li
?????文件???????8002??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\li
?????文件???????2106??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\li
?????文件?????201612??2015-10-16?16:34??ply_loader\openglstudy_readply\Debug\main.obj
?????文件?????201624??2015-10-09?17:09??ply_loader\openglstudy_readply\Debug\main2.obj
?????文件???????1158??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\mt.command.1.tlog
?????文件???????1688??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\mt.read.1.tlog
?????文件????????758??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\mt.write.1.tlog
?????文件????????381??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\openglstudy_readply.exe.intermediate.manifest
?????文件?????????78??2015-11-11?11:35??ply_loader\openglstudy_readply\Debug\openglstudy_readply.lastbuildstate
?????文件????????984??2015-11-11?11:35??ply_loader\openglstudy_readply\Debug\openglstudy_readply.log
?????文件????????713??2014-09-04?12:38??ply_loader\openglstudy_readply\Debug\openglstudy_readply.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2014-08-17?14:20??ply_loader\openglstudy_readply\Debug\openglstudy_readply.write.1.tlog
?????文件?????265451??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\ply.obj
?????文件?????164885??2014-09-04?12:40??ply_loader\openglstudy_readply\Debug\PlyLoader.obj
?????文件????1395712??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\vc100.idb
?????文件?????733184??2015-10-16?16:43??ply_loader\openglstudy_readply\Debug\vc100.pdb
?????文件???????4470??2015-10-16?16:34??ply_loader\openglstudy_readply\main.cpp
?????文件?????932977??2005-08-09?00:03??ply_loader\openglstudy_readply\man.ply
?????文件???????3687??2015-10-09?17:10??ply_loader\openglstudy_readply\openglstudy_readply.vcxproj
?????文件???????1145??2015-10-09?17:10??ply_loader\openglstudy_readply\openglstudy_readply.vcxproj.filters
............此處省略15個文件信息
- 上一篇:高斯投影正反算MFC
- 下一篇:指針式儀表識別(MFC)
評論
共有 條評論