LineSegmentIntersector::Intersection结构体各成员含义

目录

1. 概述

 2. 交点结构体说明


1. 概述

      osgUtil::Intersector有几个子类,如下:

每个子类表示不同的求交器。所谓求交器就是判定和物体相交的类,通过这些类可以很方便的得出交点、实现拾取功能等。LineSegmentIntersector类是osgUtil::Intersector其中的一个子类,其表示线段求交器,即通过线段和三维场景中的某个物体相交,该类一般和osgUtil::IntersectionVisitor即求交访问器类一起使用,从而得出交点、实现拾取功能等。关于osgUtil::LineSegmentIntersector类的具体应用及源码分析,请参考如下博文:

 2. 交点结构体说明

       线段和几何体的交点结构体如下:

       struct OSGUTIL_EXPORT Intersection
        {
            Intersection():
                ratio(-1.0),
                primitiveIndex(0) {}

            bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }

            typedef std::vector<unsigned int>   IndexList;
            typedef std::vector<double>         RatioList;

            double                          ratio;
            osg::NodePath                   nodePath;
            osg::ref_ptr<osg::Drawable>     drawable;
            osg::ref_ptr<osg::RefMatrix>    matrix;
            osg::Vec3d                      localIntersectionPoint;
            osg::Vec3                       localIntersectionNormal;
            IndexList                       indexList;
            RatioList                       ratioList;
            unsigned int                    primitiveIndex;

            const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
            osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }

            const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
            osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }

            /** Convenience function for mapping the intersection point to any textures assigned to the objects intersected.
             *  Returns the Texture pointer and texture coords of object hit when a texture is available on the object, returns NULL otherwise.*/
            osg::Texture* getTextureLookUp(osg::Vec3& tc) const;

        };

ratio:表示线段起始点到交点的线段长度占据整个线段长度的比例。如下为线段SE,L为SE和指定几何体的交点:

             

则:

ration = SL / SE

nodePath:从场景总根节点到和直线相交的几何体的节点路径。关于什么是节点路径 ,请参考:

getParentalNodePaths、osg::NodePathList、osg::NodePath详解。 

drawable:就是和线段相交的可绘制对象,也即几何对象。如:线段和长方体相交,则drawable就是osg::ShapeDrawable对象,而不是osg::Box对象。

primitiveIndex:就是和线段相交的可绘制对象,也即几何对象图元索引。如:线段和长方体相交,则primitiveIndex就表示长方体的第几个三角面,注意:不是矩形面,而是三角面,OPenGL绘制矩形并不是直接绘制一个矩形,而是绘制两个三角面,由这两个三角面再拼成矩形,这样效率会高很多,因为显卡硬件对三角形支持很好,而对四边形支持不是那么高效率。

localIntersectionPoint:基于和线段相交的可绘制对象所在局部坐标系下的交点坐标。

localIntersectionNormal:基于和线段相交的可绘制对象所在局部坐标系下的交点的法线坐标。

matrix:变换矩阵。该矩阵乘以localIntersectionPoint,则表示基于世界坐标下的交点坐标。

indexList:存放和线段相交的可绘制对象的图元的顶点索引的容器。如:线段和长方体相交,则图元就表示组成长方体某个矩形面的三角面的三个顶点存放在indexList中。

ratioList:存放三角面三条边占的权重,也可以理解u,v是交点的纹理坐标值。三条边的权重分别为1.0-u-v、u、v,关于1.0-u-v、u、v的含义参见:射线和三角形的相交检测(ray triangle intersection test)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值