zoukankan      html  css  js  c++  java
  • osg求交,模型矩阵

    Intersector* LineSegmentIntersector::clone(osgUtil::IntersectionVisitor& iv)
    {
        if (_coordinateFrame==MODEL && iv.getModelMatrix()==0)
        {
            osg::ref_ptr<LineSegmentIntersector> lsi = new LineSegmentIntersector(_start, _end);
            lsi->_parent = this;
            return lsi.release();
        }

        // compute the matrix that takes this Intersector from its CoordinateFrame into the local MODEL coordinate frame
        // that geometry in the scene graph will always be in.//
        osg::Matrix matrix;
        switch (_coordinateFrame)
        {
            case(WINDOW):
                if (iv.getWindowMatrix()) matrix.preMult( *iv.getWindowMatrix() );
                if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
                if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
                if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
                break;
            case(PROJECTION):
                if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
                if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
                if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
                break;
            case(VIEW):
                if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
                if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
                break;
            case(MODEL):
                if (iv.getModelMatrix()) matrix = *iv.getModelMatrix();
                break;
        }

        osg::Matrix inverse;
        inverse.invert(matrix);

        osg::ref_ptr<LineSegmentIntersector> lsi = new LineSegmentIntersector(_start * inverse, _end * inverse);//把相交点转到模型矩阵

        //而模型本身不需要转换,其坐标就是在模型坐标系中的坐标,求得的交点也是在局部坐标系中的坐标
        lsi->_parent = this;
        return lsi.release();

      switch(mode)
            {
                case(GL_TRIANGLES):
                {
                    const Vec3* vlast = &_vertexArrayPtr[first+count];                                   ///一个geometry下面挂几个drawable,每个drawable下有几个

                                                                                                                                //primitive,每一个primitive就在此循环一次求交
                    for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
                        this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
                    break;
                }
                case(GL_TRIANGLE_STRIP):
                {
                    const Vec3* vptr = &_vertexArrayPtr[first];
                    for(GLsizei i=2;i<count;++i,++vptr)
                    {
                        if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),_treatVertexDataAsTemporary);
                        else       this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
                    }
                    break;
                }
                case(GL_QUADS):
                {
                    const Vec3* vptr = &_vertexArrayPtr[first];
                    for(GLsizei i=3;i<count;i+=4,vptr+=4)
                    {
                        this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
                        this->operator()(*(vptr),*(vptr+2),*(vptr+3),_treatVertexDataAsTemporary);
                    }
                    break;
                }
                case(GL_QUAD_STRIP):
                {
                    const Vec3* vptr = &_vertexArrayPtr[first];
                    for(GLsizei i=3;i<count;i+=2,vptr+=2)
                    {
                        this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
                        this->operator()(*(vptr+1),*(vptr+3),*(vptr+2),_treatVertexDataAsTemporary);
                    }
                    break;
                }
                case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN
                case(GL_TRIANGLE_FAN):
                {
                    const Vec3* vfirst = &_vertexArrayPtr[first];
                    const Vec3* vptr = vfirst+1;
                    for(GLsizei i=2;i<count;++i,++vptr)
                    {
                        this->operator()(*(vfirst),*(vptr),*(vptr+1),_treatVertexDataAsTemporary);
                    }
                    break;
                }
                case(GL_POINTS):
                case(GL_LINES):
                case(GL_LINE_STRIP):
                case(GL_LINE_LOOP):
                default:
                    // can't be converted into to triangles.
                    break;
            }
        }
    }

  • 相关阅读:
    FCC---Learn How Bezier Curves Work---定义坐标轴点的值,影响斜率,改变速度。具体调试换值既可以体会
    FCC---Change Animation Timing with Keywords--两个小球从A都B,相同循环时间 duration, 不同的速度 speed
    FCC---Animate Multiple Elements at Variable Rates---还可以改循环时间,达到不同律动频率的效果
    FCC---Animate Elements at Variable Rates----一闪一闪亮晶晶,不同的闪动节奏
    FCC---Make a CSS Heartbeat using an Infinite Animation Count----超级好看的心跳,粉色的
    FCC---Animate Elements Continually Using an Infinite Animation Count---设置animation-iteration-count的次数为无限,让小球一直跳动
    FCC---Create Visual Direction by Fading an Element from Left to Right---一个带好看背景色的圆形图案,从左到右移动,透明度opacity渐变为0.1,背景色渐渐消失的效果
    FCC---Create Movement Using CSS Animation---设计一个盒子上下左右移动,结合animation, @keyframe, position (上下左右的offset)
    FCC---Use CSS Animation to Change the Hover State of a Button---鼠标移过,背景色变色,用0.5s的动画制作
    Python入门必学知识,30万年薪Python工程师带你学
  • 原文地址:https://www.cnblogs.com/lizhengjin/p/1836356.html
Copyright © 2011-2022 走看看