http://www.devdiv.com/home.php?mod=space&uid=23234&do=blog&id=3310
用openGL中的glClipPlanef方法达到效果
一个相关的链接
http://paulbourke.net/geometry/planeeq/
写visit方法
-(void)visit
{
[selfbeforeDraw];
[supervisit];
[selfafterDraw];
}
-(void)beforeDraw
{
float top = 210.0f;;
float bottom = -130.0f;
float left = -180.0f;
float right = 300.0f;
//不必修改下面的其他值,上述的常量可以在平面中抠出矩形块,bottom 和 left要为负数
//至于具体的原理,可以去查看openGL的书籍,上面有详细的介绍,这里,直接用就行
GLfloat planeTop[] = {0.0f, -1.0f, 0.0f,top};
//1.0,y > 100
GLfloat planeBottom[] = {0.0f, 1.0f, 0.0f,bottom};
//
GLfloat planeLeft[] = {1.0f, 0.0f, 0.0f, left};
GLfloat planeRight[] = {-1.0f, 0.0f, 0.0f,right};
glClipPlanef(GL_CLIP_PLANE0, planeTop);
glClipPlanef(GL_CLIP_PLANE1, planeBottom);
glClipPlanef(GL_CLIP_PLANE2, planeLeft);
glClipPlanef(GL_CLIP_PLANE3, planeRight);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
}
-(void)afterDraw
{
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}