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


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

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


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

示例1: setBaseAnimation

void 
Agent::updateLocomote(Ogre::Real deltaTime)
{
	//This is the update locomotion from the previous assignment
	// Set idle animation
	if (mDirection == Ogre::Vector3::ZERO)
	{
		if (nextLocation()) 
        {
			Ogre::Vector3 src = mBodyNode->getOrientation() * Ogre::Vector3::UNIT_Z;
				if ((1.0f + src.dotProduct(mDirection)) < 0.0001f) 
				{
					mBodyNode->yaw(Ogre::Degree(180));
				}
				else
				{
					Ogre::Quaternion quat = src.getRotationTo(mDirection);
					mBodyNode->rotate(quat);
				}
			setBaseAnimation(ANIM_RUN_BASE);
			setTopAnimation(ANIM_RUN_TOP);
		}
	}
	else
	{
       Ogre::Real move = mWalkSpeed * deltaTime;
       mDistance -= move;
	   if (mDistance <= 0.0f)
	   {
		   mBodyNode->setPosition(mDestination);
		   mDirection = Ogre::Vector3::ZERO;
		   if (!nextLocation())
		   {                  
			   setBaseAnimation(ANIM_IDLE_BASE);
			   setTopAnimation(ANIM_IDLE_TOP);
		   } 
		   else
		   {
			   Ogre::Vector3 src = mBodyNode->getOrientation() * Ogre::Vector3::UNIT_Z;
			   if ((1.0f + src.dotProduct(mDirection)) < 0.0001f) 
			   {
				   mBodyNode->yaw(Ogre::Degree(180));
			   }
			   else
			   {
				   Ogre::Quaternion quat = src.getRotationTo(mDirection);
				   mBodyNode->rotate(quat);
			   } 
		   }
	   }
	   else { mBodyNode->translate(mDirection * move); }
	}
	
}
开发者ID:Segobiano,项目名称:425_Final_Project,代码行数:54,代码来源:Agent.cpp

示例2: approach

void EnemyController::approach(void)
{
	EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR));
	Ogre::Vector3 temp = FCKnowledge::getSingleton().getPlayerPosition() - enemy->getPosition();
	Ogre::Vector3 direction = temp * enemy->getAxis();
	//std::cout<<direction.x<<" "<<direction.y<<" "<<direction.z<<std::endl;
	if(direction.angleBetween(Ogre::Vector3::NEGATIVE_UNIT_Z) >= Ogre::Radian(Ogre::Degree(1)))
	{
		Ogre::Quaternion test = direction.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Z);
		Ogre::Degree angle = enemy->getRotateLimit();
		
		double yawNum = test.getYaw().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees();
		yawNum = Ogre::Math::Clamp(yawNum, -1.0, 1.0);
		enemy->yaw(yawNum);

		double pitchNum = test.getPitch().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees();
		pitchNum = Ogre::Math::Clamp(pitchNum, -1.0, 1.0);
		enemy->pitch(pitchNum);
		
		double rollNum = test.getRoll().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees();
		rollNum = Ogre::Math::Clamp(rollNum, -1.0, 1.0);
		enemy->roll(rollNum);
		
	}
	else
	{
		enemy->yaw(0);
		enemy->pitch(0);
		enemy->roll(0);
	}
}
开发者ID:utah2013zyd,项目名称:Game,代码行数:31,代码来源:EnemyController.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: frameRenderingQueued

//-----------------------------------------------------------------------------
bool IntermediateTutorial1::frameRenderingQueued(const Ogre::FrameEvent &evt)
{
	if (mDirection == Ogre::Vector3::ZERO) 
	{
		if (nextLocation()) 
		{
			// Set walking animation
			mAnimationState = mEntity->getAnimationState("Walk");
			mAnimationState->setLoop(true);
			mAnimationState->setEnabled(true);

			rotateRobotToDirection();
		}
	}
	else
	{
		Ogre::Real move = mWalkSpeed * evt.timeSinceLastFrame;
		mDistance -= move;
		if (mDistance <= 0.0f)
		{
			mNode->setPosition(mDestination);
			mDirection = Ogre::Vector3::ZERO;

			// Set animation based on if the robot has another point to walk to. 
			if (!nextLocation())
			{
				// Set Idle animation                     
				mAnimationState = mEntity->getAnimationState("Idle");
				mAnimationState->setLoop(true);
				mAnimationState->setEnabled(true);
			} 
			else
			{
				// Rotation Code will go here later
				Ogre::Vector3 src = mNode->getOrientation() * Ogre::Vector3::UNIT_X;
				if ((1.0f + src.dotProduct(mDirection)) < 0.0001f) 
				{
					mNode->yaw(Ogre::Degree(180));
				}
				else
				{
					Ogre::Quaternion quat = src.getRotationTo(mDirection);
					mNode->rotate(quat);
				} // else
			}
		}
		else
		{
			mNode->translate(mDirection * move);
		} // else
	} // if


	mAnimationState->addTime(evt.timeSinceLastFrame);

	return BaseApplication::frameRenderingQueued(evt);
}
开发者ID:asnwerear,项目名称:VEngine,代码行数:58,代码来源:IntermediateTutorial1.cpp

示例5: rotatePlayer

void PlayerObject::rotatePlayer() {
    Ogre::Vector3 src = objectNode->getOrientation() * Ogre::Vector3::UNIT_X;
    src.y = 0;
    mDirection.y = 0;
    src.normalise();
    Ogre::Real mDistance = mDirection.normalise();
    Ogre::Quaternion quat = src.getRotationTo(mDirection);

    objectNode->rotate(quat);
    objectNode->yaw(Ogre::Degree(-90));
} // rotatePlayer
开发者ID:mattschwartz,项目名称:rogre,代码行数:11,代码来源:PlayerObject.cpp

示例6:

//-----------------------------------------------------------------------------
void IntermediateTutorial1::rotateRobotToDirection(void)
{
	Ogre::Vector3 src = mNode->getOrientation() * Ogre::Vector3::UNIT_X;      // Orientation from initial direction
	src.y = 0;                                                    // Ignore pitch difference angle
	mDirection.y = 0;
	src.normalise();
	Ogre::Real mDistance = mDirection.normalise( );                     // Both vectors modified so renormalize them
	Ogre::Quaternion quat = src.getRotationTo(mDirection);

	mNode->rotate(quat);
}
开发者ID:asnwerear,项目名称:VEngine,代码行数:12,代码来源:IntermediateTutorial1.cpp

示例7: rotateTank

void Tank::rotateTank(void){
	Ogre::Vector3 src = mTankBodyNode->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_X;
				
	if ((1.0 + src.dotProduct(mDirection)) < 0.0001) 
	{
		mTankBodyNode->yaw(Ogre::Degree(180));
	}
	else
	{
		Ogre::Quaternion quat = src.getRotationTo(mDirection);
		mTankBodyNode->rotate(quat);
	}   
}
开发者ID:swn881,项目名称:CSCI356_JUSTDOEET,代码行数:13,代码来源:TankManager.cpp

示例8: _setViewMode

//-----------------------------------------------------------------------------------------
bool CCameraEditor::_setViewMode(OgitorsPropertyBase* property, const int& value)
{
    if(value)
    {
        if(mAutoTrackTarget->get() != "None")
            _setAutoTrackTarget(mAutoTrackTarget, "None");

        //Set it to CVM_FREE so we can set to new orientation
        mViewMode->init(0);
        Ogre::Vector3 normal = Ogre::Vector3::UNIT_Z;
        switch(value)
        {
        case CVM_GLOBAL_LEFT: setDerivedOrientation(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_X));break;
        case CVM_GLOBAL_RIGHT: setDerivedOrientation(normal.getRotationTo(Ogre::Vector3::UNIT_X));break;
        case CVM_GLOBAL_FRONT: setDerivedOrientation(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Z));break;
        case CVM_GLOBAL_BACK: setDerivedOrientation(Ogre::Quaternion::IDENTITY);break;
        case CVM_GLOBAL_TOP: setDerivedOrientation(normal.getRotationTo(Ogre::Vector3::UNIT_Y));break;
        case CVM_GLOBAL_BOTTOM: setDerivedOrientation(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Y));break;

        case CVM_LOCAL_LEFT: mOrientation->set(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_X));break;
        case CVM_LOCAL_RIGHT: mOrientation->set(normal.getRotationTo(Ogre::Vector3::UNIT_X));break;
        case CVM_LOCAL_FRONT: mOrientation->set(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Z));break;
        case CVM_LOCAL_BACK: mOrientation->set(Ogre::Quaternion::IDENTITY);break;
        case CVM_LOCAL_TOP: mOrientation->set(normal.getRotationTo(Ogre::Vector3::UNIT_Y));break;
        case CVM_LOCAL_BOTTOM: mOrientation->set(normal.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Y));break;
        }
        //Restore the value
        mViewMode->init(value);
    }
    else
    {
        if(mAutoTrackTarget->get() != "None")
            _setAutoTrackTarget(mAutoTrackTarget, mAutoTrackTarget->get());
    }

    return true;
}
开发者ID:ZelconGames,项目名称:Ogitor-Facade,代码行数:38,代码来源:CameraEditor.cpp

示例9: updateCharDirMoving

void PlayerCharacter::updateCharDirMoving(Ogre::Vector3* moveDir, unsigned long timeSinceLastFrame, Ogre::Radian &moveDirRotAngle)
{
	 // TODO: Running backwards goes crazy, turn too fast

	// http://www.ogre3d.org/tikiwiki/Intermediate+Tutorial+1&structure=Tutorials
	// http://www.ogre3d.org/tikiwiki/Quaternion+and+Rotation+Primer#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_

	if(!moveDir->isZeroLength())
	{
		Ogre::Vector3 src = this->node->getOrientation() * Ogre::Vector3::UNIT_Z;

		if ((1.0f + src.dotProduct(*moveDir)) < 0.0001f) 
		{
			this->node->yaw(Ogre::Degree(180));
		}
		else
		{
			Ogre::Quaternion quat = src.getRotationTo(*moveDir);
			this->node->rotate(quat);
		}
	}

	/*if(!moveDir->isZeroLength())
	{
		//Ogre::Vector3 targetDirection = Quaternion(moveDirRotAngle, Vector3::UNIT_Y) * (*moveDir);
		Ogre::Vector3 targetDirection = this->node->getOrientation() * *moveDir;

		Ogre::Radian rotationDifferenceToLastValue = m_lastTargetDirection.angleBetween(targetDirection);

		Radian targetRotation;

		if(rotationDifferenceToLastValue > Ogre::Radian(Ogre::Real(0.001)))
		{
			Quaternion rotationQuat = (Vector3::UNIT_X).getRotationTo(targetDirection, Vector3::UNIT_Y);

			Radian targetRotation = rotationQuat.getYaw();

			//m_moveRotation.setTargetValueWithAdjustedSmoothtime(targetRotation, true);
			m_moveRotation = targetRotation;
		}


		//m_moveRotation.smoothValue(timeSinceLastFrame);
		this->node->setDirection(0,0,-1, Node::TS_WORLD);
		this->node->yaw(m_moveRotation);

		m_lastTargetDirection = targetDirection;
	}*/
}
开发者ID:stevygee,项目名称:Animacion,代码行数:49,代码来源:PlayerCharacter.cpp

示例10:

void 
Robot::updateLocomote(Ogre::Real deltaTime)
{
	
	if (mDirection == Ogre::Vector3::ZERO)
	{
		if (this->nextLocation()) // a check to see if there is another destination
		{
			// Set walking animation
			this->setBaseAnimation(ANIM_WALK, true);
			this->setTopAnimation(ANIM_WALK, true);
		}
	}
	else
	{
		Ogre::Real move = mWalkSpeed * deltaTime;
		mDistance -= move;

		if (mDistance <= 0.0f) // over shooting target
		{
			this->mBodyNode->setPosition(mDestination);
			mDirection = Ogre::Vector3::ZERO;
			 if (!this->nextLocation()) // a check to see if there is another destination
			 {
				this->setBaseAnimation(ANIM_IDLE, true);
				this->setTopAnimation(ANIM_IDLE, true);
			 }
			 else
			 {
				 Ogre::Vector3 src = this->mBodyNode->getOrientation() * Ogre::Vector3::UNIT_X;
				 if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
				 {
					 this->mBodyNode->yaw(Ogre::Degree(180));
				 }
				 else
				 {
					Ogre::Quaternion quat = src.getRotationTo(mDirection);
					this->mBodyNode->rotate(quat);
					this->mBodyNode->yaw(Ogre::Degree(angleOffset));  // To correct for models facing different directions
				}
			 }
		}
		else
		{
			this->mBodyNode->translate(mDirection * move);
		}
	}
	
}
开发者ID:jannamcl,项目名称:AStar_OGRE3D,代码行数:49,代码来源:Robot.cpp

示例11: mousePressed

void PlayerObject::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id) {
    if (dead || attacking) {
        return;
    } // if
	int x = evt.state.X.abs;
	int y = evt.state.Y.abs;
	Ogre::Ray mouseRay = camera->getCameraToViewportRay(x/float(evt.state.width), y/float(evt.state.height));
	Ogre::Vector3 point = World::getInstance().getCurrentZone()->getIntersectingPlane(mouseRay);
    point.y = objectNode->getPosition().y;

    if (id == OIS::MB_Left) {
        walkTo = point;
    } // if
    else if (id == OIS::MB_Right) {
        int ran = rand() % 3;
        attacking = true;
        walkTo = objectNode->getPosition();
 
        // Rotate player
        Ogre::Vector3 dir = point - walkTo;
        Ogre::Vector3 src = objectNode->getOrientation() * Ogre::Vector3::UNIT_X;
        src.y = 0;
        dir.y = 0;
        src.normalise();
        Ogre::Real mDistance = dir.normalise();
        Ogre::Quaternion quat = src.getRotationTo(dir);

        objectNode->rotate(quat);
        objectNode->yaw(Ogre::Degree(-90));
        
        switch (ran) {
            case 0:
                mAnimationState = objectEntity->getAnimationState("Attack1");
                break;

            case 1:
                mAnimationState = objectEntity->getAnimationState("Attack2");
                break;

            default:
                mAnimationState = objectEntity->getAnimationState("Attack3");
        } // switch-case
        
        mAnimationState->setTimePosition(0);
        mAnimationState->setLoop(false);
        mAnimationState->setEnabled(true);
        SoundManager::getInstance().ATTACK_MISS_1_SOUND->play();
    } // else if
} // mousePresesd
开发者ID:mattschwartz,项目名称:rogre,代码行数:49,代码来源:PlayerObject.cpp

示例12: rotateToTarget

void Utility::rotateToTarget(Ogre::SceneNode* node,
											  const Ogre::Vector3& target,
											  bool ignoreY,
											  Ogre::Vector3 originalDirection)
{
	Ogre::Vector3 source = node->getOrientation() * originalDirection;
	if(ignoreY)
	{
		source.y = 0;
	}

	node->rotate(source.getRotationTo(target));

	return;
}
开发者ID:Dar13,项目名称:WastelandArchive,代码行数:15,代码来源:Utility.cpp

示例13: update

	void BaseTower::update(float time)
	{
		if(die)
			return;

		fireCD -= time;

		if(fireCD < 0 && !enemyFactory->enemyList.empty())
		{
			/*
			if(enemyFactory->enemyList.size() == 1)
			{
				Enemy *e= *enemyFactory->enemyList.begin();
				if(e->nearlyDie)
					return;
			}
			*/

			enemy = *enemyFactory->enemyList.begin();


			if(!ifInRange(enemy->getSceneNode()->getPosition(),sceneNode->getPosition(), range))
			{
				return;
			}

			fireCD = 2.0f;
			Ogre::Vector3 src = sceneNode->getOrientation() * Ogre::Vector3::UNIT_X;
			src.y = 0;

			Ogre::Vector3 direction = enemy->getSceneNode()->getPosition() - sceneNode->getPosition();
			direction.y = 0;
			Ogre::Quaternion quat = src.getRotationTo(direction); //direction
			sceneNode->rotate(quat);
			//sceneNode->yaw(Ogre::Degree(90));	

			Bullet *b = bulletFactory->generate(sceneNode->getPosition(), sceneNode->getOrientation(), BULLET_NORMAL);
			Vector3 v = b->getSceneNode()->getPosition();
			v.y = 160;
			b->getSceneNode()->setPosition(v);

			

		}
		
	}
开发者ID:robinbattle,项目名称:Knockout,代码行数:46,代码来源:BaseTower.cpp

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

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


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