DOO-SABIN 细分曲面(编辑中)
2016-05-04 19:38
495 查看
之前实现了简单的细分曲线,即Chaikin细分算法,现在准备实现DooSabine细分曲面
我这里借助http://www.idav.ucdavis.edu/education/CAGDNotes/CAGDNotes/Doo-Sabin/Doo-Sabin.html
这篇文章中的例子,首先需要先绘制出实例中的这个图
两个小时过去了。。我终于画出这幅图来了。。给跪,其中一定要用到这里面的关于polygon模式的语句
其中GL_FRONT for front-facing polygons, GL_BACK for back-facing polygons, or GL_FRONT_AND_BACK for front- and back-facing polygons
mode有
我这里借助http://www.idav.ucdavis.edu/education/CAGDNotes/CAGDNotes/Doo-Sabin/Doo-Sabin.html
这篇文章中的例子,首先需要先绘制出实例中的这个图
两个小时过去了。。我终于画出这幅图来了。。给跪,其中一定要用到这里面的关于polygon模式的语句
void glPolygonMode(GLenum face, GLenum mode
);
其中GL_FRONT for front-facing polygons, GL_BACK for back-facing polygons, or GL_FRONT_AND_BACK for front- and back-facing polygons
mode有
GL_POINT,
GL_LINE, and
GL_FILL三种,其中初始状态是GL_FILL,正反两面都是
#include<GL/GLUT.H> #include <windows.h> #include <math.h> #include <gl/GL.h> static const GLfloat vertex_list[2][8][3] = { {{ -0.1f, 0.5f, 0.3f }, { -0.1f, 0, 0.3f }, { -0.6f, 0, 0.3f }, { -0.6f, -0.5f, 0.3f }, { 0.6f, -0.5f, 0.3f }, { 0.6f, 0, 0.3f }, { 0.1f, 0, 0.3f }, { 0.1f, 0.5f, 0.3f } }, { { -0.1f, 0.5f, -0.3f }, { -0.1f, 0, -0.3f }, { -0.6f, 0, -0.3f }, { -0.6f, -0.5f, -0.3f }, { 0.6f, -0.5f, -0.3f }, { 0.6f, 0, -0.3f }, { 0.1f, 0, -0.3f }, { 0.1f, 0.5f, -0.3f } } }; void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glRotatef(60, 1, 1, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(100.0f, 1.0f, 1.0f, 10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, -0.8, 1.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /*glRotatef(-60, -1, 1, 1);*/ glColor3f(0, 0, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); for (int j = 0; j < 8; ++j) // 每个面有八个顶点,循环八次 glVertex3fv(vertex_list[0][j]); glEnd(); glBegin(GL_POLYGON); for (int j = 0; j < 8; ++j) // 每个面有八个顶点,循环八次 glVertex3fv(vertex_list[1][j]); glEnd(); //绘制侧面的面 glColor3f(0, 0, 1); for (int i = 0; i < 8; i++) // 有八个面,循环八次 { if (i == 7) { glBegin(GL_QUADS); glVertex3fv(vertex_list[0][i]); glVertex3fv(vertex_list[0][0]); glVertex3fv(vertex_list[1][0]); glVertex3fv(vertex_list[1][i]); glEnd(); } else { glBegin(GL_QUADS); glVertex3fv(vertex_list[0][i]); glVertex3fv(vertex_list[0][i + 1]); glVertex3fv(vertex_list[1][i + 1]); glVertex3fv(vertex_list[1][i]); glEnd(); } } glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("opengl1"); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0; }学到这里突然要发现需要学习好多数据结构的东西。。我觉得有必要专门写一篇关于数据结构和图形表示的博客。。那这一块的东西还是暂时放一放。马上搞定了回来补
#include<GL/GLUT.H> #include <windows.h> #include <math.h> #include <gl/GL.h> static const GLfloat vertex_list[2][8][3] = { {{ -0.1f, 0.5f, 0.3f }, { -0.1f, 0, 0.3f }, { -0.6f, 0, 0.3f }, { -0.6f, -0.5f, 0.3f }, { 0.6f, -0.5f, 0.3f }, { 0.6f, 0, 0.3f }, { 0.1f, 0, 0.3f }, { 0.1f, 0.5f, 0.3f } }, { { -0.1f, 0.5f, -0.3f }, { -0.1f, 0, -0.3f }, { -0.6f, 0, -0.3f }, { -0.6f, -0.5f, -0.3f }, { 0.6f, -0.5f, -0.3f }, { 0.6f, 0, -0.3f }, { 0.1f, 0, -0.3f }, { 0.1f, 0.5f, -0.3f } } }; void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glRotatef(60, 1, 1, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(100.0f, 1.0f, 1.0f, 10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, -0.8, 1.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /*glRotatef(-60, -1, 1, 1);*/ glColor3f(0, 0, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); for (int j = 0; j < 8; ++j) // 每个面有八个顶点,循环八次 glVertex3fv(vertex_list[0][j]); glEnd(); glBegin(GL_POLYGON); for (int j = 0; j < 8; ++j) // 每个面有八个顶点,循环八次 glVertex3fv(vertex_list[1][j]); glEnd(); //绘制侧面的面 glColor3f(0, 0, 1); for (int i = 0; i < 8; i++) // 有八个面,循环八次 { if (i == 7) { glBegin(GL_QUADS); glVertex3fv(vertex_list[0][i]); glVertex3fv(vertex_list[0][0]); glVertex3fv(vertex_list[1][0]); glVertex3fv(vertex_list[1][i]); glEnd(); } else { glBegin(GL_QUADS); glVertex3fv(vertex_list[0][i]); glVertex3fv(vertex_list[0][i + 1]); glVertex3fv(vertex_list[1][i + 1]); glVertex3fv(vertex_list[1][i]); glEnd(); } } glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("opengl1"); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0; }这篇博文没有写完。。突然发现要去补数据结构的课。。,好了不多说了,去补课了
相关文章推荐
- 解决Vista系统OpenGL驱动问题的方法整理
- Delphi下OpenGL2d绘图之画四边形的方法
- Delphi下OpenGL2d绘图之画点的方法
- Delphi下OpenGL2d绘图之初始化流程详解
- Delphi使用OpenGL2d绘图之画图片Bmp的方法
- 通过OpenGL ES混合模式缩放视频缓冲区来适应显示尺寸
- VC运用OPENGL加载BMP纹理图的实现方法汇总
- java实现OpenGL ES纹理映射的方法
- java基于OpenGL ES实现渲染实例
- OpenGL坐标系介绍
- 【翻译】安卓opengl ES教程之四——添加颜色
- linux下opengl的安装(with qt)
- OpenGL超级宝典笔记——显示列表
- OpenGL超级宝典笔记——顶点数组
- OpenGL生成轮廓
- OpenGL超级宝典笔记——性能比较
- OpenGL超级宝典笔记——顶点缓冲区对象
- OpenGL超级宝典笔记——选择
- OpenGL超级宝典笔记——反馈
- OpenGL超级宝典笔记——遮挡查询