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


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

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


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

示例1: intersectTri

bool OgreMesh::intersectTri(const Ogre::Ray &ray, IntersectResult &rtn, Triangle*itr, bool isplane) {
    std::pair<bool, Real> hit = isplane
      ? Ogre::Math::intersects(ray, Ogre::Plane(itr->v1.coord, itr->v2.coord,itr->v3.coord))
      : Ogre::Math::intersects(ray, itr->v1.coord, itr->v2.coord,itr->v3.coord, true, false);
    rtn.u = 0;
    rtn.v = 0;
    if (hit.first && hit.second < rtn.distance) {
      rtn.intersected = hit.first;
      rtn.distance = hit.second;
      Ogre::Vector3 nml=(itr->v1.coord-itr->v2.coord).
              crossProduct(itr->v3.coord-itr->v2.coord);
      rtn.normal.x=nml.x;
      rtn.normal.y=nml.y;
      rtn.normal.z=nml.z;
      rtn.tri = *itr;
      Ogre::Vector3 intersect = ray.getPoint(hit.second) - rtn.tri.v2.coord;
      Ogre::Vector3 aVec = (rtn.tri.v1.coord - rtn.tri.v2.coord);
      Ogre::Vector3 bVec = (rtn.tri.v3.coord - rtn.tri.v2.coord);
      if (aVec.length() > 1.0e-10 && bVec.length() > 1.0e-10) {
        rtn.u = rtn.tri.v2.u + (rtn.tri.v1.u - rtn.tri.v2.u)*cos(aVec.angleBetween(intersect).valueRadians())*intersect.length()/aVec.length();
        rtn.v = rtn.tri.v2.v + (rtn.tri.v3.v - rtn.tri.v2.v)*cos(bVec.angleBetween(intersect).valueRadians())*intersect.length()/bVec.length();
      }
    }
    return rtn.intersected;
}
开发者ID:LittleForker,项目名称:sirikata,代码行数:25,代码来源:OgreMeshRaytrace.cpp

示例2: OnUpdate

void BotControlComponent::OnUpdate(double time_diff) {
    if(IsEnabled()) {
        if(mAircraftComponentName == "") {
            dt::Logger::Get().Error("Cannot control aircraft: no aircraft component set.");
            return;
        }

        Ogre::Vector3 diff = mTarget - GetNode()->GetPosition(dt::Node::SCENE);
        if(diff.length() < 1) {
            mTarget = Ogre::Vector3(dt::Random::Get(-15.f, 15.f), dt::Random::Get(-10.f, 10.f), 0);
            diff = mTarget - GetNode()->GetPosition(dt::Node::SCENE);
        }
        diff.normalise();

        AircraftComponent* aircraft = GetNode()->FindComponent<AircraftComponent>(mAircraftComponentName);
        aircraft->GetPhysicsBody()->SetCentralForce(btVector3(diff.x, diff.y, 0) * 14);

        dt::Node* player = GetNode()->GetScene()->FindChildNode("player_aircraft");
        //target player
        diff = player->GetPosition(dt::Node::SCENE) - GetNode()->GetPosition(dt::Node::SCENE);
        aircraft->SetTargetAngle(Ogre::Vector3::UNIT_X.getRotationTo(diff, Ogre::Vector3::UNIT_Z).getRoll());

        if(diff.length() < 15)
            aircraft->Shoot();
    }
}
开发者ID:Blarget2,项目名称:gamejam,代码行数:26,代码来源:BotControlComponent.cpp

示例3: update

void AnimateableCharacter::update(Ogre::Real timeSinceLastFrame)
{
    updatePosition(timeSinceLastFrame);

    if (mClipTo)
        clipToTerrainHeight();

    Ogre::Vector3 velocity = getVelocity(); // Current velocity of agent
    Ogre::Real speed = velocity.length();

    if(speed > 0.15) {
        //mAnimState->setEnabled(true);
        //mAnimState->addTime(mAnimSpeedScale * speed * timeSinceLastFrame);

        if(speed > 0/*0.8*/) {  // Avoid jitter (TODO keep this?)
            // Rotate to look in walking direction
            Ogre::Vector3 src = getLookingDirection();
            src.y = 0;  // Ignore y direction

            velocity.y = 0;
            velocity.normalise();
            mNode->rotate(src.getRotationTo(velocity));
        }
    } else {    // Assume character has stopped
        mAnimState->setEnabled(false);
        mAnimState->setTimePosition(0);
		}
}
开发者ID:Alex-G,项目名称:MuOnline,代码行数:28,代码来源:AnimateableCharacter.cpp

示例4: isCameraInsideLight

bool DeferredLight::isCameraInsideLight(Ogre::Camera* camera) {
    switch (parentLight->getType()) {
        case Ogre::Light::LT_DIRECTIONAL:
            return false;
        case Ogre::Light::LT_POINT: {
            Ogre::Real distanceFromLight =
                camera->getDerivedPosition().distance(parentLight->getDerivedPosition());

            // Small epsilon fix to account for the fact that we aren't a true sphere.
            return distanceFromLight <= radius + camera->getNearClipDistance() + 0.1;
        }
        case Ogre::Light::LT_SPOTLIGHT: {
            Ogre::Vector3 lightPos = parentLight->getDerivedPosition();
            Ogre::Vector3 lightDir = parentLight->getDerivedDirection();
            Ogre::Radian attAngle = parentLight->getSpotlightOuterAngle();

            // Extend the analytic cone's radius by the near clip range by moving its tip accordingly.
            Ogre::Vector3 clipRangeFix = -lightDir * (camera->getNearClipDistance() / Ogre::Math::Tan(attAngle/2));
            lightPos = lightPos + clipRangeFix;

            Ogre::Vector3 lightToCamDir = camera->getDerivedPosition() - lightPos;
            Ogre::Real distanceFromLight = lightToCamDir.normalise();

            Ogre::Real cosAngle = lightToCamDir.dotProduct(lightDir);
            Ogre::Radian angle = Ogre::Math::ACos(cosAngle);

            // Check whether we will see the cone from our current POV.
            return (distanceFromLight <= (parentLight->getAttenuationRange() + clipRangeFix.length()))
                   && (angle <= attAngle);
        }
        default:
            return false;
    }
}
开发者ID:summerbreezeex,项目名称:SolidBlack,代码行数:34,代码来源:DeferredLight.cpp

示例5: Zoom

/*---------------------------------------------------------------------------------*/
void CameraHandler::Zoom(const OIS::MouseEvent &arg)
{
	bool okToZoom = false;
	//Direction from imaginary camera position to character
	Ogre::Vector3 directionToCharacter =  mvpCharNode->_getDerivedPosition() - mvpCamNoCollisionNode->_getDerivedPosition();
	//No direction in Y direction.
	directionToCharacter.y = 0;
	//To check if we're too close or too far
	Ogre::Real lengthToCharacter = directionToCharacter.length();

	//If zoom is positive, we only have to worry about going too close
	if (lengthToCharacter > *mvpCamDistanceMin && arg.state.Z.rel > 0)
	{
		okToZoom = true;
	}
	//If zoom is negative, we only have to worry about going too far
	else if (lengthToCharacter < *mvpCamDistanceMax && arg.state.Z.rel < 0)
	{
		okToZoom = true;
	}

	if (okToZoom)
	{
		//Always the same speed, not dependent of the distance
		directionToCharacter.normalise();
		//At the startup, the camera was translated @ Z axis.
		mvpCamNoCollisionNode->translate(Ogre::Vector3::NEGATIVE_UNIT_Z * (*mvpZoom) * arg.state.Z.rel, Ogre::Node::TS_LOCAL);
	}

}
开发者ID:dremerbuik,项目名称:projectkarma,代码行数:31,代码来源:CameraHandler.cpp

示例6: MouseWheel

void CombatCamera::MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys)
{
    Ogre::Real total_move = TotalMove(move, mod_keys, DistanceToLookAtPoint());
    if (0 < move)
    {
        const unsigned int TICKS = GG::GUI::GetGUI()->Ticks();

        const unsigned int ZOOM_IN_TIMEOUT = 750u;
        if (m_initial_zoom_in_position == INVALID_MAP_LOCATION ||
            ZOOM_IN_TIMEOUT < TICKS - m_previous_zoom_in_time)
        {
            std::pair<bool, Ogre::Vector3> intersection = IntersectMouseWithEcliptic(pt);
            m_initial_zoom_in_position = intersection.first ? intersection.second : INVALID_MAP_LOCATION;
        }

        if (m_initial_zoom_in_position != INVALID_MAP_LOCATION) {
            const double CLOSE_FACTOR = move * 0.333 * ZoomFactor(mod_keys);
            Ogre::Vector3 start = Moving() ? m_look_at_point_target : LookAtPoint();
            Ogre::Vector3 delta = m_initial_zoom_in_position - start;
            double delta_length = delta.length();
            double distance = std::min(std::max(1.0, delta_length * CLOSE_FACTOR), delta_length);
            delta.normalise();
            Ogre::Vector3 new_center = start + delta * distance;
            if (new_center.length() < SystemRadius())
                LookAtPositionAndZoom(new_center, ZoomResult(total_move));
        }

        m_previous_zoom_in_time = TICKS;
    } else if (move < 0) {
        ZoomImpl(total_move);
    }
}
开发者ID:Ablu,项目名称:freeorion,代码行数:32,代码来源:CombatCamera.cpp

示例7: separate

       Ogre::Vector3 separate(const Vehicle& agent,
                              const std::set<Vehicle*>& neighbours,
                              const float simulation_time)
       {
         Ogre::Vector3 result(Ogre::Vector3::ZERO) ;
         
         for(std::set<Vehicle*>::const_iterator neighbour = neighbours.begin() ;
             neighbour != neighbours.end() ;
             ++neighbour)
         {
           // test proximity
           const float sumOfRadii = agent.getRadius() + (*neighbour)->getRadius() ;
           const float minCenterToCenter = sumOfRadii;
 
           Ogre::Vector3 offset = (*neighbour)->predictFuturePosition(simulation_time)-
                                  agent.predictFuturePosition(simulation_time) ;
           const float futureDistance = offset.length() ;
           InternalMessage("SteeringBehaviour","SteeringBehaviour::separate offset=" +
                                       Kernel::toString(offset.x) + 
                                 "," + Kernel::toString(offset.y) + 
                                 "," + Kernel::toString(offset.z)) ;
           
           if (futureDistance < minCenterToCenter)
           {
             result += offset / (futureDistance*futureDistance) ;
           }
           InternalMessage("SteeringBehaviour","SteeringBehaviour::futureDistance =" + Kernel::toString(futureDistance)) ;
         }
         InternalMessage("SteeringBehaviour","SteeringBehaviour::separate =" +
                                     Kernel::toString(result.x) + 
                               "," + Kernel::toString(result.y) + 
                               "," + Kernel::toString(result.z)) ;
         return result ;
       }
开发者ID:BackupTheBerlios,项目名称:projet-univers-svn,代码行数:34,代码来源:steering_behaviour.cpp

示例8: UpdateAI

void CharacterController::UpdateAI(float dt)
{
	_CurrentPathAge += dt;
	//std::cerr << _CurrentPathIndex << " / " << _CurrentPath.size() << "\n";
	if (_CurrentPathIndex + 2 <= _CurrentPath.size())
	{
		Ogre::Vector3 const & a = _CurrentPath[_CurrentPathIndex];
		Ogre::Vector3 const & b = _CurrentPath[_CurrentPathIndex+1];
		Ogre::Vector3 const & m = GetPosition();
		Ogre::Vector3 const ab = b - a;
		Ogre::Vector3 const am = m - a;
		Ogre::Vector3 const mb = b - m;
		Ogre::Vector3 const mb_unit = mb.normalisedCopy();
		
		float remaining = mb.length();
		for(size_t i = _CurrentPathIndex + 1; i + 2 <= _CurrentPath.size(); ++i)
		{
			remaining += _CurrentPath[i].distance(_CurrentPath[i+1]);
		}
		//std::cerr << "Remaining distance: " << remaining << " m\n";
		
		float lambda = am.dotProduct(ab) / ab.squaredLength();
		
		//const float tau = 0.1;
		
		SetVelocity(_CurrentVelocity * mb_unit);
		
		if (lambda > 1) _CurrentPathIndex++;
		/*if (_CurrentPathIndex + 1 == _CurrentPath.size())
			SetVelocity(Ogre::Vector3(0.));*/
	}
}
开发者ID:Meumeu,项目名称:PMD,代码行数:32,代码来源:CharacterController.cpp

示例9: UpdateMovement

void CEntity::UpdateMovement(Ogre::Real ElapsedTime)
{
	//Also update walk/idle animation?
	if( IsMoving() ){
		Ogre::Real LenghtLeftToGo = (GetDestination() - GetPosition()).length();
		Ogre::Vector3 Movement = GetMovement();
		Ogre::Vector3 CorrectedMovement = ( Movement * ElapsedTime );

		//Set the right angle for the entity
		mNode->lookAt( GetDestination(), Ogre::Node::TS_WORLD );

		if( CorrectedMovement.length() < LenghtLeftToGo ){ //Not at destination yet, just move
			mNode->translate( CorrectedMovement );
		}else{ //Arrived at destination
			mNode->setPosition( GetDestination() );
			ReachedDestination();
			//TODO: If there is a next destination then go there with the frametime left of this movement.
			//(Loop till all frametime is used for movement)
			//Example: if there are 3 destinations left, and the first 2 will be reached
			//in 2 seconds.
			//If the user has a slow computer that updates the frame every 2,5 seconds,
			//then it should first use x seconds to reach destination one, then check
			//for how many seconds left, and use those to go to the next node and so on.
		}
	}
}
开发者ID:alexleclair,项目名称:NNYv3,代码行数:26,代码来源:Entity.cpp

示例10: orient

void AnimalThirdPersonControler::orient(int i_xRel, int i_yRel, double i_timeSinceLastFrame)
{
	if (!(m_pAnimal != nullptr && m_pCamera != nullptr))
		return;

	Ogre::Vector3 camPos = m_pCamera->getPosition();
	
	Ogre::Radian angleX(i_xRel * -m_camAngularSpeed);
	Ogre::Radian angleY(i_yRel * -m_camAngularSpeed);

	Ogre::Vector3 avatarToCamera = m_pCamera->getPosition() - m_pAnimal->m_pNode->getPosition();

	// restore lenght
	if (avatarToCamera.length() != m_camDistance)
		avatarToCamera = avatarToCamera.normalisedCopy() * m_camDistance;
	
	// Do not go to the poles
	Ogre::Radian latitude = m_pAnimal->m_pNode->getOrientation().zAxis().angleBetween(avatarToCamera);
	if (latitude < Ogre::Radian(Ogre::Math::DegreesToRadians(10.f)) && angleY < Ogre::Radian(0.f))
		angleY = Ogre::Radian(0.f);
	else if (latitude > Ogre::Radian(Ogre::Math::DegreesToRadians(170.f)) && angleY > Ogre::Radian(0.f))
		angleY = Ogre::Radian(0.f);

	Ogre::Quaternion orient = Ogre::Quaternion(angleY, m_pCamera->getOrientation().xAxis()) * Ogre::Quaternion(angleX, m_pCamera->getOrientation().yAxis());
	Ogre::Vector3 newAvatarToCamera = orient * avatarToCamera;

	// Move camera closer if collides with terrain
	m_collideCamWithTerrain(newAvatarToCamera);
}
开发者ID:BeanOfLight,项目名称:BeanOfLight,代码行数:29,代码来源:AnimalThirdPersonControler.cpp

示例11: evade

       Ogre::Vector3 evade(const Vehicle& agent,const Vehicle& target)
       {
         // a parameter
         const float maxPredictionTime = 2 ;
         
         Ogre::Vector3 offset = target.getPosition()-agent.getPosition() ;
         const float distance = offset.length() ;
         
         // may be equal to zero when target has reached agent 
         const float roughTime = distance / target.getSpeed().length() ;
 
         const float predictionTime = ((roughTime > maxPredictionTime) ?
                                       maxPredictionTime :
                                       roughTime);
     
         const Ogre::Vector3 menace_position = target.predictFuturePosition(predictionTime) ;
         
         Ogre::Vector3 desiredVelocity = agent.getPosition() - menace_position ;
         const float desiredSpeed =  desiredVelocity.normalise() ;
 
         if (desiredSpeed == 0)
         {
           desiredVelocity = agent.getForward() ;
           desiredVelocity.normalise() ;
         }
         
         // we should evade with maximum speed 
         desiredVelocity = desiredVelocity*agent.getMaxSpeed() ;
         agent.normalizeSpeed(desiredVelocity) ;
 
         return desiredVelocity-agent.getSpeed() ;
       }
开发者ID:BackupTheBerlios,项目名称:projet-univers-svn,代码行数:32,代码来源:steering_behaviour.cpp

示例12: distance

      /*
        distance(target_positon+t*target_speed) = t*interceptor_speed
        formal solver gives :
          
        delta = 
            (-target_positon.y^2-target_positon.x^2)*target_speed.z^2
            +(2*target_positon.y*target_positon.z*target_speed.y+2*target_positon.x*target_positon.z*target_speed.x)*target_speed.z
            +(-target_positon.z^2-target_positon.x^2)*target_speed.y^2
            +2*target_positon.x*target_positon.y*target_speed.x*target_speed.y
            +(-target_positon.z^2-target_positon.y^2)*target_speed.x^2
            +interceptor_speed^2*target_positon.z^2
            +interceptor_speed^2*target_positon.y^2
            +interceptor_speed^2*target_positon.x^2
        
        if delta > 0
        t = (sqrt(delta)
              -target_positon.z*target_speed.z-target_positon.y*target_speed.y-target_positon.x*target_speed.x)
            /(target_speed.z^2+target_speed.y^2+target_speed.x^2-laser_speed^2)
        
        special case for delta=0 when equation becomes linear
      */
      std::pair<bool,float> calculateInterceptionTime(
          const Ogre::Vector3& target_position,
          const Ogre::Vector3& target_speed,
          const float& interceptor_speed)
      {
        
        // result ;
        float time = 0 ;
        
        if (target_speed.length() != 0)
        {
          
          float delta = 
                  (-pow(target_position.y,2)-pow(target_position.x,2))*pow(target_speed.z,2)
                  +(2*target_position.y*target_position.z*target_speed.y+2*target_position.x*target_position.z*target_speed.x)*target_speed.z
                  +(-pow(target_position.z,2)-pow(target_position.x,2))*pow(target_speed.y,2)
                  +2*target_position.x*target_position.y*target_speed.x*target_speed.y
                  +(-pow(target_position.z,2)-pow(target_position.y,2))*pow(target_speed.x,2)
                  +pow(interceptor_speed,2)*pow(target_position.z,2)
                  +pow(interceptor_speed,2)*pow(target_position.y,2)
                  +pow(interceptor_speed,2)*pow(target_position.x,2) ;

          float divisor = target_speed.squaredLength()-pow(interceptor_speed,2) ;
          
          if (delta > 0 && fabs(divisor) > 1e-10)
          {
            float b = -target_position.z*target_speed.z-target_position.y*target_speed.y-target_position.x*target_speed.x ;
            time = (sqrt(delta)+b)/divisor ;
            if (time < 0)
              time = (-sqrt(delta)+b)/divisor ;
          }
          else
          {
            /// no real solution : target is unreachable by interceptor
            return std::pair<bool,float>(false,0) ;
          }
        }
        else
        {
          time = target_position.length()/interceptor_speed ;
        }
        
        return std::pair<bool,float>(true,time) ;
      }
开发者ID:BackupTheBerlios,项目名称:projet-univers-svn,代码行数:65,代码来源:algorithm.cpp

示例13: _notifyRescaled

	//-----------------------------------------------------------------------
	void LineEmitter::_notifyRescaled(const Ogre::Vector3& scale)
	{
		// Scale the internal attributes and use them, otherwise this results in too many calculations per particle
		ParticleEmitter::_notifyRescaled(scale);
		Ogre::Real scaleLength = scale.length();
		_mScaledEnd = mEnd * scale;
		_mScaledMaxDeviation = mMaxDeviation * scaleLength;
		_mScaledMinIncrement = mMinIncrement * scaleLength;
		_mScaledMaxIncrement = (mMaxIncrement - mMinIncrement) * scaleLength;
		_mScaledLength = _mScaledEnd.length();
	}
开发者ID:dbabox,项目名称:aomi,代码行数:12,代码来源:ParticleUniverseLineEmitter.cpp

示例14: move

void Bomber::move(Ogre::Vector3 distance)
{
	if(warpTimer <= 0.0 && distance.length() <= 10000){
		m_pNode->translate(m_pNode->getOrientation() * -50 * Ogre::Vector3::UNIT_Y);
		m_pNode->needUpdate();
		warpTimer = 60.0f;
	}else{
		warpTimer -= 0.1f;
	}
	
}
开发者ID:WilliamCreber,项目名称:COMP3501_EOY_Project,代码行数:11,代码来源:Bomber.cpp

示例15: createPositionBuffer

    //-------------------------------------------------------------------------
    void
    ManualObject::position( const Ogre::Vector3 &position )
    {
        if( m_position == nullptr )
        {
            createPositionBuffer();
        }
        *(m_position++) = position;

		m_bbox.merge( position );
		m_radius = std::max( m_radius, position.length() );
    }
开发者ID:adrielvel,项目名称:q-gears,代码行数:13,代码来源:QGearsManualObject.cpp


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