Esempio n. 1
0
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);
	}
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
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);
}
Esempio n. 5
0
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() );
}
Esempio n. 6
0
//-------------------------------------------------------------------------------------
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());
}
Esempio n. 7
0
//-----------------------------------------------------------------------------------------
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);
}
Esempio n. 8
0
//-------------------------------------------------------------------------------
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;
}
Esempio n. 9
0
	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;
	}
Esempio n. 10
0
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;
}
Esempio n. 11
0
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());				
            }
        }
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
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();

	

}
Esempio n. 14
0
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);
}
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);
}
Esempio n. 16
0
btMatrix3x3 Utility::convert_OgreMatrix3(const Ogre::Matrix3 &m)
{
	btMatrix3x3 mat;
	Ogre::Quaternion quat;
	quat.FromRotationMatrix(m);
	mat.setRotation(Utility::convert_OgreQuaternion(quat));
	return mat;
}
Esempio n. 17
0
void Vehicle::jet(NxReal stiff)
{
	Ogre::Quaternion quat = UtilityFunc::NxQuat_ToOgre_Quat(mActor->getGlobalOrientationQuat());
	NxVec3 nxv3			  = UtilityFunc::OgreVec3_To_NxVec3(quat.zAxis());

	nxv3.normalize();
	mActor->addForce(nxv3 * stiff, NX_IMPULSE);
}
Esempio n. 18
0
//-----------------------------------------------------------------------------------------
void CCameraEditor::yaw(const Ogre::Radian &value)
{
    Ogre::Quaternion q;

    q.FromAngleAxis(value, Ogre::Vector3::UNIT_Y);
    q.normalise();
    
    mOrientation->set(q * mOrientation->get());
}
Esempio n. 19
0
//-----------------------------------------------------------------------------------------
void CCameraEditor::roll(const Ogre::Radian &value)
{
    Ogre::Quaternion q;
    Ogre::Vector3 axis = mOrientation->get() * Ogre::Vector3::UNIT_Z;
    q.FromAngleAxis(value, axis);
    q.normalise();
    
    mOrientation->set(q * mOrientation->get());
}
void AppFrameListener::moveInGameCamera()
{
	//mCamNode->setPosition(Ogre::Vector3(100,200,100));
	////mCamNode->setOrientation(planeOri);
	//mCamNode->lookAt(Ogre::Vector3::ZERO, Ogre::Node::TS_WORLD, Ogre::Vector3::UNIT_Z);

	//return;


	Ogre::Vector3 planePos, planeDir, planeOmega;
	Ogre::Quaternion planeOri;

	mAirplane->getPositionOrientation(planePos,	planeOri);	
	mAirplane->getOmega(planeOmega);

	planeOmega = planeOri.Inverse() * planeOmega;	

	mCamNode->setPosition(planePos);
	mCamNode->setOrientation(planeOri);
	
	
	if( Ogre::Math::Abs(planeOmega.x) - Ogre::Math::Abs(mLastPlaneOmegaX) < 60*mTimeSinceLastFrame)
		mLastPlaneOmegaX = planeOmega.x;
	if( Ogre::Math::Abs(planeOmega.z) - Ogre::Math::Abs(mLastPlaneOmegaZ) < 60*mTimeSinceLastFrame)
		mLastPlaneOmegaZ = planeOmega.z;
	//if( planeVel.z > 0 && planeVel.z - mLastPlaneSpeed < 1)
	//	mLastPlaneSpeed = planeVel.z;

	
	
	if(mCamPosition != 0 || mCamLookBack)
	{
		mCamNode->pitch( Ogre::Radian(mLastPlaneOmegaX)*-0.1 );
		mCamNode->roll( Ogre::Radian(mLastPlaneOmegaZ)*-0.1);
	}
	if(mCamLookBack)
	{
		mCamNode->yaw(Ogre::Degree(180));
		//mCamNode->translate(Ogre::Vector3(0,5,-20), Ogre::Node::TS_LOCAL);
	}
	
	mCamNode->translate(mCamTranslation, Ogre::Node::TS_LOCAL);			


	//Launch a ray from airplane in it's direction, to get the first hit in order 
	//to find the correct position for the crosshair
	Ogre::Vector3 closestPos;
	Ogre::Matrix4 camMatrix;			
	bool enemyHit = false;
	enemyHit = mAirplane->getTargetHitPoint(closestPos);
	camMatrix = mCamera->getProjectionMatrix() * mCamera->getViewMatrix(true);			
	mHUDManager->setCrosshairVScroll((camMatrix*closestPos).y, enemyHit);	

	

}
Esempio n. 21
0
		bool frameEnded(const Ogre::FrameEvent &evt)
		{
			Ogre::Quaternion q;
			q.FromAngleAxis(Ogre::Degree(360 * ((float) timer.getMilliseconds()) / 5000), Ogre::Vector3(0, 1, 0));
			for (auto node = nodes.begin(); node != nodes.end(); node++)
			{
				(*node)->setOrientation(q);
			}
			return true;
		}
void OgrePointSpecification::setGlobalRotation(const VEHA::RotationVector& orientation)
{
	Ogre::Quaternion q;
	Ogre::Vector3 v(orientation.x,orientation.y,orientation.z);
	q.FromAngleAxis(Ogre::Radian(orientation.angle),v);
	if(getParent())
		q=shared_dynamic_cast<OgrePointSpecification>(_parent)->_node->convertWorldToLocalOrientation(q);
	_node->setOrientation(q);
	_node->_update(true,true);
}
Esempio n. 23
0
 //-------------------------------------------------------------------------
 void
 AFile::setFrameRotation( Ogre::TransformKeyFrame* key_frame
                         , const Ogre::Vector3& v ) const
 {
     Ogre::Quaternion rot;
     Ogre::Matrix3 mat;
     mat.FromEulerAnglesZXY( Ogre::Radian(Ogre::Degree( -v.y )), Ogre::Radian(Ogre::Degree( -v.x )), Ogre::Radian(Ogre::Degree( -v.z )) );
     rot.FromRotationMatrix( mat );
     key_frame->setRotation( rot );
 }
Esempio n. 24
0
void fix_gta_coord(Ogre::Quaternion& quat)
{
    swap(quat.y, quat.z);
    Ogre::Radian angle;
    Ogre::Vector3 axis;
    quat.ToAngleAxis(angle, axis);
    //swap(axis.y, axis.z);
    axis = Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X) * axis;
    quat.FromAngleAxis(angle, axis);
}
Ogre::Quaternion DotSceneLoader::parseQuaternion(rapidxml::xml_node<>* XMLNode)
{
	//! @todo Fix this crap!

	Ogre::Quaternion orientation;

	if (XMLNode->first_attribute("qx"))
	{
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qx")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qy")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qz")->value());
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qw")->value());
	}
	if (XMLNode->first_attribute("qw"))
	{
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qw")->value());
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qx")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qy")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qz")->value());
	}
	else if (XMLNode->first_attribute("axisX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisX")->value());
		axis.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisY")->value());
		axis.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisZ")->value());
		Ogre::Real angle = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angle")->value());;
		orientation.FromAngleAxis(Ogre::Angle(angle), axis);
	}
	else if (XMLNode->first_attribute("angleX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleX")->value());
		axis.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleY")->value());
		axis.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleZ")->value());
		//orientation.FromAxes(&axis);
		//orientation.F
	}
	else if (XMLNode->first_attribute("x"))
	{
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("x")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("y")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("z")->value());
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("w")->value());
	}
	else if (XMLNode->first_attribute("w"))
	{
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("w")->value());
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("x")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("y")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("z")->value());
	}

	return orientation;
}
Esempio n. 26
0
Ogre::Degree
Entity::GetRotation() const
{
    assert( m_model_root_node );
    Ogre::Quaternion q = m_model_root_node->getOrientation();
    Ogre::Degree temp;
    Ogre::Vector3 vec = Ogre::Vector3::UNIT_Z;
    q.ToAngleAxis( temp, vec );

    return temp;
}
Esempio n. 27
0
    void PhysicsSystem::doPhysics(float dt, const std::vector<std::pair<std::string, Ogre::Vector3> >& actors)
    {
        //set the DebugRenderingMode. To disable it,set it to 0
        //eng->setDebugRenderingMode(1);

        //set the walkdirection to 0 (no movement) for every actor)
        for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
        {
            OEngine::Physic::PhysicActor* act = it->second;
            act->setWalkDirection(btVector3(0,0,0));
        }
		playerMove::playercmd& pm_ref = playerphysics->cmd;

        pm_ref.rightmove = 0;
        pm_ref.forwardmove = 0;
        pm_ref.upmove = 0;

		//playerphysics->ps.move_type = PM_NOCLIP;
        for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
            iter!=actors.end(); ++iter)
        {
            //dirty stuff to get the camera orientation. Must be changed!

            Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first);
            Ogre::Vector3 dir;
            Ogre::Node* yawNode = sceneNode->getChildIterator().getNext();
            Ogre::Node* pitchNode = yawNode->getChildIterator().getNext();
			Ogre::Quaternion yawQuat = yawNode->getOrientation();
            Ogre::Quaternion pitchQuat = pitchNode->getOrientation();



            playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees();

			playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90;


                Ogre::Quaternion quat = yawNode->getOrientation();
                Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);

				pm_ref.rightmove = -iter->second.x;
				pm_ref.forwardmove = -iter->second.y;
				pm_ref.upmove = iter->second.z;



            }





        mEngine->stepSimulation(dt);
    }
Esempio n. 28
0
void CameraManager::setOrientation(Ogre::Quaternion ori){

	mNodeYaw = ori.getYaw();
	mNodePitch = ori.getPitch();
	mNodeRoll = ori.getRoll();

	if(mCameraMode == OCULUS)
		mOculusCamera->setOrientation(ori);
	else
		mSimpleCamera->setOrientation(ori);

}
Esempio n. 29
0
/*/////////////////////////////////////////////////////////////////*/
void OgreOggListener::setOrientation(const Ogre::Quaternion& q) {
  Ogre::Vector3 vDirection = q.zAxis();
  Ogre::Vector3 vUp = q.yAxis();

  mOrientation[0] = -vDirection.x;
  mOrientation[1] = -vDirection.y;
  mOrientation[2] = -vDirection.z;
  mOrientation[3] = vUp.x;
  mOrientation[4] = vUp.y;
  mOrientation[5] = vUp.z;
  alListenerfv(AL_ORIENTATION, mOrientation);
}
Esempio n. 30
0
void Application::updateStats()
{
	static Ogre::String currFps = "Current FPS: ";
	static Ogre::String avgFps = "Average FPS: ";
	static Ogre::String bestFps = "Best FPS: ";
	static Ogre::String worstFps = "Worst FPS: ";
	static Ogre::String tris = "Triangle Count: ";
	static Ogre::String batches = "Batch Count: ";

	// update stats when necessary
	try {
		Ogre::OverlayElement* guiAvg = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/AverageFps");
		Ogre::OverlayElement* guiCurr = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
		Ogre::OverlayElement* guiBest = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/BestFps");
		Ogre::OverlayElement* guiWorst = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/WorstFps");

		const Ogre::RenderTarget::FrameStats& stats = m_window->getStatistics();
		guiAvg->setCaption(avgFps + Ogre::StringConverter::toString(stats.avgFPS));
		guiCurr->setCaption(currFps + Ogre::StringConverter::toString(stats.lastFPS));
		guiBest->setCaption(bestFps + Ogre::StringConverter::toString(stats.bestFPS)
			+" "+Ogre::StringConverter::toString(stats.bestFrameTime)+" ms");
		guiWorst->setCaption(worstFps + Ogre::StringConverter::toString(stats.worstFPS)
			+" "+Ogre::StringConverter::toString(stats.worstFrameTime)+" ms");

		Ogre::OverlayElement* guiTris = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/NumTris");
		guiTris->setCaption(tris + Ogre::StringConverter::toString(stats.triangleCount));

		Ogre::OverlayElement* guiBatches = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/NumBatches");
		guiBatches->setCaption(batches + Ogre::StringConverter::toString(stats.batchCount));

		/////////////////////////
		
		Ogre::Vector3 camPos = m_camera->getPosition();
		Ogre::Quaternion camOri = m_camera->getOrientation();
		Ogre::Vector3 freddyPos = m_sceneNode->getPosition();
		Ogre::Quaternion freddyOri = m_sceneNode->getOrientation();
		
		Ogre::OverlayElement* guiDbg = Ogre::OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
		guiDbg->setTop(0);

		Ogre::String message = 
			"Camera Position: x: "+Ogre::StringConverter::toString(camPos.x)+", y: "+Ogre::StringConverter::toString(camPos.y)+", z:"+Ogre::StringConverter::toString(camPos.z) + "\n" + 
			"Camera orientation: yaw: "+Ogre::StringConverter::toString(camOri.getYaw())+", pitch: "+Ogre::StringConverter::toString(camOri.getPitch())+", roll:"+Ogre::StringConverter::toString(camOri.getRoll()) + "\n" + 
			"Freddy position: x: "+Ogre::StringConverter::toString(freddyPos.x)+", y: "+Ogre::StringConverter::toString(freddyPos.y)+", z:"+Ogre::StringConverter::toString(freddyPos.z) + "\n" + 
			"Freddy orientation: yaw: "+Ogre::StringConverter::toString(freddyOri.getYaw())+", pitch: "+Ogre::StringConverter::toString(freddyOri.getPitch())+", roll:"+Ogre::StringConverter::toString(freddyOri.getRoll());
		
		guiDbg->setCaption(message);
		debugWindow->setText("This is a demo!");
	}
	catch(...) { /* ignore */ }
}