本文整理汇总了C++中ogre::Vector3::normalise方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::normalise方法的具体用法?C++ Vector3::normalise怎么用?C++ Vector3::normalise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Vector3
的用法示例。
在下文中一共展示了Vector3::normalise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _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);
}
示例2: 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;
}
示例3: 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);
}
示例4: init
void RoomSurface::init(Ogre::Vector3 normal, Ogre::Real x_size, Ogre::Real z_size,
CreateVisualActor create_visual_actor) {
create_visual_actor_ = create_visual_actor == CREATE_VISUAL_ACTOR;
init();
normal.normalise();
normal_ = normal;
// ***Important***
// The surface is constructed from a "flat" rectangle sitting in the xz-plane, hence
// we define its size by the x- and z- sizes. Once the surface has been rotated to have the
// passed-in normal the x_size and z_size will not actually correspond to the surfaces'
// x and z dimensions in world space.
StaticBox::set_size(Ogre::Vector3(x_size, kSurfaceThickness, z_size));
// Rotate the box to correspond to the passed-in normal
set_orientation(surfaceOrientationForNormal(normal));
}
示例5: rotateTo
void CharacterMovement::rotateTo( QVector3D directionLook )
{
qDebug() << "[CharacterMovement::rotateTo]" << directionLook;
Ogre::Vector3 newDirection = UtilFunctions::qVector3dToOgreVector3( directionLook ) - _node->getPosition();
newDirection.y = 0;
newDirection.normalise();
// Check if it is necessary to rotate
// Ogre::Vector3 auxDirection = UtilFunctions::qVector3dToOgreVector3( _direction );
// auxDirection.normalise();
// qDebug() << "[CharacterMovement::rotateTo]" << directionLook << newDirection.dotProduct( auxDirection );
// if( newDirection.dotProduct( auxDirection ) != 1 )
{
_direction = UtilFunctions::ogreVector3ToQVector3d( newDirection );
_rotationValue = -4.0f; // TODO: find another was to stop the rotation (it wasn't stopping)
_rotating = true;
}
}
示例6: OnInit
// ----------------------------------------------------------
void OgreTestWidget::OnInit()
{
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC,"principal");
// create camera
mCamera = mSceneMgr->createCamera("PlayerCam_EntityPanel" + mName);
mCamera->setPosition(Ogre::Vector3(0, 0, -40));
mCamera->lookAt(Ogre::Vector3(0,0,0));
mCamera->setAutoAspectRatio(true);
mCamera->setNearClipDistance(0.1);
// create viewport
mViewport = mRenderWindow->addViewport(mCamera);
mViewport->setBackgroundColour(Ogre::ColourValue(0.1, 0.1, 0.1, 1));
mCamera->setAspectRatio((mViewport->getActualWidth()) /
(mViewport->getActualHeight()));
mViewport->_updateDimensions();
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.1,0.1,0.1));
Ogre::Light* luz = mSceneMgr->createLight("Light0");
luz->setType(Ogre::Light::LT_SPOTLIGHT);
luz->setPosition(0,100,-100);
luz->setSpotlightRange(Ogre::Degree(10), Ogre::Degree(90));
Ogre::Vector3 direccion = -luz->getPosition();
direccion.normalise();
luz->setDirection(direccion);
luz->setDiffuseColour(1,1,1);
luz->setSpecularColour(0.25, 0.25, 0.25);
mFocusNodo = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3::ZERO);
mFocusNodo->attachObject(mCamera);
/*
mNodoEscena = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity* entity = mSceneMgr->createEntity("pelota1", "flechaShape.mesh");
mNodoEscena->attachObject(entity);
*/
}
示例7:
/* Return vector for a normalized (radius 1.0) sphere */
Ogre::Vector3 Grid::projectToSphere(unsigned int x, unsigned int y)
{
Ogre::Vector3 pos;
float mSizeFloat, xFloat, yFloat, halfStep;
mSizeFloat = static_cast<float>(gridSize);
xFloat = static_cast<float>(x)/mSizeFloat;
yFloat = static_cast<float>(y)/mSizeFloat;
halfStep = 1.0f/(mSizeFloat*2.0f);
// For convenience treat xy-heightmap as a xz-plane in sphere-coordinates
pos.x = 1.0f-halfStep - xFloat*2.0f;
pos.z = -1.0f+halfStep + yFloat*2.0f;
pos.y = 1.0f;
// Simple re-orientation
pos = orientation*pos;
// project heightMap to sphere
pos.normalise();
return pos;
}
示例8: _joinBones
void PhysicsRagDoll::_joinBones(PhysicsRagDoll::JointType type, RagBone* parent, RagBone* child, Ogre::Vector3 pos, Ogre::Vector3 pin, Ogre::Real limit1, Ogre::Real limit2, OgreNewt::World* world)
{
pin.normalise();
OgreNewt::Joint* joint = NULL;
switch (type)
{
case PhysicsRagDoll::JT_BALLSOCKET:
joint = new OgreNewt::BasicJoints::BallAndSocket(world, child->getBody(), parent->getBody(), pos);
((OgreNewt::BasicJoints::BallAndSocket*)joint)->setLimits(pin, Ogre::Degree(limit1), Ogre::Degree(limit2));
break;
case PhysicsRagDoll::JT_HINGE:
joint = new OgreNewt::BasicJoints::Hinge(world, child->getBody(), parent->getBody(), pos, pin);
((OgreNewt::BasicJoints::Hinge*)joint)->setCallback(RagBone::_hingeCallback);
joint->setUserData(Ogre::Any(child));
child->setLimits(limit1, limit2);
break;
}
}
示例9: collidesWithEntity
bool CollisionTools::collidesWithEntity(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const float rayHeightLevel, const Ogre::uint32 queryMask)
{
Ogre::Vector3 fromPointAdj(fromPoint.x, fromPoint.y + rayHeightLevel, fromPoint.z);
Ogre::Vector3 toPointAdj(toPoint.x, toPoint.y + rayHeightLevel, toPoint.z);
Ogre::Vector3 normal = toPointAdj - fromPointAdj;
float distToDest = normal.normalise();
Ogre::Vector3 myResult(0, 0, 0);
Ogre::MovableObject* myObject = NULL;
float distToColl = 0.0f;
if (raycastFromPoint(fromPointAdj, normal, myResult, myObject, distToColl, queryMask))
{
distToColl -= collisionRadius;
return (distToColl <= distToDest);
}
else
{
return false;
}
}
示例10:
//Moves the Character
Ogre::Vector3 PlayerCharacter::updateMovement(unsigned long timeSinceLastFrame, Vector3 inputMoveDir, Ogre::Radian* moveDirRotAngle)
{
//static const float maxUpdateDelay = 0.1f;
//Ogre::Vector3 moveVector = Quaternion(*moveDirRotAngle, Vector3::UNIT_Y) * inputMoveDir;
Ogre::Vector3 moveVector = this->node->getOrientation() * inputMoveDir;
moveVector.normalise();
// Acceleration
if( inputMoveDir.isZeroLength() )
{
curMoveSpeed -= 0.001f * timeSinceLastFrame;
curMoveSpeed = (curMoveSpeed < 0.001f) ? 0.f : curMoveSpeed;
}
else
{
curMoveSpeed += 0.001f * timeSinceLastFrame;
curMoveSpeed = (curMoveSpeed > maxMoveSpeed) ? maxMoveSpeed : curMoveSpeed;
}
// Standing or running?
if( curMoveSpeed == 0.f )
{
this->animation->setNextAction("stop");
return node->getPosition();
}
else
{
this->animation->setNextAction("run");
Ogre::Vector3 newPos = node->getPosition() + moveVector * curMoveSpeed * (Ogre::Real)timeSinceLastFrame;
this->node->setPosition(newPos);
// Pass actual character speed on to animation system
this->animation->setFlagValue( "character_speed", curMoveSpeed );
return newPos;
}
}
示例11: onHUDPhysicalSelect
void SingleplayerGame::onHUDPhysicalSelect(Player* attacker, Player* target) {
mAttackRunning = true;
bool attackSuccessful = attacker->attemptPhysicalAttack();
attacker->lookAt(target);
AnimationCallback cb = [this, attacker, target, attackSuccessful](void)-> void{
if (attackSuccessful) {
attacker->lookAt(target);
attacker->physicalAttack(*target);
if (!target->isDead()) {
time_t physicalStartTime = time(nullptr);
ParticleEndCheckCallback endCheck = [physicalStartTime](void) -> bool {
return difftime(time(nullptr), physicalStartTime) >= 1;
};
ParticleCallback onEnd = [](void) -> void {};
target->mParticleController->runParticleSystem(PT_Physical, endCheck, onEnd);
}
}
else {
attacker->missAttack(*target);
}
mAttackRunning = false;
attacker->mAnimationController->runIdleAnimation();
};
attacker->mAnimationController->runAnimation(AnimationType::Physical, cb);
if (attackSuccessful) {
mSoundBank->play("physical_woosh_fx");
mSoundBank->play("physical_impact_fx");
}
else {
mSoundBank->play("physical_miss_fx");
}
Ogre::Vector3 camPos = (attacker->sceneNode->_getDerivedPosition() + Ogre::Vector3(0, 200, 0)) - (target->sceneNode->_getDerivedPosition() + Ogre::Vector3(0, 100, 0));
camPos.normalise();
camPos *= 300;
camPos += (attacker->sceneNode->_getDerivedPosition() + Ogre::Vector3(0, 200, 0));
mRenderer->mCamera->setPosition(camPos);
mRenderer->mCamera->lookAt(target->sceneNode->_getDerivedPosition() + Ogre::Vector3(0, 100, 0));
}
示例12: Response
void SlideCollisionResponse::Response(PhysObjDescriptor* object, CollisionModel3D *CollisionModel, bool ismodelowner)
{
// при коллизии определяется треугольник и объект движется параллельно плоскости тругольника
float t1[9], t2[9], p[3], *t;
CollisionModel->getCollisionPoint(p,false);
Ogre::Vector3 normal, IntersectionPoint(p[0],p[1],p[2]);
CollisionModel->getCollidingTriangles(t1, t2, false);
if (ismodelowner)
t=t1;
else
t=t2;
Ogre::Plane collidplane(Ogre::Vector3(t[0],t[1],t[2]),
Ogre::Vector3(t[3],t[4],t[5]),
Ogre::Vector3(t[6],t[7],t[8]));
Ogre::Vector3 proj = collidplane.projectVector(object->LinVelocity);
proj.normalise();
Ogre::Vector3 Normal = collidplane.normal;
Ogre::Vector3 linvel = object->LinVelocity;
Ogre::Vector3 throttle = object->Throttle;
Ogre::Vector3 dir=proj+Normal/2;
dir.normalise();
object->Object->SetForces(Ogre::Vector3::ZERO);
object->VelocityVector = dir*(linvel.length()+1);
object->LinVelocity = dir*(linvel.length()+1);
object->Object->SetReplacingDirection(dir*(linvel.length()+1));
object->Object->AddForce(IntersectionPoint, dir*(linvel.length()+1)*Owner->GetMass()/object->Object->GetMass());
}
示例13: mouseMoved
bool CCameraController::mouseMoved( const OIS::MouseEvent &arg )
{
Ogre::Vector3 vtPlayerPos = m_pBindObject->GetPosition();
if( arg.state.buttonDown( OIS::MB_Right ) )
{
Rotate(arg.state.X.rel, arg.state.Y.rel);
Ogre::Vector3 vtCamera = m_pCamera->getPosition();
Ogre::Vector3 vtDir = vtCamera-vtPlayerPos;
vtDir.normalise();
vtDir.y = 0;
m_pBindObject->SetDirection(vtDir);
}
if( arg.state.buttonDown( OIS::MB_Left ) )
{
Rotate(arg.state.X.rel, arg.state.Y.rel);
}
return true;
}
示例14: Rotate
VOID CCameraController::Rotate( float x, float y )
{
float angle = -x * 0.01f;
float xt = m_vecUnitDir.x * cos(angle) + m_vecUnitDir.z * sin(angle);
float zt = m_vecUnitDir.z * cos(angle) - m_vecUnitDir.x * sin(angle);
m_vecUnitDir.x = xt;
m_vecUnitDir.z = zt;
//¼ÆËãXZÐýתÖá
Ogre::Vector3 axis;
axis.x = -m_vecUnitDir.z;
axis.z = m_vecUnitDir.x;
axis.y = 0;
axis.normalise();
//ÑØÖáÐýת
{
float angle = y * 0.01f;
float x =
m_vecUnitDir.x * (axis.x * axis.x * (1 - cos(angle)) + cos(angle)) +
m_vecUnitDir.y * (axis.x * axis.y * (1 - cos(angle)) - axis.z * sin(angle)) +
m_vecUnitDir.z * (axis.x * axis.z * (1 - cos(angle)) + axis.y * sin(angle));
float y =
m_vecUnitDir.x * (axis.x * axis.y * (1 - cos(angle)) + axis.z * sin(angle)) +
m_vecUnitDir.y * (axis.y * axis.y * (1 - cos(angle)) + cos(angle)) +
m_vecUnitDir.z * (axis.y * axis.z * (1 - cos(angle)) - axis.x * sin(angle));
float z =
m_vecUnitDir.x * (axis.x * axis.z * (1 - cos(angle)) - axis.y * sin(angle)) +
m_vecUnitDir.y * (axis.y * axis.z * (1 - cos(angle)) + axis.x * sin(angle)) +
m_vecUnitDir.z * (axis.z * axis.z * (1 - cos(angle)) + cos(angle));
m_vecUnitDir.x = x;
m_vecUnitDir.y = y;
m_vecUnitDir.z = z;
}
m_bPositionUpate = TRUE;
}
示例15: isCameraInsideLight
bool DeferredLight::isCameraInsideLight(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());
return distanceFromLight <= mRadius + camera->getNearClipDistance() + 0.1;
}
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 = 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() + clipRangeFix.length()))
&& (angle <= attAngle);
}
default:
//Please the compiler
return false;
}
}