OpenGL_读取PLY文件+光照
OpenGL读取PLY实例,实现鼠标和键盘的模型操控,另外加有光源旋转动画
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1988159 1996-08-05 06:47 OpenGL_读取PLY文件+光照un000.ply
文件 3033195 1996-08-05 08:00 OpenGL_读取PLY文件+光照un_zipper.ply
文件 14456495 2013-09-08 14:37 OpenGL_读取PLY文件+光照datahappy_recon.tar.gz
文件 156672 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugHelloGlut.bsc
文件 262208 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.exe
文件 420248 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.ilk
文件 38913 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.obj
文件 3789656 2015-11-30 19:57 OpenGL_读取PLY文件+光照DebugHelloGlut.pch
文件 713728 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.pdb
文件 0 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugHelloGlut.sbr
文件 10032 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugPlyInput.obj
文件 0 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugPlyInput.sbr
文件 279552 2015-12-21 14:26 OpenGL_读取PLY文件+光照Debugvc60.idb
文件 86016 2015-12-21 14:26 OpenGL_读取PLY文件+光照Debugvc60.pdb
文件 33831477 1996-08-05 08:15 OpenGL_读取PLY文件+光照dragon_vrip.ply
文件 1749 2013-11-06 13:20 OpenGL_读取PLY文件+光照Geometry.h
文件 62175 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfgl.h
文件 7483 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfglu.h
文件 10473 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfglut.h
文件 5287 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLglsmap.h
文件 27670 2000-12-13 00:22 OpenGL_读取PLY文件+光照GLglut.h
文件 4190 1999-02-16 10:55 OpenGL_读取PLY文件+光照GLglutf90.h
文件 9119 2000-12-12 23:07 OpenGL_读取PLY文件+光照GL ube.h
文件 221184 2013-09-23 16:43 OpenGL_读取PLY文件+光照glut32.dll
文件 28728 2013-09-23 16:43 OpenGL_读取PLY文件+光照glut32.lib
文件 3145784 2009-08-26 17:18 OpenGL_读取PLY文件+光照GoogleEarth.bmp
文件 42619420 1996-08-05 08:06 OpenGL_读取PLY文件+光照happy_vrip.ply
文件 8222 2015-12-01 21:12 OpenGL_读取PLY文件+光照HelloGlut.cpp
文件 4544 2013-11-28 23:22 OpenGL_读取PLY文件+光照HelloGlut.dsp
文件 541 2013-09-23 16:43 OpenGL_读取PLY文件+光照HelloGlut.dsw
............此处省略12个文件信息
#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);
//计算法向量的均值
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 < nFaces; 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 < nvertices; 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);//看到三角形
//启动光照明
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);//light0就是第0个光源,一共有8个光源
//glEnable(GL_LIGHT1);
//set the light
GLfloat ambientProperties[] = {0.5f 0.5f 0.5f 1.0f}; //RGB+齐次坐标1.0RGB在0.0-1.0之间,,,环境光
GLfloat diffuseProperties[] = {1.0f 1.0f 1.0f 1.0f}; //漫反射光
GLfloat specularProperties[] = {1.0f 1.0f 1.0f 1.0f}; //镜面反射光
//指定材质
GLfloat ambi[]={0.191250 0.073500 0.022500 1.000000};
GLfloat diff[]={0.703800 0.270480 0.082800
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1988159 1996-08-05 06:47 OpenGL_读取PLY文件+光照un000.ply
文件 3033195 1996-08-05 08:00 OpenGL_读取PLY文件+光照un_zipper.ply
文件 14456495 2013-09-08 14:37 OpenGL_读取PLY文件+光照datahappy_recon.tar.gz
文件 156672 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugHelloGlut.bsc
文件 262208 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.exe
文件 420248 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.ilk
文件 38913 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.obj
文件 3789656 2015-11-30 19:57 OpenGL_读取PLY文件+光照DebugHelloGlut.pch
文件 713728 2015-12-21 14:26 OpenGL_读取PLY文件+光照DebugHelloGlut.pdb
文件 0 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugHelloGlut.sbr
文件 10032 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugPlyInput.obj
文件 0 2013-11-06 19:30 OpenGL_读取PLY文件+光照DebugPlyInput.sbr
文件 279552 2015-12-21 14:26 OpenGL_读取PLY文件+光照Debugvc60.idb
文件 86016 2015-12-21 14:26 OpenGL_读取PLY文件+光照Debugvc60.pdb
文件 33831477 1996-08-05 08:15 OpenGL_读取PLY文件+光照dragon_vrip.ply
文件 1749 2013-11-06 13:20 OpenGL_读取PLY文件+光照Geometry.h
文件 62175 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfgl.h
文件 7483 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfglu.h
文件 10473 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLfglut.h
文件 5287 1999-02-08 13:11 OpenGL_读取PLY文件+光照GLglsmap.h
文件 27670 2000-12-13 00:22 OpenGL_读取PLY文件+光照GLglut.h
文件 4190 1999-02-16 10:55 OpenGL_读取PLY文件+光照GLglutf90.h
文件 9119 2000-12-12 23:07 OpenGL_读取PLY文件+光照GL ube.h
文件 221184 2013-09-23 16:43 OpenGL_读取PLY文件+光照glut32.dll
文件 28728 2013-09-23 16:43 OpenGL_读取PLY文件+光照glut32.lib
文件 3145784 2009-08-26 17:18 OpenGL_读取PLY文件+光照GoogleEarth.bmp
文件 42619420 1996-08-05 08:06 OpenGL_读取PLY文件+光照happy_vrip.ply
文件 8222 2015-12-01 21:12 OpenGL_读取PLY文件+光照HelloGlut.cpp
文件 4544 2013-11-28 23:22 OpenGL_读取PLY文件+光照HelloGlut.dsp
文件 541 2013-09-23 16:43 OpenGL_读取PLY文件+光照HelloGlut.dsw
............此处省略12个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)