查看: 1994|回复: 8

clipPlane的相关问题

[复制链接]

该用户从未签到

发表于 2013-4-7 10:24:50 | 显示全部楼层 |阅读模式
设置了两个clipPlane,如何让二者以任意角度相交进行剖面?

该用户从未签到

发表于 2013-4-7 13:31:45 | 显示全部楼层
参看osgclip例子

该用户从未签到

 楼主| 发表于 2013-4-7 13:40:44 | 显示全部楼层
    osg::ref_ptr<osg::ClipPlane>  m_clipPlane0 = new osg::ClipPlane;
    osg::ref_ptr<osg::ClipPlane>  m_clipPlane1 = new osg::ClipPlane;
    m_clipPlane0->setClipPlane(0,0,-1,0);
    m_clipPlane1->setClipPlane(0,1,0,0);
    clipnode->addClipPlane(m_clipPlane0);
    clipnode->addClipPlane(m_clipPlane1);

只显示m_clipPlane1的切割结果

该用户从未签到

发表于 2013-4-7 13:53:16 | 显示全部楼层
Geometry is always clipped against the boundaries of a six-plane frustum in x, y, and z. glClipPlane allows the specification of additional planes, not necessarily perpendicular to the x, y, or Z axis, against which all geometry is clipped. To determine the maximum number of additional clipping planes, call glGetIntegerv with argument GL_MAX_CLIP_PLANES. All implementations support at least six such clipping planes. Because the resulting clipping region is the intersection of the defined half-spaces, it is always convex.

glClipPlane specifies a half-space using a four-component plane equation. When glClipPlane is called, equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates. Subsequent changes to the modelview matrix have no effect on the stored plane-equation components. If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero, the vertex is \f2in\f1 with respect to that clipping plane. Otherwise, it is out.

To enable and disable clipping planes, call glEnable and glDisable with the argument GL_CLIP_PLANEi, where i is the plane number.

All clipping planes are initially defined as (0, 0, 0, 0) in eye coordinates and are disabled.

该用户从未签到

 楼主| 发表于 2013-4-7 14:00:01 | 显示全部楼层
在OpenGL中使用glEnable就能唤醒,但在OSG中怎么设置,才能显示多个面共同截取的效果?

该用户从未签到

发表于 2013-4-7 14:04:49 | 显示全部楼层
ClipPlane 的序号,您没有设置它的序号,默认都是0那么在state中怎么分辨?

该用户从未签到

 楼主| 发表于 2013-4-7 14:27:10 | 显示全部楼层
您说的对,现在可以啦!另外,怎样实现沿着Z轴旋转ClipPlane呢?

该用户从未签到

 楼主| 发表于 2013-4-7 17:41:09 | 显示全部楼层
        std::vector<osg::ClipPlane*>    m_clipPlane;
        osg::ref_ptr<osg::ClipPlane>  m_clipPlane0 = new osg::ClipPlane;

        for ( int i = 0 ; i < 2; i++)
        {
                switch(i)
                {
                case 0:
                        m_clipPlane0->setClipPlane(1,0,0,0);
                        m_clipPlane0->setClipPlaneNum(0);
                        break;

                default:
                        m_clipPlane0->setClipPlane(0,1,0,0);
                        m_clipPlane0->setClipPlaneNum(1);
                        break;
                }
                m_clipPlane.push_back(m_clipPlane0);
        }
调试时,循环开始时是对的,但最后一次循环时,会再执行一次m_clipPlane0->setClipPlaneNum(0);语句,导致两个截面的序号都为1!怎么回事?

该用户从未签到

 楼主| 发表于 2013-4-8 16:25:20 | 显示全部楼层
wulingxia 发表于 2013-4-7 17:41
std::vector    m_clipPlane;
        osg::ref_ptr  m_clipPlane0 = new osg::ClipPlane;

是智能指针的问题!嘿嘿
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表