opengl 裁剪平面

原帖地址:http://blog.sina.com.cn/s/blog_5ff6097b0100xqvr.html

  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-5是经过两个裁剪平面裁剪的线框球体,裁去了3/4体积,如图3-23所示。


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

示例程序3-5 经过两个裁剪平面裁剪的线框球体:clip.c

void init(void)  
{  
glClearColor(0.0,0.0,0.0,0.0);  
glShadeModel(GL_FLAT);  
}  
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);  
glLoadIdentity();  
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;  
} 

 

转载于:https://www.cnblogs.com/dragon2012/p/3776325.html

相关资源:opengles裁剪平面
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页