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


C++ Quaternion::FromAngleAxis方法代码示例

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


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

示例1: Enter

void AlliedGetCloseState::Enter(Agent * agent)
{
	//assumes that 0 is player, allies start with 1 and so on, also max 3 allies
	Vector3 dest = WORLD->getPlayerAgent()->GetPosition();
	int ally_id = agent->getID();
	if (ally_id == 1)
	{
		Quaternion q;
		q.FromAngleAxis(Radian(Math::PI / 2), Vector3::UNIT_Y);
		dest += WORLD->getPlayerAgent()->GetDirection() * q * Vector3::UNIT_Z * AIConsts::PlayerCloseDistance;
	}
	else if (ally_id == 2)
	{
		Quaternion q;
		q.FromAngleAxis(Radian(Math::PI / 2), Vector3::UNIT_Y);
		dest += WORLD->getPlayerAgent()->GetDirection() * q * Vector3::NEGATIVE_UNIT_Z * AIConsts::PlayerCloseDistance;
	}
	else if (ally_id == 3)
	{
		Quaternion q;
		q.FromAngleAxis(Radian(Math::PI / 1), Vector3::UNIT_Y);
		dest += WORLD->getPlayerAgent()->GetDirection() * q * Vector3::UNIT_Z * AIConsts::PlayerCloseDistance;
	}

	agent->orderGoTo(dest);
}
开发者ID:drwbns,项目名称:tpnew---latest-ogre_v2-1,代码行数:26,代码来源:AlliedGetCloseState.cpp

示例2: Radian

	Vector3 Vector3::RandomDeviant(
        Radian angle,
        Vector3 up )
    {
        Vector3 newUp;

        if (up == Vector3::ZERO)
        {
            // Generate an up vector
            newUp = this->Perpendicular;
        }
        else
        {
            newUp = up;
        }

        // Rotate up vector by random amount around this
        Quaternion q;
        q.FromAngleAxis( Radian(Math::UnitRandom() * Math::TWO_PI), *this );
        newUp = q * newUp;

        // Finally rotate this by given angle around randomised up
        q.FromAngleAxis( angle, newUp );
        return q * (*this);
    }
开发者ID:RoboticOxygen,项目名称:extramegablob,代码行数:25,代码来源:MogreVector3.cpp

示例3:

	Quaternion Vector3::GetRotationTo(Vector3 dest, Vector3 fallbackAxis)
    {
        // Based on Stan Melax's article in Game Programming Gems
        Quaternion q;
        // Copy, since cannot modify local
        Vector3 v0 = *this;
        Vector3 v1 = dest;
        v0.Normalise();
        v1.Normalise();

        Real d = v0.DotProduct(v1);
        // If dot == 1, vectors are the same
        if (d >= 1.0f)
        {
            return Quaternion::IDENTITY;
        }
		
		// sometimes the dot product yields -1.0000001
		// floating point math does that to you
		if (d < -1.0f)
			d = -1.0f;

        Real s = Math::Sqrt( (1+d)*2 );
		if (s < 1e-6f)
		{
			if (fallbackAxis != Vector3::ZERO)
			{
				// rotate 180 degrees about the fallback axis
				q.FromAngleAxis(Radian(Math::PI), fallbackAxis);
			}
			else
			{
				// Generate an axis
				Vector3 axis = Vector3::UNIT_X.CrossProduct(*this);
				if (axis.IsZeroLength) // pick another if colinear
					axis = Vector3::UNIT_Y.CrossProduct(*this);
				axis.Normalise();
				q.FromAngleAxis(Radian(Math::PI), axis);
			}
		}
		else
		{
            Real invs = 1 / s;

			Vector3 c = v0.CrossProduct(v1);

	        q.x = c.x * invs;
    	    q.y = c.y * invs;
        	q.z = c.z * invs;
        	q.w = s * 0.5;
			q.Normalise();
		}
        return q;
    }
开发者ID:RoboticOxygen,项目名称:extramegablob,代码行数:54,代码来源:MogreVector3.cpp

示例4: getXMLRotation

//-------------------------------------------------------------------------------------
Quaternion SceneLoader::getXMLRotation(rapidxml::xml_node<>* node)
{
  Quaternion rotation = Quaternion::IDENTITY;
  Vector3 components = getXMLVector(node, ROTATION_X_STRING, ROTATION_Y_STRING, ROTATION_Z_STRING);

  rotation.FromAngleAxis(Ogre::Degree(components.x), Vector3::UNIT_X);
  rotation.FromAngleAxis(Ogre::Degree(components.y), Vector3::UNIT_Y);
  rotation.FromAngleAxis(Ogre::Degree(components.z), Vector3::UNIT_Z);

  return rotation;
}
开发者ID:arrian,项目名称:3d-engine,代码行数:12,代码来源:SceneLoader.cpp

示例5: getOrientation

Ogre::Quaternion CameraManager::getOrientation()
{
	Quaternion ident;
	Radian angle;
	Vector3 vector;
	mPitchNode->getOrientation().ToAngleAxis(angle,vector);
	ident.FromAngleAxis(-angle,vector);
	Quaternion tmp;
	mYawNode->getOrientation().ToAngleAxis(angle,vector);
	tmp.FromAngleAxis(-angle,vector);
	ident = ident * tmp;

	return ident;
}
开发者ID:BGCX261,项目名称:zju-computer-game-svn-to-git,代码行数:14,代码来源:CameraManager.cpp

示例6:

	ParaEngine::Quaternion Vector3::getRotationTo(const Vector3& dest, const Vector3& fallbackAxis /*= Vector3::ZERO*/) const
	{
		// Based on Stan Melax's article in Game Programming Gems
		Quaternion q;
		// Copy, since cannot modify local
		Vector3 v0 = *this;
		Vector3 v1 = dest;
		v0.normalise();
		v1.normalise();

		float d = v0.dotProduct(v1);
		// If dot == 1, vectors are the same
		if (d >= 1.0f)
		{
			return Quaternion::IDENTITY;
		}
		if (d < (1e-6f - 1.0f))
		{
			if (fallbackAxis != Vector3::ZERO)
			{
				// rotate 180 degrees about the fallback axis
				q.FromAngleAxis(Radian(Math::PI), fallbackAxis);
			}
			else
			{
				// Generate an axis
				Vector3 axis = Vector3::UNIT_X.crossProduct(*this);
				if (axis.isZeroLength()) // pick another if colinear
					axis = Vector3::UNIT_Y.crossProduct(*this);
				axis.normalise();
				q.FromAngleAxis(Radian(Math::PI), axis);
			}
		}
		else
		{
			float s = Math::Sqrt((1 + d) * 2);
			float invs = 1 / s;

			Vector3 c = v0.crossProduct(v1);

			q.x = c.x * invs;
			q.y = c.y * invs;
			q.z = c.z * invs;
			q.w = s * 0.5f;
			q.normalise();
		}
		return q;
	}
开发者ID:LiXizhi,项目名称:NPLRuntime,代码行数:48,代码来源:ParaVector3.cpp

示例7: SetDirection

void TransformationComponent::SetDirection( Vec3& i_oDirection )
{
	if (i_oDirection == Vec3::ZERO)		
		return;

	i_oDirection.normalise();

	Vec3 oXAxe;
	Vec3 oYAxe;
	Vec3 oZAxe;

	m_oOrientation.ToAxes(oXAxe, oYAxe, oZAxe);

	Quaternion rotQuat;
	if ( (oZAxe + i_oDirection).squaredLength() <  0.0f) 
	{
		// Oops, a 180 degree turn (infinite possible rotation axes)
		// Default to yaw i.e. use current UP
		rotQuat.FromAngleAxis(Ogre::Radian(Ogre::Math::PI), oYAxe);
	}
	else
	{
		// Derive shortest arc to new direction
		rotQuat = oZAxe.getRotationTo(i_oDirection);
	}

	m_oOrientation = rotQuat * m_oOrientation;
}
开发者ID:Mr3lw00d,项目名称:MGD_GAMEPLAY__MDG14,代码行数:28,代码来源:TransformationComponent.cpp

示例8: RotateSel

//  Rotate selected
void SplineRoad::RotateSel(Real relA, Vector3 axis, int addYawRoll)
{
	if (vSel.empty())  return;
	Vector3 pos0 = getPos0();
	
	Quaternion q;  q.FromAngleAxis(Degree(relA), axis);
	Matrix3 m;  q.ToRotationMatrix(m);
	
	//  rotate 2d yaw around center
	for (std::set<int>::const_iterator it = vSel.begin(); it != vSel.end(); ++it)
	{
		Vector3 pos = getPos(*it) - pos0;
		Vector3 npos = pos * m + pos0;

		pos = npos;
		if (mP[*it].onTer)
			pos.y = (mTerrain ? mTerrain->getHeightAtWorldPosition(pos.x, 0, pos.z) : 0.f) + fHeight;
		setPos(*it, pos);
		
		if (addYawRoll==1)  // todo: get from axis?
			mP[*it].mYaw -= relA;  // rot point yaw
		else if (addYawRoll==2)
			// todo: * mul by cos of yaw ?..
			mP[*it].mRoll -= relA;  // rot point roll
		
		vMarkNodes[*it]->setPosition(pos);
		//Move1(*it, npos);
	}
	bSelChng = true;
}
开发者ID:HaohaoLau,项目名称:stuntrally,代码行数:31,代码来源:Road_Edit.cpp

示例9: keyPressed

bool pathDrawerState::keyPressed(const OIS::KeyEvent& e)
{
    if (e.key == OIS::KC_ESCAPE)
        _exitGame = true;
        
    if (e.key == OIS::KC_F2)
        guardarRuta();
        
    if (e.key == OIS::KC_F4)
        cargarRutaCheckPoint("rutasIA.xml");
        //cargarRuta("rutasIA.xml");
        
    if (e.key == OIS::KC_F9)
        borrarTodasLasMarcas();
        
    if (e.key == OIS::KC_U &&
        _nodoSelector && 
        _nodoSelector->getName().substr(0,_nodoSelector->getName().find("_")-1) != _checkPointInfo.nombreNodo)
    {
        Quaternion q = Quaternion::IDENTITY;
        q.FromAngleAxis(Ogre::Degree(-90),Vector3::UNIT_Y);
        _nodoSelector->setOrientation(q);
    }
        
    
    return true;
}
开发者ID:jalcolea,项目名称:cars,代码行数:27,代码来源:pathDrawerState.cpp

示例10: parseQuaternion

Quaternion DotSceneLoader::parseQuaternion(TiXmlElement *XMLNode)
{
    //! @todo Fix this crap!
 
    Quaternion orientation;
 
    if(XMLNode->Attribute("qx"))
    {
        orientation.x = StringConverter::parseReal(XMLNode->Attribute("qx"));
        orientation.y = StringConverter::parseReal(XMLNode->Attribute("qy"));
        orientation.z = StringConverter::parseReal(XMLNode->Attribute("qz"));
        orientation.w = StringConverter::parseReal(XMLNode->Attribute("qw"));
    }
    else if(XMLNode->Attribute("axisX"))
    {
        Vector3 axis;
        axis.x = StringConverter::parseReal(XMLNode->Attribute("axisX"));
        axis.y = StringConverter::parseReal(XMLNode->Attribute("axisY"));
        axis.z = StringConverter::parseReal(XMLNode->Attribute("axisZ"));
        Real angle = StringConverter::parseReal(XMLNode->Attribute("angle"));;
        orientation.FromAngleAxis(Ogre::Angle(angle), axis);
    }
    else if(XMLNode->Attribute("angleX"))
    {
        Vector3 axis;
        axis.x = StringConverter::parseReal(XMLNode->Attribute("angleX"));
        axis.y = StringConverter::parseReal(XMLNode->Attribute("angleY"));
        axis.z = StringConverter::parseReal(XMLNode->Attribute("angleZ"));
        //orientation.FromAxes(&axis);
        //orientation.F
    }
 
    return orientation;
}
开发者ID:SuperMagicBadger,项目名称:Zombiess,代码行数:34,代码来源:DotSceneLoader.cpp

示例11: rotate

void Transforms::rotate(const Vector3& axis, const Radian& angle,
                        tTransformSpace relativeTo)
{
    Quaternion q;
    q.FromAngleAxis(angle,axis);
    rotate(q, relativeTo);
}
开发者ID:Kanma,项目名称:Athena-Entities,代码行数:7,代码来源:Transforms.cpp

示例12: _latheBodyImpl

//-----------------------------------------------------------------------
void Lathe::_latheBodyImpl(TriangleBuffer& buffer, const Shape* shapeToExtrude) const
{
	int numSegShape = shapeToExtrude->getSegCount();
	assert(numSegShape>1 && "Shape must contain at least two points");
	int offset =0;

	//int numSeg = mClosed?mNumSeg+1:mNumSeg;
	int numSeg = mNumSeg+1;
	buffer.rebaseOffset();
	buffer.estimateIndexCount(numSeg*numSegShape*6);
	buffer.estimateVertexCount((numSegShape+1)*(numSeg+1));
	
	Radian angleEnd(mAngleEnd);
	if (mAngleBegin>mAngleEnd)
		angleEnd+=(Radian)Math::TWO_PI;

	for (int i=0;i<numSeg;i++)
	{
		Radian angle;
		if (mClosed)
			angle = i/(Real)mNumSeg*Math::TWO_PI;
		else
			angle = mAngleBegin + i/(Real)mNumSeg*(angleEnd-mAngleBegin);
		Quaternion q;
		q.FromAngleAxis(angle,Vector3::UNIT_Y);

		for (int j=0;j<=numSegShape;j++)
		{
			const Vector2& v0 = shapeToExtrude->getPoint(j);
			Vector3 vp(v0.x,v0.y,0);
			const Vector2& vp2direction = shapeToExtrude->getAvgDirection(j);
			Vector2 vp2normal = vp2direction.perpendicular();
			Vector3 normal(vp2normal.x, vp2normal.y, 0);
			normal.normalise();
			if (shapeToExtrude->getOutSide() == SIDE_RIGHT)
				normal = -normal;

			addPoint(buffer, q*vp,
							 q*normal,
							 Vector2(i/(Real)mNumSeg, j/(Real)numSegShape));

			if (j <numSegShape && i <numSeg-1)
			{
				if (shapeToExtrude->getOutSide() == SIDE_RIGHT)
				{
					buffer.triangle(offset + numSegShape + 2, offset, offset + numSegShape + 1);
					buffer.triangle(offset + numSegShape + 2, offset + 1, offset);
				}
				else
				{
					buffer.triangle(offset + numSegShape + 2, offset + numSegShape + 1, offset);
					buffer.triangle(offset + numSegShape + 2, offset, offset + 1);
				}
			}
			offset ++;
		}
	}
}
开发者ID:DavidEichmann,项目名称:ode,代码行数:59,代码来源:ProceduralLathe.cpp

示例13: Enter

void AlliedLookAroundState::Enter(Agent * agent)
{
	Quaternion mq = agent->GetRotation();
	float some = Math::fDeg2Rad * Math::RangeRandom(-90, 90);
	Quaternion aq; aq.FromAngleAxis(Radian(some), Vector3::UNIT_Y);
	agent->SetDirection(mq * aq);
	//exit immidiately
	agent->setWaitTime(0);
}
开发者ID:drwbns,项目名称:tpnew---latest-ogre_v2-1,代码行数:9,代码来源:AlliedLookAroundState.cpp

示例14: setWorldGeometry

    //-----------------------------------------------------------------------
    void BspSceneManager::setWorldGeometry(const String& filename)
    {
        mLevel.setNull();
        // Check extension is .bsp
        char extension[6];
        size_t pos = filename.find_last_of(".");
		if( pos == String::npos )
            OGRE_EXCEPT(
				Exception::ERR_INVALIDPARAMS,
                "Unable to load world geometry. Invalid extension (must be .bsp).",
                "BspSceneManager::setWorldGeometry");

        strncpy(extension, filename.substr(pos + 1, filename.length() - pos).c_str(), 5);
		extension[5] = 0;

        if (stricmp(extension, "bsp"))
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
			"Unable to load world geometry. Invalid extension (must be .bsp).",
            "BspSceneManager::setWorldGeometry");

        // Load using resource manager
        mLevel = BspResourceManager::getSingleton().load(filename, 
            ResourceGroupManager::getSingleton().getWorldResourceGroupName());

		if (mLevel->isSkyEnabled())
		{
			// Quake3 is always aligned with Z upwards
			Quaternion q;
			q.FromAngleAxis(Radian(Math::HALF_PI), Vector3::UNIT_X);
			// Also draw last, and make close to camera (far clip plane is shorter)
			setSkyDome(true, mLevel->getSkyMaterialName(),
				mLevel->getSkyCurvature(), 12, 2000, false, q);
		}
		else
		{
			setSkyDome(false, StringUtil::BLANK);
		}

        // Init static render operation
        mRenderOp.vertexData = mLevel->mVertexData;
        // index data is per-frame
        mRenderOp.indexData = OGRE_NEW IndexData();
        mRenderOp.indexData->indexStart = 0;
        mRenderOp.indexData->indexCount = 0;
        // Create enough index space to render whole level
        mRenderOp.indexData->indexBuffer = HardwareBufferManager::getSingleton()
            .createIndexBuffer(
                HardwareIndexBuffer::IT_32BIT, // always 32-bit
                mLevel->mNumIndexes, 
                HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false);

        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
        mRenderOp.useIndexes = true;


    }
开发者ID:airgames,项目名称:vuforia-gamekit-integration,代码行数:57,代码来源:OgreBspSceneManager.cpp

示例15:

Agent * EnemyPatrolIdlingState::Enter(Agent* agent)
{
	agent->setWaitTime(0);
	//turn around randomly
	Quaternion mq = agent->GetRotation();
	float some = Math::fDeg2Rad * Math::RangeRandom(-90, 90);
	Quaternion aq; aq.FromAngleAxis(Radian(some), Vector3::UNIT_Y);
	agent->SetDirection(mq * aq);
	return nullptr;
}
开发者ID:drwbns,项目名称:1stperson,代码行数:10,代码来源:EnemyPatrolIdlingState.cpp


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