# opengl 裁剪平面

1. void glClipPlane(GLenum plane, const GLdouble *equation);

定义一个裁剪平面。equation参数指向平面方程Ax + By + Cz + D = 0的4个系数。equation=（0，-1，0,0），前三个参数（0，-1,0）可以理解为法线向下，只有向下的，即Y<0的才能显示，最后一 个参数0表示从z=0平面开始。这样就是裁剪掉上半平面。相应的equation=（0,1,0,0）表示裁剪掉下半平面，equation= （1,0,0,0）表示裁剪掉左半平面，equation=（-1,0,0,0）表示裁剪掉右半平面，equation=（0,0,-1,0）表示裁剪掉 前半平面，equation=（0,0,1,0）表示裁剪掉后半平面

 图3-23 裁剪后的线框球体

void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
}
void display(void)
{
GLdouble eqn [4]={0.0,1.0,0.0,0.0};
GLdouble eqn2 [4] ={1.0,0.0,0.0,0.0};
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);

glClipPlane(GL_CLIP_PLANE0,eqn);
glEnable(GL_CLIP_PLANE0);

glClipPlane(GL_CLIP_PLANE1,eqn2);
glEnable(GL_CLIP_PLANE1);
glRotatef(90.0,1.0,0.0,0.0);

glutWireSphere(1.0,20,16);
glPopMatrix();
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv [0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
} 

11-25

06-01 7125
10-28
01-20 5830
11-06 336
09-16 1110
07-08 3416
11-28 647
04-15 4940
07-13 5516
08-21 1037
01-08 1687
02-18 4045
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客