• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ogre::Vector3类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: destination

//-------------------------------------------------------------------------------------
bool
PlayersManager::moving(zappy::Player *p, int i)
{
  OPlayer *OPlayer = this->mOPlayers.at(i);
  this->speed = Constants::SquareSize /
    ((Constants::timeUnit / static_cast<Ogre::Real>(time)));

  Ogre::SceneNode *node = OPlayer->getSceneNode();
  Ogre::Vector3 &direction = OPlayer->getDirection();
  Ogre::Real &distance = OPlayer->getDistance();
  Ogre::Real move = this->speed * this->tslf;
  Ogre::Vector3 destination(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize);
  Ogre::AnimationState *anim = OPlayer->getEntity()->
    getAnimationState(distance <= 0.0f ? "Idle" : "Walk");

  anim->setLoop(true);
  anim->setEnabled(true);
  if (direction == Ogre::Vector3::ZERO)
    {
      Ogre::Vector3 src = node->getOrientation() * Ogre::Vector3::UNIT_X;
      direction = destination - node->getPosition();
      distance = direction.normalise();
      if ((1.0f + src.dotProduct(direction)) < 0.0001f)
        node->yaw(Ogre::Degree(180));
      else
        node->rotate(src.getRotationTo(direction));
      if (distance > Constants::SquareSize)
        distance = 0.0f;
    }
  else
    {
      distance -= move;
      if (distance <= 0.0f)
        {
          node->setPosition(destination);
          direction = Ogre::Vector3::ZERO;
        }
      else
        node->translate(direction * move);
    }
  if (OPlayer->stateHasChanged())
    OPlayer->detachAnim();
  anim->addTime(this->tslf);
  return true;
}
开发者ID:jorge-d,项目名称:zappy,代码行数:46,代码来源:PlayersManager.cpp


示例2: 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


示例3: IsCameraInside

bool DeferredLight::IsCameraInside(Ogre::Camera* camera)
{
    switch (mParentLight->getType())
    {
    case Ogre::Light::LT_DIRECTIONAL:
        return false;

    case Ogre::Light::LT_POINT:
        {
            Ogre::Real distanceFromLight =
                camera->getDerivedPosition().distance(mParentLight->getDerivedPosition());

            // Small epsilon fix to account for the fact that we aren't a true sphere.
            return distanceFromLight <= mRadius + camera->getNearClipDistance() + 0.1f;
        }

    case Ogre::Light::LT_SPOTLIGHT:
        {
            Ogre::Vector3 lightPos = mParentLight->getDerivedPosition();
            Ogre::Vector3 lightDir = mParentLight->getDerivedDirection();
            Ogre::Radian attAngle = mParentLight->getSpotlightOuterAngle();

            // Extend the analytic cone's radius by the near clip range by moving its
            // tip accordingly.
            // Some trigonometry needed here.
            Ogre::Vector3 clipRangeFix =
                -lightDir * (camera->getNearClipDistance() / Ogre::Math::Tan(attAngle / 2));
            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 <=
                    (mParentLight->getAttenuationRange() / cosAngle + clipRangeFix.length())) &&
                   (angle <= attAngle);
        }

    default:
        return false;
    }
}
开发者ID:davedissian,项目名称:dawnengine,代码行数:45,代码来源:DeferredLight.cpp


示例4: mouseMoveEvent

/** The user moved the mouse, if tracking process it
@param e The event data
*/
void QtSpacescapeWidget::mouseMoveEvent(QMouseEvent *e) {
    if (mMousePressed) {
        QPoint curPos = e->pos();
		
        double w = width();
        double h = height();
		
        double curX = (curPos.x() * 2. - w) / w;
        double curY = (h - curPos.y() * 2.) / h;
        double x0 = (mMousePressPos.x() * 2. - w) / w;
        double y0 = (h - mMousePressPos.y() * 2.) / h;
		
        Ogre::Vector3 v1(x0, y0, 0);
        Ogre::Vector3 v2(curX, curY, 0);
		
        double radiusSqr = mRADIUS * mRADIUS;
        double cutoff = radiusSqr * 0.5;
        double Rho = v1[0] * v1[0] + v1[1] * v1[1];
        v1[2] = (Rho < cutoff) ? sqrt(radiusSqr - Rho) : (cutoff / sqrt(Rho));
		
        Rho = v2[0] * v2[0] + v2[1] * v2[1];
        v2[2] = (Rho < cutoff) ? sqrt(radiusSqr - Rho) : (cutoff / sqrt(Rho));
		
        // v_cross is the normal of rotating plane
        Ogre::Vector3 cross = v2.crossProduct(v1);
        cross.normalise();

        // compute the angle
        v1.normalise();
        v2.normalise();
        double cosAngle = v1.dotProduct(v2);
        if (cosAngle < -1.0)
            cosAngle = -1.0;
        else if(cosAngle > 1.0)
            cosAngle = 1.0;
        double angle = acos(cosAngle);
		
        mCameraNode->rotate(cross, Ogre::Radian(angle));
		
        mMousePressPos = curPos;
        mLastCamOrientation = mCameraNode->getOrientation();

        update();
    }
}
开发者ID:StevenChristy,项目名称:Spacescape,代码行数:48,代码来源:QtSpacescapeWidget.cpp


示例5: Intersects

/*
*	\brief	Does this bounding box intersect with another
*/
const bool CSpaghettiBoundsSphere::Intersects( 
		CSpaghettiBounds *other,							//!< The bounding box to test against
		std::vector<CCollision> &collision
	)
{
	if (other->GetType() == BoundsType::Box)
	{
		// Sphere on box
		const bool result = other->Intersects(this, collision);
		if (!result)
			return false;

		return true;
	}
	else if (other->GetType() == BoundsType::Sphere)
	{
		// Sphere on sphere
		CSpaghettiBoundsSphere *const otherSphere = static_cast<CSpaghettiBoundsSphere*>(other);
		const float distance = (m_position - otherSphere->GetPosition()).length();
		const float radius = GetRadius() + otherSphere->GetRadius();

		if (distance <= radius)
		{
			Ogre::Vector3 collisionNormal = otherSphere->GetPosition() - GetPosition();
			collisionNormal.normalise();

			Ogre::Vector3 collisionPoint =collisionNormal * GetRadius();

			CCollision newCollision;
			newCollision.bodyOne = GetBody();
			newCollision.bodyTwo = otherSphere->GetBody();
			newCollision.collisionNormal = collisionNormal;
			newCollision.collisionPoint = GetPosition() + collisionPoint;
			newCollision.penetration = radius - distance;

			collision.push_back(newCollision);

			return true;
		}

		return false;
	}

	return false;
}
开发者ID:SamOatesUniversity,项目名称:Year-3---Physics---Spaghetti,代码行数:48,代码来源:CSpaghettiBoundsSphere.cpp


示例6: 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


示例7: update

void Fighter::update(Ogre::Real deltaTime)
{
	Ogre::Vector3 curPos = mNode->getPosition();
	Ogre::Vector3 direction = curPos - mCursorPos;

	Ogre::Vector3 src = mNode->getOrientation() * -Ogre::Vector3::UNIT_Z;
	src.y = 0;                                                   
	direction.y = 0;
	src.normalise();
	direction.normalise();
	
	mNode->setPosition(mNode->getPosition()+mCurrentMoveVector);
	Ogre::Quaternion quat = src.getRotationTo(direction); 

	mNode->rotate(quat);

	/*
	 * Update all shots
	 */
	for(std::vector<Shot*>::iterator it = mShots.begin(); it != mShots.end();)
	{
		(*it)->update(deltaTime);
		/**
		@see	http://www.ogre3d.org/forums/viewtopic.php?t=2519
				http://de.wikipedia.org/wiki/Projektionsmatrix
		 */
		Ogre::Vector3 hcpPos = (*mCameraPtr)->getProjectionMatrix()*(*mCameraPtr)->getViewMatrix()*mNode->getPosition();

		if ((hcpPos.x < -1.0f) || 
		  (hcpPos.x > 1.0f) ||
		  (hcpPos.y < -1.0f) || 
		  (hcpPos.y > 1.0f))
		{
			(*it)->die();
			delete (*it);
			it = mShots.erase(it);
		}
		else
		{
			++it;
		}
	}
	//Update positon for enemies
	mCurrentPosition = mNode->getPosition();
}
开发者ID:tscheims1,项目名称:ogre,代码行数:45,代码来源:Figther.cpp


示例8:

  void
  CharacterController::_doOgreOpcodeCollision(CollisionPacket& colData,
      float sweepOffset)
  {
    Ogre::Vector3 pos_R3 = colData.basePoint * colData.eRadius;
    Ogre::Vector3 vel_R3 = colData.velocity * colData.eRadius;

    OgreOpcode::CollisionPair** reports;

    // TODO: sweptSphereCheck does not support ellipsoids,
    // so we must use only one dimension!!!
    Ogre::Real radius = colData.eRadius.x;

    // Add a little offset to velocity so that we don't get too close.
    Ogre::Vector3 offset = vel_R3;
    offset.normalise();
    offset *= sweepOffset;

    OgreOpcode::Details::CollisionClass collClass =
        OgreOpcode::COLLTYPE_ALWAYS_EXACT;

    int count =
        OgreOpcode::CollisionManager::getSingletonPtr()->getDefaultContext()->sweptSphereCheck(
            pos_R3, vel_R3 + offset, radius, collClass, reports);

    if (count)
      {
        // search for closest distance collision
        int closest = 0;
        Ogre::Real d = reports[0]->distance;
        for(int i = 1; i < count; i++){
        if (reports[i]->distance < d)
          {
            d = reports[i]->distance;
            closest = i;
          }
      }

        colData.foundCollision = true;
        colData.nearestDistance = reports[closest]->distance;
        colData.intersectionPoint = reports[closest]->contact / colData.eRadius;

        mContactName = reports[closest]->other_object->getName();
      }
  }
开发者ID:PlumInTheLateAfternoonShade,项目名称:ember_gsoc_2013_test,代码行数:45,代码来源:OgreOpcodeCharacterController.cpp


示例9: wanderMovement

void Tank::wanderMovement(const float & deltaTime)
{
	if(wanderPathCreated)
	{
		if (mWanderDirection == Ogre::Vector3::ZERO) 
		{
			wanderNextLocation();
		}
		else
		{

			Ogre::Real move = mMoveSpd * (deltaTime);
			mWanderDistance -= move;
			Ogre::Vector3 src = mTankBodyNode->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_X;
	
			//http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer
			//this is used for rotation of the tank
			if ((1.0 + src.dotProduct(mWanderDirection)) < 0.0001) 
			{
				mTankBodyNode->yaw(Ogre::Degree(180));
			}
			else
			{
				mWanderDirection.y = 0;
				Ogre::Quaternion quat = src.getRotationTo(mWanderDirection);
				
				Ogre::Quaternion mOrientSrc = mTankBodyNode->getOrientation();
				Ogre::Quaternion mOrientDest = quat * mOrientSrc;
				Ogre::Quaternion delta = Ogre::Quaternion::nlerp(deltaTime * 2.0, mOrientSrc, mOrientDest, true);
				mTankBodyNode->setOrientation(delta);
			}      
			//for movement
			if (mWanderDistance <= 0)
			{
				mTankBodyNode->setPosition(mWanderDestination);
				mWanderDirection = Ogre::Vector3::ZERO;
			}
			else
			{
				mTankBodyNode->translate(move * mWanderDirection);
			}
		}
	}
	
}
开发者ID:swn881,项目名称:CSCI356_JUSTDOEET,代码行数:45,代码来源:TankManager.cpp


示例10: mSceneManager

MapCameraLightning::MapCameraLightning(Ogre::SceneManager& sceneManager)
: mSceneManager(sceneManager)
{
	mLight = sceneManager.createLight("MapFixedSunLight");
	mLight->setType(Ogre::Light::LT_DIRECTIONAL);

	mLight->setPosition(Ogre::Vector3(-500,300,-350));
	Ogre::Vector3 dir = -mLight->getPosition();
	dir.normalise();
	mLight->setDirection(dir);

	mLight->setDiffuseColour(Ogre::ColourValue(0.8, 0.8, 0.6)); //yellow
	//mSun->setSpecularColour(1, 1, 0.7); //yellow
	mLight->setCastShadows(false);
	mLight->setAttenuation(1000000, 1, 0, 0);

	mLight->setVisible(false);
}
开发者ID:Arsakes,项目名称:ember,代码行数:18,代码来源:Map.cpp


示例11: 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


示例12: 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


示例13: _behaviorIdle

void NPCCharacter::_behaviorIdle()
{
	stop();
	//still want to point the character in the direction last traveled.
	Ogre::Vector3 vel = getVelocity();
	float speed = vel.length();
	Ogre::Vector3 src = _node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
	src.y = 0;

	vel.y = 0;
	vel.normalise();
	_node->rotate(src.getRotationTo(vel));

	_isBhvFinished = true;

	//transition to idle animation
	_animHandler.blend("Idle",AnimationBlender::BlendWhileAnimating,.2f,true);
}
开发者ID:Dar13,项目名称:WastelandArchive,代码行数:18,代码来源:npc_character.cpp


示例14: cos

Ogre::Vector3 SuperEllipsoid::CalculateNormal(float phi, float beta, float n1, float n2,
                                              float scale_x, float scale_y, float scale_z)
{
  Ogre::Vector3 normal;

  float cos_phi = cos(phi);
  float cos_beta = cos(beta);
  float sin_phi = sin(phi);
  float sin_beta = sin(beta);

  normal.x = SIGN(cos_phi) * pow(fabs(cos_phi), 2-n1) * SIGN(sin_beta) * pow(fabs(sin_beta), 2-n2) / scale_x;
  normal.y = SIGN(sin_phi) * pow(fabs(sin_phi), 2-n1) / scale_y;
  normal.z = SIGN(cos_phi) * pow(fabs(cos_phi), 2-n1) * SIGN(cos_beta) * pow(fabs(cos_beta), 2-n2) / scale_z;

  normal.normalise();

  return normal;
}
开发者ID:janfrs,项目名称:kwc-ros-pkg,代码行数:18,代码来源:super_ellipsoid.cpp


示例15: collidesWithObject

	Ogre::Entity* CollisionTools::collidesWithObject(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const Ogre::uint32 queryMask)
	{
		Ogre::Vector3 normal = toPoint - fromPoint;
		float distToDest = normal.normalise();

		Ogre::Vector3 myResult(0, 0, 0);
		Ogre::Entity* myObject = NULL;
		float distToColl = 0.0f;

		if (raycastFromPoint(fromPoint, normal, myResult, myObject, distToColl, queryMask))
		{
			distToColl -= collisionRadius;
			if (distToColl <= distToDest)
				return myObject;
		}

		return NULL;
	}
开发者ID:robinbattle,项目名称:tankwar,代码行数:18,代码来源:CollisionTools.cpp


示例16: Seek

Ogre::Vector3 SteeringBehaviors::Pursuit(Character* evader)
{
	Ogre::Vector3 ToEvader = evader->GetSceneNode()->getPosition() - mCharacter->GetSceneNode()->getPosition();
	double RelativeHeading = mCharacter->GetHeading().dotProduct(evader->GetHeading());

	//if evader is in front and moving forward
	if((ToEvader.dotProduct(mCharacter->GetHeading())) > 0 && (RelativeHeading < -0.95))
		return Seek(evader->GetSceneNode()->getPosition());

	//not ahead so look forward
	double LookAheadTime = ToEvader.length() / (mCharacter->GetMaxSpeed() + evader->GetMaxSpeed());
	Ogre::Vector3 currentVelocity = evader->GetVelocity();
	Ogre::Real currentSpeed = currentVelocity.normalise();
	Ogre::Vector3 desiredVelocity =  Seek(evader->GetSceneNode()->getPosition() + evader->GetHeading() * currentSpeed * LookAheadTime);
	desiredVelocity.y = 0;
	return desiredVelocity;

}
开发者ID:kaoticscout,项目名称:Portfolio,代码行数:18,代码来源:SteeringBehaviors.cpp


示例17: 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


示例18: update

void BaseNpc::update(double timeSinceLastFrame)
{
  mAnimationState->addTime(timeSinceLastFrame);

  if (m_pCurrentState) {
    m_pCurrentState->Execute(this);
  }

  if (isMoving == false) {
    if (nextLocation(m_pNpcNode)) {
      // Set walking animation
      mAnimationState = m_pNPC->getAnimationState("Walk");
      mAnimationState->setLoop(true);
      mAnimationState->setEnabled(true);
      isMoving = true;
    } else {
      // Not moving and no locations in list
    }
  } else {
    Ogre::Real move = mWalkSpeed * timeSinceLastFrame;
    mDistance -= move;
    if (mDistance <= 0.0f) {
      m_pNpcNode->setPosition(mDestination);
      mDirection = Ogre::Vector3::ZERO;
      // Set animation based on if the robot has another point to walk to.
      if (! nextLocation(m_pNpcNode)) {
          // Set Idle animation
          mAnimationState = m_pNPC->getAnimationState("Idle");
          mAnimationState->setLoop(true);
          mAnimationState->setEnabled(true);
      } else {
        Ogre::Vector3 src = m_pNpcNode->getOrientation() * Ogre::Vector3::UNIT_X;
        if ((1.0f + src.dotProduct(mDirection)) < 0.0001f) {
          m_pNpcNode->yaw(Ogre::Degree(180));
        } else {
          Ogre::Quaternion quat = src.getRotationTo(mDirection);
          m_pNpcNode->rotate(quat);
        }
      }
    } else {
      m_pNpcNode->translate(mDirection * move);
    }
  }
}
开发者ID:Gorgoroth,项目名称:advanced-ogre-framework,代码行数:44,代码来源:BaseNpc.cpp


示例19: findCell

Cell* NavigationMesh::findCell(const Ogre::Vector3& pos) {
    Ogre::Vector3 v;
    Ogre::Vector3 minDistance = Ogre::Vector3(500.0, 500.0, 500.0);
    Cell* closestCell = 0;
    
    for (Cells::iterator i = _cells.begin(); i != _cells.end(); ++i) {
        if ((*i)->containsPoint(pos)) {
            return *i;
        }
	
	v = (*i)->getCenter() - pos;
	if (v.squaredLength() < minDistance.squaredLength()) {
	    minDistance = v;
	    closestCell = (*i);
	}
    }

    return closestCell;
}
开发者ID:manituan,项目名称:Artificial-Intelligence,代码行数:19,代码来源:navigationMesh.cpp


示例20: setDefinition

//------------------------------------------------------------------------------------------------
void RayDebugShape::setDefinition(const Ogre::Vector3& start,
                                  const Ogre::Vector3& direction,
                                  const Ogre::Real length) {
  clear();

  const Ogre::Vector3 end(start + (direction.normalisedCopy() * length));
  addLine(start, end);

  draw();
}
开发者ID:Dima-Meln,项目名称:ORSE,代码行数:11,代码来源:OgreBulletCollisionsDebugShape.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ogre::VertexBufferBinding类代码示例发布时间:2022-05-31
下一篇:
C++ ogre::UTFString类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap