当前位置: 首页>>代码示例>>C++>>正文


C++ Vec3::length方法代码示例

本文整理汇总了C++中osg::Vec3::length方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3::length方法的具体用法?C++ Vec3::length怎么用?C++ Vec3::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::Vec3的用法示例。


在下文中一共展示了Vec3::length方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getAngleBetween

    double Frustum::getAngleBetween(const osg::Vec3 &a, const osg::Vec3 &b) {

        float dot = a * b;
        float mag = a.length() * b.length();
        
        double angle = acos(dot/mag);
        
		if (osg::isNaN(angle)) 
            return 0;
        else
            return angle;
    }
开发者ID:cefix,项目名称:cefix,代码行数:12,代码来源:Frustum.cpp

示例2: operator

float ConeSector::operator() (const osg::Vec3& eyeLocal) const
{
    float dotproduct = eyeLocal*_axis;
    float length = eyeLocal.length();
    if (dotproduct>_cosAngle*length) return 1.0f; // fully in sector
    if (dotproduct<_cosAngleFade*length) return 0.0f; // out of sector
    return (dotproduct-_cosAngleFade*length)/((_cosAngle-_cosAngleFade)*length);
}
开发者ID:BlitzMaxModules,项目名称:osg.mod,代码行数:8,代码来源:Sector.cpp

示例3:

osg::Vec3 ShadowTechnique::computeOrthogonalVector(const osg::Vec3& direction) const
{
    float length = direction.length();
    osg::Vec3 orthogonalVector = direction ^ osg::Vec3(0.0f, 1.0f, 0.0f);
    if (orthogonalVector.normalize()<length*0.5f)
    {
        orthogonalVector = direction ^ osg::Vec3(0.0f, 0.0f, 1.0f);
        orthogonalVector.normalize();
    }
    return orthogonalVector;
}
开发者ID:LaurensVoerman,项目名称:OpenSceneGraph,代码行数:11,代码来源:ShadowTechnique.cpp

示例4: set

        void set(const osg::Vec3d& start, osg::Vec3d& end, float ratio=FLT_MAX)
        {
            _hit=false;
            _index = 0;
            _ratio = ratio;

            _s = start;
            _d = end - start;
            _length = _d.length();
            _d /= _length;
        }
开发者ID:BlitzMaxModules,项目名称:osg.mod,代码行数:11,代码来源:LineSegmentIntersector.cpp

示例5: computePosition

void GliderManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
{
    osg::Vec3 f(lv);
    f.normalize();
    osg::Vec3 s(f^up);
    s.normalize();
    osg::Vec3 u(s^f);
    u.normalize();
    
    osg::Matrixd rotation_matrix(s[0],     u[0],     -f[0],     0.0f,
                                s[1],     u[1],     -f[1],     0.0f,
                                s[2],     u[2],     -f[2],     0.0f,
                                0.0f,     0.0f,     0.0f,      1.0f);
                   
    _eye = eye;
    _distance = lv.length();
    _rotation = rotation_matrix.getRotate().inverse();
}
开发者ID:yueying,项目名称:osg,代码行数:18,代码来源:GliderManipulator.cpp

示例6: if

    osg::ref_ptr<osg::Geode> createRefGeometry( osg::Vec3 p, double len )
    {
        osg::ref_ptr<osg::Geode> geode = new osg::Geode;  

        if ( _drawingFlag==1 )
        {
            osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
            osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;

            // Joint
            vertices->push_back( osg::Vec3(-len, 0.0, 0.0) );
            vertices->push_back( osg::Vec3( len, 0.0, 0.0) );
            vertices->push_back( osg::Vec3( 0.0,-len, 0.0) );
            vertices->push_back( osg::Vec3( 0.0, len, 0.0) );
            vertices->push_back( osg::Vec3( 0.0, 0.0,-len) );
            vertices->push_back( osg::Vec3( 0.0, 0.0, len) );

            // Bone
            vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0) );
            vertices->push_back( p );

            geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 8) );
            geometry->setVertexArray( vertices.get() );

            geode->addDrawable( geometry.get() );
        }
        else if ( _drawingFlag==2 )
        {
            osg::Quat quat;
            osg::ref_ptr<osg::Box> box = new osg::Box( p*0.5, p.length(), len, len );
            quat.makeRotate( osg::Vec3(1.0,0.0,0.0), p );
            box->setRotation( quat );

            geode->addDrawable( new osg::ShapeDrawable(box.get()) );
        }
        
        return geode;
    }
开发者ID:BlitzMaxModules,项目名称:osg.mod,代码行数:38,代码来源:ReaderWriterBVH.cpp

示例7: applyConstrainedTranslation


//.........这里部分代码省略.........
                        rot.makeRotate(dirVec, localHitNormal);
                        //std::cout << "flipped = " << rot.x()<<","<<rot.y()<<","<<rot.z()<<","<<rot.w() << " ... angle=" << acos(rot.w())*2 << ", indegrees=" << osg::RadiansToDegrees(acos(rot.w()))*2 << std::endl;
                    }


                    osg::Vec3 rotEulers = QuatToEuler(rot);
                    //std::cout << "newHitNormal:\t" << localHitNormal.x()<<","<<localHitNormal.y()<<","<<localHitNormal.z() << std::endl;


                    if ((_mode==COLLIDE)||(_mode==COLLIDE_THRU)||(_mode==STICK))
                    {
                        // Let the collisionPoint be just a bit before the real
                        // hitpoint (to avoid numerical imprecision placing the
                        // node behind the plane):
                        osg::Vec3 collisionPoint = localHitPoint - (localHitNormal * 0.01);

                        // place the node at the collision point
                        setTranslation(collisionPoint.x(), collisionPoint.y(), collisionPoint.z());

                        BROADCAST(this, "ssfff", "collide", hitNode->id->s_name, osg::RadiansToDegrees(rotEulers.x()), osg::RadiansToDegrees(rotEulers.y()), osg::RadiansToDegrees(rotEulers.z()));


                        if (_mode==COLLIDE)
                        {
                            // SLIDE along the hit plane with the left over energy:
                            // ie, project the remaining vector onto the surface we
                            // just intersected with.
                            //
                            // using:
                            //   cos(theta) = distToSurface / remainderVector length
                            //
                            double cosTheta = (dirVec * -localHitNormal) ; // dot product
                            osg::Vec3 remainderVector = (localPos + v) - localHitPoint;
                            double distToSurface = cosTheta * remainderVector.length();
                            osg::Vec3 slideVector = remainderVector + (localHitNormal * distToSurface);

                            // pseudo-recursively apply remainder of bounce:
                            applyConstrainedTranslation( slideVector );
                        }
                        else if (_mode==COLLIDE_THRU)
                        {
                            // allow the node to pass thru (ie, just apply the
                            // translation):
                            //setTranslation(v.x(), v.y(), v.z());
                            osg::Vec3 newPos = localPos + v;
                            setTranslation(newPos.x(), newPos.y(), newPos.z());
                        }

                        return;
                    }


                    else if (_mode==BOUNCE)
                    {
                        // bounce returns a translation mirrored about the hit
                        // normal to the surface



                        // the new direction vector is a rotated version
                        // of the original, about the localHitNormal:
                        //osg::Vec3 newDir = (rot * 2.0) * -dirVec;
                        osg::Vec3 newDir = (rot * (rot * -dirVec));
                        newDir.normalize();
                        //std::cout << "newDir = " << newDir.x()<<","<<newDir.y()<<","<<newDir.z() << std::endl;
开发者ID:simonec77,项目名称:spinframework,代码行数:66,代码来源:ConstraintsNode.cpp

示例8: planePointDistanceRef

float cvr::planePointDistanceRef(const osg::Vec3 & planePoint,
        const osg::Vec3 & planeNormal, const osg::Vec3 & point)
{
    return ((point - planePoint) * planeNormal) / planeNormal.length();
}
开发者ID:dacevedofeliz,项目名称:calvr,代码行数:5,代码来源:OsgMath.cpp

示例9: calculateAngle

double CVehicle::calculateAngle(osg::Vec3 vecA,osg::Vec3 vecB)
{
	double angle,angleA,angleB;

	angle = acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angle < 0.0001)
	{
		angle = 0.0;
		return angle;
	}

	//求得vecA vecB分别与x轴正向的夹角
	angleA =  acos( vecA.x() / vecA.length() );   
	if( vecA.y() >= 0 )
		angleA = angleA;
	if( vecA.y() < 0 )
		angleA = 2.0 * osg::PI - angleA;


	angleB =  acos( vecB.x() / vecB.length() );   
	if( vecB.y() >= 0 )
		angleB = angleB;
	if( vecB.y() < 0 )
		angleB = 2.0 * osg::PI - angleB;


	//得到两向量间的夹角,通过angleA angleB的关系来判断旋转的方向

	if( angleA > angleB && (angleA - angleB) <= osg::PI )
		angle = -1.0 * acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angleA > angleB && (angleA - angleB) > osg::PI)
		angle = acos(vecA * vecB / (vecA.length() * vecB.length())) ;


	if( angleA < angleB && (angleB - angleA) <= osg::PI )
		angle = acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angleA < angleB && (angleB - angleA) > osg::PI)
		angle = -1.0 *  acos(vecA * vecB / (vecA.length() * vecB.length()))  ;

	return angle;
}
开发者ID:HOUWEI,项目名称:VirtualCity,代码行数:41,代码来源:Vehicle.cpp

示例10: setAxis

 void setAxis(const osg::Vec3 &a)
 {
     axis_ = a / a.length();
 }
开发者ID:yueying,项目名称:osg,代码行数:4,代码来源:osgparticle.cpp


注:本文中的osg::Vec3::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。