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


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

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


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

示例1: createTreeList

void ForestTechniqueManager::createTreeList(osg::Node* terrain,const osg::Vec3& origin, const osg::Vec3& size,unsigned int numTreesToCreate,TreeList& trees)
{

    float max_TreeHeight = sqrtf(size.length2()/(float)numTreesToCreate);
    float max_TreeWidth = max_TreeHeight*0.5f;

    float min_TreeHeight = max_TreeHeight*0.3f;
    float min_TreeWidth = min_TreeHeight*0.5f;

    trees.reserve(trees.size()+numTreesToCreate);


    for(unsigned int i=0;i<numTreesToCreate;++i)
    {
        Tree* tree = new Tree;
        tree->_position.set(random(origin.x(),origin.x()+size.x()),random(origin.y(),origin.y()+size.y()),origin.z());
        tree->_color.set(random(128,255),random(128,255),random(128,255),255);
        tree->_width = random(min_TreeWidth,max_TreeWidth);
        tree->_height = random(min_TreeHeight,max_TreeHeight);
        tree->_type = 0;

        if (terrain)
        {
            osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
                new osgUtil::LineSegmentIntersector(tree->_position,tree->_position+osg::Vec3(0.0f,0.0f,size.z()));

            osgUtil::IntersectionVisitor iv(intersector.get());

            terrain->accept(iv);

            if (intersector->containsIntersections())
            {
                osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections();
                for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
                    itr != intersections.end();
                    ++itr)
                {
                    const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
                    tree->_position = intersection.getWorldIntersectPoint();
                }
            }
        }

        trees.push_back(tree);
    }
}
开发者ID:yueying,项目名称:osg,代码行数:46,代码来源:osgforest.cpp

示例2: fabs

/* ....................................................................... */
void
CharacterBase::_move(ooReal step_size)
{

    (void) step_size ;

    if( ! m_body.valid() ) {
        return ;
    }

    if( ! m_is_on_ground ) {
        m_lmotor->setParam(dParamVel, 0.0) ;
        m_lmotor->setParam(dParamFMax, 0.0) ;
        m_lmotor->setParam(dParamVel2, 0.0) ;
        m_lmotor->setParam(dParamFMax2, 0.0) ;
        m_lmotor->setParam(dParamVel3, 0.0) ;
        m_lmotor->setParam(dParamFMax3, 0.0) ;



        osg::Vec3   direction = m_body->getQuaternion() * m_motion_velocity ;

        const ooReal    speed = direction.normalize() ;
        const osg::Vec3 velocity = direction * speed ;

        const osg::Vec3 force = direction * m_body->getMass() * 9.80665f ;


        m_lmotor->setParam(dParamVel,   velocity.x()        ) ;
        m_lmotor->setParam(dParamVel2,  velocity.y()        ) ;
        m_lmotor->setParam(dParamVel3,  velocity.z()        ) ;

        m_lmotor->setParam(dParamFMax,  fabs( force.x() )   ) ;
        m_lmotor->setParam(dParamFMax2, fabs( force.y() )   ) ;
        m_lmotor->setParam(dParamFMax3, fabs( force.z() )   ) ;


        return ;
    }



    osg::Vec3   direction = m_motion_velocity ;

    direction = m_body->getQuaternion() * direction ;

    const ooReal    speed = direction.normalize() ;

    direction = direction ^ m_ground_contact_normal ;
    direction = m_ground_contact_normal ^ direction ;
    direction.normalize() ;

    const osg::Vec3 force = direction * m_motion_fmax * m_motion_fmax_mult ;
    const osg::Vec3 velocity = direction * speed ;


    m_lmotor->setParam(dParamVel,   velocity.x()        ) ;
    m_lmotor->setParam(dParamVel2,  velocity.y()        ) ;
    m_lmotor->setParam(dParamVel3,  velocity.z()        ) ;

    m_lmotor->setParam(dParamFMax,  fabs( force.x() )   ) ;
    m_lmotor->setParam(dParamFMax2, fabs( force.y() )   ) ;
    m_lmotor->setParam(dParamFMax3, fabs( force.z() )   ) ;




    if( m_jump_res_time <= 0.0  &&  force.length2() > 1.0e-1 ) {
        const ooReal    body_speed      = m_body->getLinearVelocity().length() ;

        const osg::Vec3 down_versor     = m_up_versor * -1.0 ;

        const ooReal    step_speed      = body_speed >= m_footstep_info.SpeedThreshold ;

        const ooReal    time_multiplier = body_speed * m_footstep_info.TimeMultiplier ;
        const ooReal    power_factor    = body_speed * m_footstep_info.PowerFactor ;
        const ooReal    magnitude       = body_speed * m_footstep_info.Magnitude ;


        m_footstep_time += step_size * time_multiplier * 2.0 * (ooReal)rand() / (ooReal)RAND_MAX ;


        const ooReal    sin_arg = m_footstep_time * 2.0 * osg::PI ;

        ooReal  strength = sin( sin_arg )  * 0.5  +  0.5 ;

        m_footstep_derivative = cos( sin_arg ) * osg::PI ;

        strength = pow( strength, power_factor ) ;



        m_body->addForce( down_versor * magnitude * strength * step_speed ) ;
    }
}
开发者ID:novichiv,项目名称:osgode,代码行数:96,代码来源:CharacterBase.cpp


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