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


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

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


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

示例1: addTime

void MovementAnimation::addTime( Ogre::Real timeSinceLastFrame )
{
    if( mMoving )
    {
        Ogre::Real move = mSpeed * timeSinceLastFrame;

        Ogre::Vector3 position = mNode->getPosition();

        if( position.distance( mDestination ) < move )
        {
            position = mDestination;
        }
        else
        {
            // We work out direction each time, as the node may have been re-positioned by other code.
            Ogre::Vector3 direction = mDestination - position;

            direction.normalise();

            position += direction * move;
        }

        mNode->setPosition( position );
    }
}
开发者ID:merlinblack,项目名称:Game-Engine-Testbed,代码行数:25,代码来源:animation.cpp

示例2: calcDistance

/*
 * Calculates sound level by getting the distance of two vectors and mapping it between 0 and 255
 * using a given range (5000)
 */
int SoundManager::calcDistance(Ogre::Vector3 camPosition, Ogre::Vector3 soundPosition) {
   Ogre::Real distance = camPosition.distance(soundPosition); //get the distance between sound and camera
    if(distance > 5500)
      distance = 5500;
    int dist = distance/5500 * 255; //1500 should be the max range.
    return dist;
}
开发者ID:nolnoch,项目名称:game-tech,代码行数:11,代码来源:SoundManager.cpp

示例3: snapTpPortal

//-------------------------------------------------------------------------------
bool PortalEditor::snapTpPortal(PortalEditor* dest,bool bAllowMove )
{
    //reposition & realign this portal (and its parent zone)
    //to connect with this portal.

    //Before snapping portals togther, we should check that the zone is
    //not already locked into position by another portal join.
    //However, even if this is the case, we can still join portals if
    //they are already in the correct position.

    //get current position data:
    Ogre::Quaternion qZone = mParentZone->getDerivedOrientation();
    Ogre::Quaternion qDest = dest->getDerivedOrientation();
    Ogre::Quaternion qPortal = this->getOrientation();
    Ogre::Vector3 vDest = dest->getDerivedPosition();
    Ogre::Vector3 vPortal = this->getDerivedPosition();


    const Ogre::Real DIST_EPSILON(0.01f);//fudge factor
    const Ogre::Radian ANG_EPSILON(0.01f);
    if(vPortal.distance(vDest)<DIST_EPSILON && qPortal.equals(qDest*Ogre::Quaternion(0,0,1,0),ANG_EPSILON))return true;
    if(!bAllowMove)return false;

    //orientation
    Ogre::Quaternion qNew = (qDest*Ogre::Quaternion(0,0,1,0))*qPortal.Inverse();
    mParentZone->setDerivedOrientation(qNew);

    //position
    Ogre::Vector3 vZone = mParentZone->getDerivedPosition();
    vPortal = this->getDerivedPosition();

    mParentZone->setDerivedPosition( (vDest - (vPortal-vZone)));

    return true;
}
开发者ID:xubingyue,项目名称:Ogitor,代码行数:36,代码来源:PortalEditor.cpp

示例4: IsVisible

/*
 * Returns true if the given point is visible from the given viewpoint.
 *
 * A point is visible if it will be on screen, and if it is not occluded by
 * other objects.
 *
 * Input:
 *   point: The point whose visibility we want to check.
 *   viewpoint: The viewpoint to check from.
 *
 * Returns: True if the point is visible from the viewpoint.
 */
bool VisibilityChecker::IsVisible(const Ogre::Vector3& point,
                                  const Viewpoint& viewpoint) {
  float screen_x;
  float screen_y;
  auto old_position = camera_->getPosition();
  auto old_direction = camera_->getDirection();
  camera_->setPosition(viewpoint.position());
  camera_->lookAt(viewpoint.focus());
  GetScreenPosition(point, &screen_x, &screen_y);
  bool result = false;
  if (IsOnScreen(screen_x, screen_y)) {
    Ogre::Ray ray;
    camera_->getCameraToViewportRay(screen_x, screen_y, &ray);
    Ogre::Vector3 hit;
    if (RaycastAABB(ray, &hit)) {
      auto dist = point.distance(hit);
      if (dist < kOcclusionThreshold) {
        result = true;
      } else { // Hit something, but too far away from the target.
        result = false;
      }
    } else {
      // No hits. The ray should hit the target, but if it doesn't, that usually
      // indicates visibility. This is because if the target is occluded, the
      // ray is likely to have hit the occluding object.
      result = true;
    }
  } else { // Not on screen
    result= false;
  }
  camera_->setPosition(old_position);
  camera_->setDirection(old_direction);
  return result;
}
开发者ID:jstnhuang,项目名称:autocp,代码行数:46,代码来源:visibility.cpp

示例5: PushOgreBone

void IKChain::PushOgreBone(Ogre::Bone* OgreBone)
{
	Ogre::Bone* oBone = OgreBone;
	Ogre::Vector3 vecBonePos = oBone->getPosition();
	oBone->setManuallyControlled(true);
	IKJoint* oJoint = NULL;
	if ( mLastPush == NULL ) 
	{
		// Root
		oJoint = new IKJoint(oBone, NULL, oBone->getPosition().x + mMeshNode->getPosition().x, oBone->getPosition().y + mMeshNode->getPosition().y, oBone->getPosition().z + mMeshNode->getPosition().z);
		mIKRoot = oJoint;
		mJointCount = 1;
	}
	else
	{
		// Not root
		Ogre::Vector3 vecParent = mLastPush->GetOgreBone()->_getDerivedPosition();
		Ogre::Vector3 vecDerived = oBone->_getDerivedPosition();
		Ogre::Vector3 vecJointPos = oBone->_getDerivedPosition() + mMeshNode->getPosition();
		oJoint = new IKJoint(oBone, mLastPush, vecJointPos.x, vecJointPos.y, vecJointPos.z);
		mLastPush->SetChild(oJoint);
		mJointCount++;
		mChainLength += vecParent.distance(oBone->_getDerivedPosition());
	}
	mLastPush = oJoint;
	mIKEffector = oJoint;
	cout << "Joint count " << mJointCount << endl;
}
开发者ID:sandsmark,项目名称:loom,代码行数:28,代码来源:IKChain.cpp

示例6: calcAnimVelocity

float Animation::calcAnimVelocity(const NifOgre::TextKeyMap &keys, NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl, const Ogre::Vector3 &accum, const std::string &groupname)
{
    const std::string start = groupname+": start";
    const std::string loopstart = groupname+": loop start";
    const std::string loopstop = groupname+": loop stop";
    const std::string stop = groupname+": stop";
    float starttime = std::numeric_limits<float>::max();
    float stoptime = 0.0f;
    NifOgre::TextKeyMap::const_iterator keyiter(keys.begin());
    while(keyiter != keys.end())
    {
        if(keyiter->second == start || keyiter->second == loopstart)
            starttime = keyiter->first;
        else if(keyiter->second == loopstop || keyiter->second == stop)
        {
            stoptime = keyiter->first;
            break;
        }
        keyiter++;
    }

    if(stoptime > starttime)
    {
        Ogre::Vector3 startpos = nonaccumctrl->getTranslation(starttime) * accum;
        Ogre::Vector3 endpos = nonaccumctrl->getTranslation(stoptime) * accum;

        return startpos.distance(endpos) / (stoptime - starttime);
    }

    return 0.0f;
}
开发者ID:Chiur,项目名称:openmw,代码行数:31,代码来源:animation.cpp

示例7: SolveForTargetXInv

void IKChain::SolveForTargetXInv(Ogre::Vector3 Target, double Pitch, double Yaw, double Roll)
{
	double dRate = Target.distance(GetEffectorPosition()) / mChainLength;
	for ( int i = 0; i < 5; i++ )
	{
		mIKRoot->GetEffector()->DoSolverIterationXInv(Target, dRate, Pitch, Yaw, Roll);
		dRate = dRate / 1.5;
	}
}
开发者ID:sandsmark,项目名称:loom,代码行数:9,代码来源:IKChain.cpp

示例8: SolveForTargetYInv

void IKChain::SolveForTargetYInv(Ogre::Vector3 Target)
{
	double dRate = Target.distance(GetEffectorPosition()) / mChainLength;
	for ( int i = 0; i < 5; i++ )
	{
		mIKRoot->GetEffector()->DoSolverIterationYInv(Target, dRate);
		dRate = dRate / 1.5;
	}
}
开发者ID:sandsmark,项目名称:loom,代码行数:9,代码来源:IKChain.cpp

示例9: isSafeGoingThroughOpponent

bool Team::isSafeGoingThroughOpponent(const Ogre::Vector3& from, const Ogre::Vector3& target, float force, Player* opponent)
{
	Ogre::Vector3 to_target = target - from;
	Ogre::Vector3 to_opponent = Vector3To2(opponent->getPosition() - from);

	// If opponent if behind this player
	if (to_target.dotProduct(to_opponent) < 0)
	{
		return true;
	}

	// If Distance(opponent, from) > Distance(from, target), pass
	if (opponent->getPosition().distance(from) > from.distance(target))
	{
		return true;
	}

	// If the opponent can intercept the ball
	float x = to_target.z;
	float z = -to_target.x;
	Ogre::Vector3 oppo_pos = Vector3To2(opponent->getPosition());
	Ogre::Vector3 oppo_pos_away = oppo_pos + Ogre::Vector3(x, 0, z).normalisedCopy() * 300.f;
	Ogre::Vector3 intersect_point;
	if (GeometryHelper::get().lineSegmentIntersect(from, target, oppo_pos, oppo_pos_away, intersect_point))
	{
		float oppo_to_intersect = oppo_pos.distance(intersect_point);
		float ball_to_intersect = from.distance(intersect_point);
		float time = mBall->getTimeToCoverDistance(ball_to_intersect, force);
		if (time <= 0 || oppo_to_intersect / opponent->getMaxSpeed() < time)
		{
			return false;
		}
	}

	return true;
}
开发者ID:LiuJack,项目名称:FootballAI,代码行数:36,代码来源:Team.cpp

示例10: isSafeGoingThroughAllOpponents

bool Team::isSafeGoingThroughAllOpponents(const Ogre::Vector3& from, const Ogre::Vector3& target, float force)
{
	std::vector<Player*>& opponents = getOpponent()->getPlayers();
	const std::vector<Ogre::Vector3>& points = mPitch->getPassSafePolygon();

	for (int i = 0; i < points.size(); ++i)
	{
		mPassSafePolygon[i] = GetRotationThroughHeading(target - from) * points[i] + from; 
	}

	int num_in_polygon = 0;
	for (auto it = opponents.begin(); it != opponents.end(); ++it)
	{
		// If Distance(opponent, from) > Distance(from, target), pass
		if (from.distance((*it)->getPosition()) > from.distance(target))
		{
			continue;
		}
		
		if (GeometryHelper::get().isInPolygon((*it)->getPosition(), mPassSafePolygon))
		{
			++num_in_polygon;
		}
	}

	// No one in this region, pass is safe
	if (!num_in_polygon)
	{
		return true;
	}

	//return false;

	// Enforce to pass the ball
	return WithPossibility(0.01 / (num_in_polygon * num_in_polygon));
}
开发者ID:LiuJack,项目名称:FootballAI,代码行数:36,代码来源:Team.cpp

示例11: operateBulletEventSystem

void BulletHelixOperator::operateBulletEventSystem(Real timeElapsed)
{
    BulletEventSystem::BulletSystemVecotor::iterator it =  m_parent->getActiveBulletSystem().begin();
    while(it != m_parent->getActiveBulletSystem().end())
    {
        BulletSystem* pBulletSystem = *it;
        if(pBulletSystem && pBulletSystem->getIsCreated())
        {
            // 步骤:[6/2/2010 陈军龙]
            //      1.计算朝向
            //      2.将时间映射到曲线函数Sin (映射公式: (2 * PI) / (1 / Frequency) = x / Age  )
            //      3.计算绕螺旋的旋转轴的旋转偏移量
            //        (绕任意轴旋转公式:v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
            //        其中的 。代表点乘 * 代表叉乘,v是要旋转的向量,n是旋转轴,x是旋转的角度)
            //      4.根据到目标的百分比设置振幅,更新子弹位置
            static Ogre::Vector3 startpos = pBulletSystem->getCurrentPosition();
            Ogre::Vector3 direction = pBulletSystem->getTargetPosition() - startpos;
            direction.normalise();

            Real fCumulateTime = pBulletSystem->getAge();
            Real sinvalue = Ogre::Math::Sin(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
            Real cosvalue = Ogre::Math::Cos(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
            Ogre::Vector3 absoffset, vdelta;
            vdelta = Ogre::Vector3::UNIT_Y;//此次设置为Y轴,也可以设置为其它
            // v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
            absoffset = (vdelta - (vdelta.dotProduct(direction)) * direction) * cosvalue
                        + (vdelta.crossProduct(direction)) * sinvalue
                        + (vdelta.dotProduct(direction)) *direction;

            Real oridistance = startpos.distance(pBulletSystem->getTargetPosition());
            Real curdistance = pBulletSystem->getCurrentPosition().distance(pBulletSystem->getTargetPosition());
            Real percent = Ogre::Math::RealEqual(oridistance, 0) ? 1 : curdistance/oridistance;

            TransformInfo info;
            info = pBulletSystem->getTransformInfo();
            Ogre::Vector3 vBulletPosition = info.mPosition;
            vBulletPosition += (m_amplitude * absoffset * percent);

            info.mPosition = vBulletPosition;
            pBulletSystem->setTransformInfo(info);
            pBulletSystem->setPosition(info.mPosition);
        }
        it ++;
    }
}
开发者ID:gitrider,项目名称:wxsj2,代码行数:45,代码来源:FairyBulletHelixOperator.cpp

示例12: getNearestNode

int WalkabilityMap::getNearestNode(Ogre::Vector3 position)
{
	int nearestNode=-1;
	double minDistance=-1;
	double currentDistance;

	boost::graph_traits<Graph>::vertex_iterator vit,vend;
	for (tie(vit, vend) = vertices(mGraph); vit != vend; ++vit) 
	{
		currentDistance=position.distance(mGraph[*vit].mSceneNode->getPosition());
		if(minDistance==-1 || minDistance>currentDistance)
		{
			minDistance=currentDistance;
			nearestNode=*vit;
		}
	}

	return nearestNode;
}
开发者ID:juanjmostazo,项目名称:once-upon-a-night,代码行数:19,代码来源:WalkabilityMap.cpp

示例13: _getScoreOfPosition

float Team::_getScoreOfPosition(const Ogre::Vector3& position)
{
	// Closer to opponent's goal
	float score = 9.f * fabs((position - mGoal->getCenter()).x) / (2 * Prm.HalfPitchWidth);

	// 距离控球队员的距离
	float best_dist = 8.f;
	float dist_to_ctrl = fabs(position.distance(getControllingPlayer()->getPosition()));

	if (dist_to_ctrl > best_dist)
	{
		score += 4.f * (best_dist / (1.1 * dist_to_ctrl));
	}
	else 
	{
		score += 4.f * (dist_to_ctrl / best_dist);
	}

	return score;
}
开发者ID:aeronzhou,项目名称:FootballAI,代码行数:20,代码来源:Team.cpp

示例14: makeDecision

void EnemyAIModelHunt::makeDecision(MOC::CollisionTools *mCollisionTools, const Ogre::FrameEvent& evt, Enemy *enemy, ZombiePack **zombies, int nZombies)
{
	if (aux >= rate)
	{
		double x, z;
		movModel->calculateMove(enemy, zombies, nZombies, &x, &z);

		// Calculamos si está demasiado cerca:
		Ogre::Vector3 myPos = enemy->node->getPosition();
		if (myPos.distance(Ogre::Vector3(x, myPos.y, z)) < enemy->range*0.5)
		{
			x = 2 * myPos.x - x;
			z = 2 * myPos.z - z;
		}

		enemy->move(x, z);
	}

	enemy->update(mCollisionTools, evt, zombies);
}
开发者ID:BGCX261,项目名称:zproject-iav-git,代码行数:20,代码来源:EnemyAIModel.cpp

示例15: Initialize

void IKChain::Initialize()
{
	// Get skeleton root Ogre::Bone
	Ogre::Bone* oBoneRoot = mOgreSkeleton->getRootBone();
	Ogre::Vector3 vecBonePos = oBoneRoot->getPosition();
	oBoneRoot->setManuallyControlled(true);
	// Create IK root
	mIKRoot = new IKJoint(oBoneRoot, NULL, oBoneRoot->getPosition().x + mMeshNode->getPosition().x, oBoneRoot->getPosition().y + mMeshNode->getPosition().y, oBoneRoot->getPosition().z + mMeshNode->getPosition().z);
	// Keep track of previously processed Ogre::Bone
	IKJoint* oLastIKJoint = mIKRoot;
	// Current Ogre::Bone
	Ogre::Bone* oCurrentBone = oBoneRoot;
	cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
	mJointCount = 1;
	// Ogre::Bone iterator
	Ogre::Node::ChildNodeIterator oIterator = oCurrentBone->getChildIterator();
	Ogre::Vector3 vecParent = oBoneRoot->_getDerivedPosition();
	while ( oIterator.hasMoreElements() ) 
	{
		oCurrentBone = (Ogre::Bone*)oIterator.getNext();
		oCurrentBone->setManuallyControlled(true);
		cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
		Ogre::Vector3 vecDerived = oCurrentBone->_getDerivedPosition();
		Ogre::Vector3 vecJointPos = oCurrentBone->_getDerivedPosition() + mMeshNode->getPosition();
		vecBonePos = oCurrentBone->getPosition();
		IKJoint* oNewJoint = new IKJoint(oCurrentBone, oLastIKJoint, vecJointPos.x, vecJointPos.y, vecJointPos.z);
		oLastIKJoint->SetChild(oNewJoint);
		oLastIKJoint = oNewJoint;
		oIterator = oCurrentBone->getChildIterator();
		mJointCount++;
		mChainLength += vecParent.distance(oCurrentBone->_getDerivedPosition());
		vecParent = oCurrentBone->_getDerivedPosition();
	}
	mChainLength = mChainLength;
	mIKEffector = oLastIKJoint;
	cout << "Ogre::Bone count is " << mJointCount << endl;
}
开发者ID:sandsmark,项目名称:loom,代码行数:37,代码来源:IKChain.cpp


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