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); } }
bool Zone::contains(const osg::Vec3& point) const { for(Boundaries::const_iterator b = _boundaries.begin(); b != _boundaries.end(); ++b) { if ( b->tope.empty() ) { return true; } else if ( b->tope.contains(point) ) { double hat2 = point.length2() - b->meanRadius2; // assumes round earth if ( hat2 >= b->zmin2 && hat2 <= b->zmax2 ) { return true; } } } return false; }
/* ....................................................................... */ 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 ) ; } }