資源簡(jiǎn)介
OpenGL讀取PLY實(shí)例,實(shí)現(xiàn)鼠標(biāo)和鍵盤的模型操控,另外加有光源旋轉(zhuǎn)動(dòng)畫
代碼片段和文件信息
#define?GLUT_DISABLE_ATEXIT_HACK
#define?GL_LIGHT_MODEL_COLOR_CONTROL?0x81F8
#define?GL_SEPARATE_SPECULAR_COLOR?0x81FA
#include?“gl/glut.h“
#include?“PlyInput.h“
#include?“string.h“
#include?
#include?
#include?
const?int?width=1000;
const?int?height=700;
GLfloat?xRotation?=?0.0f?yRotation?=?0.0f;
const?GLfloat?rotSpeed?=?50.0f;//速度
bool?bLButtonDown?=?false;
GLint?lastLx?lastLy;
const?double?half_width?=?2.0;
FPoint3?*vertices?=?NULL;
FPoint3?*normals?=?NULL;
int?nvertices?=?0;
int*?indices?=?NULL;
int?nindices?=?0;
GLfloat?SclFac?=?1.0f?lastSclFac?=?1.0f;
GLfloat?xTransl?=?0.0f?yTransl?=?0.0f;
int?lastPxlastPy;
bool?bMButtonDownbRButtonDown;
GLfloat?LightPos[]?=?{0.5f0.2f0.0f1.0f};//光源位置
GLfloat?lightSpin?=?0.0f;
GLfloat?lightSpeed?=?1.0f;
GLuint?iTexture=0;
GLfloat?lightAmbient[]?=?{0.5f?0.5f?0.5f?0.1f};
GLfloat?lightDiffuse[]?=?{1.0f?1.0f?1.0f?1.0f};
GLfloat?lightSpecular[]?=?{1.0f?1.0f?1.0f?1.0f};
GLfloat?lightPosition[]?=?{1.0f?1.0f?2.0f?1.0f};
GLfloat?matAmbient[]?=?{0.5f?0.5f?0.5f?0.1f};
GLfloat?matDiffuse[]?=?{1.0f?1.0f?1.0f?1.0f};
GLfloat?matSpecular[]?=?{1.0f?1.0f?1.0f?1.0f};
GLfloat?matPosition[]?=?{1.0f?1.0f?2.0f?1.0f};
GLUquadricObj*?q;
FPoint3?CalcNormal(const?FPoint3?&v0const?FPoint3?&v1const?FPoint3?&v2){
FPoint3?p1p2p3;
p1=v1-v0;
p2=v2-v0;
p3?=?p1.cross(p2);
return?p3;
}
void?init(){
//讀取文件
LoadSimplePlyFile(“happy_vrip.ply“verticesnverticesindicesnindices);
//計(jì)算法向量的均值
int?*counts?=?new?int[nvertices];
memset(counts?0??sizeof(int)?*?nvertices);
normals?=?new?FPoint3[nindices];
memset(normals0sizeof(FPoint3)?*?nvertices);
int?nFaces;
nFaces?=?nindices?/?3;
int?offset?=?0;
for?(int?i?=?0;?i? int?ind0?=?indices[offset++];
const?FPoint3?&v0?=?vertices[ind0];
int?ind1?=?indices[offset++];
const?FPoint3?&v1?=?vertices[ind1];
int?ind2?=?indices[offset++];
const?FPoint3?&v2?=?vertices[ind2];
FPoint3?norm?=?CalcNormal(v0?v1?v2);
normals[ind0]?+=?norm;
counts[ind0]++;
normals[ind1]?+=?norm;
counts[ind1]++;
normals[ind2]?+=?norm;
counts[ind2]++;
}
for?(?i?=?0;?i? FPoint3?&normal?=?normals[i];
normal?/=?counts[i];
normal.normalize();
}
delete[]?counts;
// glPolygonMode(GL_FRONT_AND_BACKGL_LINES);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//glPolygonMode(GL_FRONT_AND_BACKGL_LINE);//看到三角形
//啟動(dòng)光照明
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);//light0就是第0個(gè)光源,一共有8個(gè)光源
//glEnable(GL_LIGHT1);
//set?the?light
GLfloat?ambientProperties[]??=?{0.5f?0.5f?0.5f?1.0f};?//RGB+齊次坐標(biāo)1.0RGB在0.0-1.0之間,,,環(huán)境光
GLfloat?diffuseProperties[]??=?{1.0f?1.0f?1.0f?1.0f};?//漫反射光
GLfloat?specularProperties[]?=?{1.0f?1.0f?1.0f?1.0f};?//鏡面反射光
//指定材質(zhì)
GLfloat?ambi[]={0.191250?0.073500?0.022500?1.000000};
GLfloat?diff[]={0.703800?0.270480?0.082800?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????1988159??1996-08-05?06:47??OpenGL_讀取PLY文件+光照\(chéng)bun000.ply
?????文件????3033195??1996-08-05?08:00??OpenGL_讀取PLY文件+光照\(chéng)bun_zipper.ply
?????文件???14456495??2013-09-08?14:37??OpenGL_讀取PLY文件+光照\(chéng)data\happy_recon.tar.gz
?????文件?????156672??2013-11-06?19:30??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.bsc
?????文件?????262208??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.exe
?????文件?????420248??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.ilk
?????文件??????38913??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.obj
?????文件????3789656??2015-11-30?19:57??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.pch
?????文件?????713728??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.pdb
?????文件??????????0??2013-11-06?19:30??OpenGL_讀取PLY文件+光照\(chéng)Debug\HelloGlut.sbr
?????文件??????10032??2013-11-06?19:30??OpenGL_讀取PLY文件+光照\(chéng)Debug\PlyInput.obj
?????文件??????????0??2013-11-06?19:30??OpenGL_讀取PLY文件+光照\(chéng)Debug\PlyInput.sbr
?????文件?????279552??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\vc60.idb
?????文件??????86016??2015-12-21?14:26??OpenGL_讀取PLY文件+光照\(chéng)Debug\vc60.pdb
?????文件???33831477??1996-08-05?08:15??OpenGL_讀取PLY文件+光照\(chéng)dragon_vrip.ply
?????文件???????1749??2013-11-06?13:20??OpenGL_讀取PLY文件+光照\(chéng)Geometry.h
?????文件??????62175??1999-02-08?13:11??OpenGL_讀取PLY文件+光照\(chéng)GL\fgl.h
?????文件???????7483??1999-02-08?13:11??OpenGL_讀取PLY文件+光照\(chéng)GL\fglu.h
?????文件??????10473??1999-02-08?13:11??OpenGL_讀取PLY文件+光照\(chéng)GL\fglut.h
?????文件???????5287??1999-02-08?13:11??OpenGL_讀取PLY文件+光照\(chéng)GL\glsmap.h
?????文件??????27670??2000-12-13?00:22??OpenGL_讀取PLY文件+光照\(chéng)GL\glut.h
?????文件???????4190??1999-02-16?10:55??OpenGL_讀取PLY文件+光照\(chéng)GL\glutf90.h
?????文件???????9119??2000-12-12?23:07??OpenGL_讀取PLY文件+光照\(chéng)GL\tube.h
?????文件?????221184??2013-09-23?16:43??OpenGL_讀取PLY文件+光照\(chéng)glut32.dll
?????文件??????28728??2013-09-23?16:43??OpenGL_讀取PLY文件+光照\(chéng)glut32.lib
?????文件????3145784??2009-08-26?17:18??OpenGL_讀取PLY文件+光照\(chéng)GoogleEarth.bmp
?????文件???42619420??1996-08-05?08:06??OpenGL_讀取PLY文件+光照\(chéng)happy_vrip.ply
?????文件???????8222??2015-12-01?21:12??OpenGL_讀取PLY文件+光照\(chéng)HelloGlut.cpp
?????文件???????4544??2013-11-28?23:22??OpenGL_讀取PLY文件+光照\(chéng)HelloGlut.dsp
?????文件????????541??2013-09-23?16:43??OpenGL_讀取PLY文件+光照\(chéng)HelloGlut.dsw
............此處省略12個(gè)文件信息
- 上一篇:鄒謀炎著,反卷積和信號(hào)復(fù)原
- 下一篇:Fiji使用手冊(cè)
評(píng)論
共有 條評(píng)論