本文整理汇总了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);
}
}
示例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 ) ;
}
}