本文整理汇总了C++中ogre::Quaternion类的典型用法代码示例。如果您正苦于以下问题:C++ Quaternion类的具体用法?C++ Quaternion怎么用?C++ Quaternion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Quaternion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: createMapObj
int Terrain::createMapObj(int x, int y, std::string meshname, int dir)
{
stTileEntityData* entitydata = new stTileEntityData;
entitydata->mTileEntity = Core::getSingleton().mSceneMgr->createEntity(meshname);
entitydata->mTileNode = mTerrainNode->createChildSceneNode();
entitydata->mTileNode->attachObject(entitydata->mTileEntity);
float xx,yy;
getWorldCoords(x,y,xx,yy);
entitydata->mTileNode->setPosition(xx ,getHeight(xx,yy),yy);
Ogre::Quaternion q;
switch(dir)
{
case North:
q.FromAngleAxis(Ogre::Degree(180),Ogre::Vector3(0,1,0));
break;
case South:
q.FromAngleAxis(Ogre::Degree(360),Ogre::Vector3(0,1,0));
break;
case West:
q.FromAngleAxis(Ogre::Degree(270),Ogre::Vector3(0,1,0));
break;
case East:
q.FromAngleAxis(Ogre::Degree(90),Ogre::Vector3(0,1,0));
break;
}
entitydata->mTileNode->setOrientation(q);
mObjId ++;
mMapObjMap.insert(std::map<int, stTileEntityData*>::value_type(mObjId,entitydata ));
return mObjId;
}
示例3: SetupAnimation
void OgreApplication::SetupAnimation(Ogre::String object_name){
/* Retrieve scene manager and root scene node */
Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();
/* Set up animation */
Ogre::Real duration = Ogre::Math::TWO_PI;
Ogre::Real num_steps = 36;
Ogre::Real step = duration/num_steps;
Ogre::Animation* animation = scene_manager->createAnimation("Animation", duration);
animation->setInterpolationMode(Ogre::Animation::IM_LINEAR);
Ogre::Node *object_scene_node = root_scene_node->getChild(object_name);
Ogre::NodeAnimationTrack* track = animation->createNodeTrack(0, object_scene_node);
/* Set up frames for animation */
Ogre::TransformKeyFrame* key;
Ogre::Quaternion quat;
for (int i = 0; i < num_steps; i++){
Ogre::Real current = ((float) i) * step;
key = track->createNodeKeyFrame(current);
quat.FromAngleAxis(Ogre::Radian(-current), Ogre::Vector3(0, 1, 0));
key->setRotation(quat);
key->setScale(Ogre::Vector3(0.5, 0.5, 0.5));
}
/* Create animation state */
animation_state_ = scene_manager->createAnimationState("Animation");
animation_state_->setEnabled(true);
animation_state_->setLoop(true);
/* Turn on animating flag */
animating_ = true;
}
示例4: setPositionOrientation
void PhysicsRagDoll::setPositionOrientation(const Ogre::Vector3& pos, const Ogre::Quaternion &orient)
{
Ogre::Vector3 oldPos = mNode->_getDerivedPosition();
Ogre::Quaternion oldOri = mNode->_getDerivedOrientation();
Ogre::Quaternion oldOriInv = oldOri.Inverse();
for (RagBoneMapIterator it = mRagBonesMap.begin(); it != mRagBonesMap.end(); it++)
{
OgreNewt::Body* body = it->second->getBody();
if (body)
{
Ogre::Vector3 boneOldPos;
Ogre::Quaternion boneOldOri;
body->getPositionOrientation(boneOldPos, boneOldOri);
// get old position and orientation in local space
Ogre::Vector3 boneOldLocalPos = oldOriInv*(boneOldPos - oldPos);
Ogre::Quaternion boneOldLocalOri = oldOriInv*boneOldOri;
// calculate and set new position in orientation
body->setPositionOrientation(pos + orient*boneOldLocalPos, orient*boneOldLocalOri);
body->unFreeze();
}
}
mNode->setPosition(pos);
mNode->setOrientation(orient);
}
示例5: setPropertiesFromCamera
void FPSViewController::setPropertiesFromCamera( Ogre::Camera* source_camera )
{
Ogre::Quaternion quat = source_camera->getOrientation() * ROBOT_TO_CAMERA_ROTATION.Inverse();
float yaw = quat.getRoll( false ).valueRadians(); // OGRE camera frame looks along -Z, so they call rotation around Z "roll".
float pitch = quat.getYaw( false ).valueRadians(); // OGRE camera frame has +Y as "up", so they call rotation around Y "yaw".
Ogre::Vector3 direction = quat * Ogre::Vector3::NEGATIVE_UNIT_Z;
if ( direction.dotProduct( Ogre::Vector3::NEGATIVE_UNIT_Z ) < 0 )
{
if ( pitch > Ogre::Math::HALF_PI )
{
pitch -= Ogre::Math::PI;
}
else if ( pitch < -Ogre::Math::HALF_PI )
{
pitch += Ogre::Math::PI;
}
yaw = -yaw;
if ( direction.dotProduct( Ogre::Vector3::UNIT_X ) < 0 )
{
yaw -= Ogre::Math::PI;
}
else
{
yaw += Ogre::Math::PI;
}
}
pitch_property_->setFloat( pitch );
yaw_property_->setFloat( mapAngleTo0_2Pi( yaw ));
position_property_->setVector( source_camera->getPosition() );
}
示例6: initAxis
//-------------------------------------------------------------------------------------
void AxisLines::initAxis(Ogre::String boneName, Ogre::Entity* entity, Ogre::SceneManager* mSceneManager)
{
if(isXVisible) /* red */
{
xLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
entity->attachObjectToBone(boneName, xLine);
xLine->setMaterial(color1);
}
if(isYVisible) /* green */
{
yLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
entity->attachObjectToBone(boneName, yLine);
yLine->setMaterial(color2);
}
if(isZVisible) /* blue */
{
zLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
entity->attachObjectToBone(boneName, zLine);
zLine->setMaterial(color3);
}
Ogre::Bone* bone = entity->getSkeleton()->getBone(boneName);
Ogre::Quaternion q = bone->getOrientation();
this->updateLines(q.xAxis(), q.yAxis(), q.zAxis());
}
示例7: setDirection
//-----------------------------------------------------------------------------------------
void CCameraEditor::setDirection(const Ogre::Vector3 &vec)
{
if (vec == Ogre::Vector3::ZERO) return;
Ogre::Vector3 zAdjustVec = -vec;
zAdjustVec.normalise();
Ogre::Quaternion orientation;
Ogre::Vector3 YawFixedAxis = Ogre::Vector3::UNIT_Y;
Ogre::Vector3 xVec = YawFixedAxis.crossProduct( zAdjustVec );
xVec.normalise();
Ogre::Vector3 yVec = zAdjustVec.crossProduct( xVec );
yVec.normalise();
orientation.FromAxes( xVec, yVec, zAdjustVec );
// transform to parent space
if (mParentEditor->get())
{
orientation = mParentEditor->get()->getNode()->_getDerivedOrientation().Inverse() * orientation;
}
mOrientation->set(orientation);
}
示例8: 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;
}
示例9: frameRenderingQueued
bool Framework::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
mTrayMgr->frameRenderingQueued(evt);
if (!mTrayMgr->isDialogVisible())
{
mCameraMan->frameRenderingQueued(evt); // if dialog isn't up, then update the camera
if (mDetailsPanel->isVisible()) // if details panel is visible, then update its contents
{
mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));
mDetailsPanel->setParamValue(1, Ogre::StringConverter::toString(mCamera->getDerivedPosition().y));
mDetailsPanel->setParamValue(2, Ogre::StringConverter::toString(mCamera->getDerivedPosition().z));
mDetailsPanel->setParamValue(4, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().w));
mDetailsPanel->setParamValue(5, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().x));
mDetailsPanel->setParamValue(6, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().y));
mDetailsPanel->setParamValue(7, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().z));
#ifdef USE_RTSHADER_SYSTEM
mDetailsPanel->setParamValue(14, Ogre::StringConverter::toString(mShaderGenerator->getVertexShaderCount()));
mDetailsPanel->setParamValue(15, Ogre::StringConverter::toString(mShaderGenerator->getFragmentShaderCount()));
#endif
Ogre::Quaternion q = mCamera->getDerivedOrientation();
mDetailsPanel->setParamValue(16, Ogre::StringConverter::toString(q.xAxis() ) );
mDetailsPanel->setParamValue(17, Ogre::StringConverter::toString(q.yAxis() ));
mDetailsPanel->setParamValue(18, Ogre::StringConverter::toString(q.zAxis() ));
}
}
return true;
}
示例10: parseQuaternion
Ogre::Quaternion Util::parseQuaternion(TiXmlElement *XMLNode)
{
Ogre::Quaternion orientation;
if(XMLNode->Attribute("qx"))
{
orientation.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("qx"));
orientation.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("qy"));
orientation.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("qz"));
orientation.w = Ogre::StringConverter::parseReal(XMLNode->Attribute("qw"));
}
else if(XMLNode->Attribute("axisX"))
{
Ogre::Vector3 axis;
axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisX"));
axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisY"));
axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisZ"));
Ogre::Real angle = Ogre::StringConverter::parseReal(XMLNode->Attribute("angle"));;
orientation.FromAngleAxis(Ogre::Angle(angle), axis);
}
else if(XMLNode->Attribute("angleX"))
{
Ogre::Vector3 axis;
axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleX"));
axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleY"));
axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleZ"));
//orientation.FromAxes(&axis);
//orientation.F
}
return orientation;
}
示例11: ProcessKeyInput
void AACamera::ProcessKeyInput(OIS::Keyboard *mKeyboard)
{
static unsigned RollSpeed = 5;
if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
{
if (abs(RelativeOrientation.getRoll().valueDegrees())<10)
{
Ogre::Quaternion q;
q.FromAngleAxis(-Ogre::Degree(RollSpeed),Ogre::Vector3::UNIT_Z);
CameraAdditionalRotation.StartRotation(RelativeOrientation, RelativeOrientation*q, CommonDeclarations::GetFPS());
}
}
else
if(mKeyboard->isKeyDown(OIS::KC_LEFT))
{
if (abs(RelativeOrientation.getRoll().valueDegrees())<10)
{
Ogre::Quaternion q;
q.FromAngleAxis(Ogre::Degree(RollSpeed),Ogre::Vector3::UNIT_Z);
CameraAdditionalRotation.StartRotation(RelativeOrientation, RelativeOrientation*q, CommonDeclarations::GetFPS());
}
}
else
{
if (RelativeOrientation!=Ogre::Quaternion::IDENTITY)
{
Ogre::Quaternion q = Ogre::Quaternion::IDENTITY;
CameraAdditionalRotation.StartRotation(RelativeOrientation, q, CommonDeclarations::GetFPS());
}
}
}
示例12: updateWheel
void OgreWheel::updateWheel(const float angle)
{
// Render change angle
Ogre::Quaternion qq;
qq.FromAngleAxis(Ogre::Radian(-angle)*5, Ogre::Vector3(0, 1, 0));
mNode->setOrientation(qq);
}
示例13: generateEnvironment
void GameState::generateEnvironment()
{
Ogre::StaticGeometry *sg = mSceneMgr->createStaticGeometry("Asteroids");
const int size = 7000;
const int amount = 5;
sg->setRegionDimensions(Ogre::Vector3(size, size, size));
//sg->setOrigin(Ogre::Vector3(-size/2, 0, -size/2));
sg->setOrigin(Vector3(-size/2, -size/2, -size/2) + Vector3(0, 0, 0)); // this will center the staticgeometry around the point in 3D space
for (int x = -size/2; x < size/2; x += (size/amount))
{
for (int y = -size/2; y < size/2; y += (size/amount))
{
for (int z = -size/2; z < size/2; z += (size/amount))
{
Ogre::Real r = size / (float)amount / 2;
Ogre::Vector3 pos(x + Ogre::Math::RangeRandom(-r, r), y + Ogre::Math::RangeRandom(-r, r), z + Ogre::Math::RangeRandom(-r, r));
Ogre::Vector3 scale(Ogre::Math::RangeRandom(0.7, 20), Ogre::Math::RangeRandom(0.7, 20), Ogre::Math::RangeRandom(0.7, 20));
Ogre::Quaternion orientation;
orientation.FromAngleAxis(Ogre::Degree(Ogre::Math::RangeRandom(0, 359)), Ogre::Vector3::UNIT_Y);
MyEntity * ent = new MyEntity("asteroid1.mesh", mSceneMgr, mWorld, pos);
ent->transform(orientation, Ogre::Vector3::ZERO);
//ent->setScale(scale);
sg->addEntity(ent->getEntity(), pos, orientation/*, scale*/);
}
}
}
sg->build();
}
示例14: setRotation
void SceneEntity::setRotation(float angel)
{
mRotateAngel = angel;
Ogre::Quaternion ori;
ori.FromAngleAxis(Ogre::Radian(Ogre::Math::PI/180*mRotateAngel),Ogre::Vector3(0,1,0));
mSceneNode->setOrientation(ori);
}
示例15: setLocalRotation
void OgrePointSpecification::setLocalRotation(const VEHA::RotationVector& orientation)
{
Ogre::Quaternion q;
Ogre::Vector3 v(orientation.x,orientation.y,orientation.z);
q.FromAngleAxis(Ogre::Radian(orientation.angle),v);
_node->setOrientation(q);
_node->_update(true,true);
}