双三次bezier曲面片代码
时间: 2023-06-27 21:02:18 浏览: 108
以下是双三次Bezier曲面片的示例代码,其中使用了OpenGL和GLUT库来绘制曲面。
```c++
#include <GL/glut.h>
#include <iostream>
const int width = 800;
const int height = 800;
GLdouble control_points[4][4][3] = {
{{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}},
{{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}},
{{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}},
{{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}};
GLUnurbsObj *nurbsObject;
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
gluBeginSurface(nurbsObject);
gluNurbsSurface(nurbsObject, 8, knots, 8, knots, 4 * 3, 3, &control_points[0][0][0], 4, 4, GL_MAP2_VERTEX_3);
gluEndSurface(nurbsObject);
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-5.0, 5.0, -5.0 * (GLdouble)h / (GLdouble)w, 5.0 * (GLdouble)h / (GLdouble)w, -5.0, 5.0);
else
glOrtho(-5.0 * (GLdouble)w / (GLdouble)h, 5.0 * (GLdouble)w / (GLdouble)h, -5.0, 5.0, -5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Bezier Surface");
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
nurbsObject = gluNewNurbsRenderer();
gluNurbsProperty(nurbsObject, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(nurbsObject, GLU_DISPLAY_MODE, GLU_FILL);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
```
阅读全文