Sign in to follow this  
jviruss

Another try of free camera

Recommended Posts

Hello,I´m doing a free camera.I´m studing how resolve this problem without ogre facilities.I want do a free camera in a more low level. I want calculate the rotation of yaw,pitch and roll. I did this clase: .H Code Code: #ifndef __FREECAMERA__ #define __FREECAMERA__ #include "OgreVector3.h" #include "OgreSceneNode.h" #include "OgreCamera.h" class CFreeCamera { public: CFreeCamera(Ogre::Camera* cam); ~CFreeCamera(); void Update(float time); void Roll(float units); void Yaw(float units); void Pitch(float units); void Transform(Ogre::Vector3 increment); protected: float m_fRoll; float m_fYaw; float m_fPitch; Ogre::Camera* m_pCamera; float PutInIntervalPI(float number); }; #endif .CPP Code: #include "FreeCamera.h" #include "App.h" #include "ChaseCamera.h" #include <OgreMath.h> ////////////////////////////////////////////////////////// CFreeCamera::CFreeCamera(Ogre::Camera* cam) { m_fRoll = 0.0f; m_fYaw = 0.0f; m_fPitch = 0.0f; m_pCamera = cam; } ////////////////////////////////////////////////////////// CFreeCamera::~CFreeCamera() { } ////////////////////////////////////////////////////////// void CFreeCamera::Update( float time ) { } ////////////////////////////////////////////////////////// float PutInIntervalPI(float number) { float pi = Ogre::Math::PI; if(number > pi) { number = -pi + (abs(number) - pi); } else if(number < -pi) { number = pi - (abs(number) - pi); } return number; } ////////////////////////////////////////////////////////// void CFreeCamera::Roll(float units) { m_fRoll = PutInIntervalPI(m_fRoll + units); Matrix3 m; m.FromEulerAnglesZYX(Radian(m_fRoll),Radian(m_fYaw),Radian(m_fPitch)); Quaternion q; q.FromRotationMatrix(m); m_pCamera->setOrientation(q); }; void CFreeCamera::Yaw(float units) { m_fYaw = PutInIntervalPI(m_fYaw + units); Matrix3 m; m.FromEulerAnglesZYX(Radian(m_fRoll),Radian(m_fPitch),Radian(m_fYaw)); Quaternion q; q.FromRotationMatrix(m); m_pCamera->setOrientation(q); }; void CFreeCamera::Pitch(float units) { m_fPitch = PutInIntervalPI(m_fPitch + units); Matrix3 m; m.FromEulerAnglesZYX(Radian(m_fRoll),Radian(m_fYaw),Radian(m_fPitch)); Quaternion q; q.FromRotationMatrix(m); m_pCamera->setOrientation(q); }; void CFreeCamera::Transform(Ogre::Vector3 increment) { m_pCamera->setPosition(m_pCamera->getPosition() + (m_pCamera->getOrientation() * increment)); }; But it not work fine.Which is the problem? What I have do to yaw,pitch and roll the camera??? Info:My up vector is Y.Which is the correct order euler angles?? Thanks

Share this post


Link to post
Share on other sites
So what exactly is your problem? What are the problems you're experiencing?

One problem I did notice: you define PutInIntervalPI as a global function and not a member of CFreeCamera. Also, if you edit your post and put your code between source tag, it will make it much more readable. To put code in source tags, do the following:

[source]Your source code here[/source]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this