33 #include <OgreCamera.h> 34 #include <OgreSceneManager.h> 35 #include <OgreSceneNode.h> 36 #include <OgreVector3.h> 37 #include <OgreQuaternion.h> 38 #include <OgreViewport.h> 43 #define MIN_DISTANCE 0.01 57 , pitch_( PITCH_START )
75 if (
pitch_ < PITCH_LIMIT_LOW )
79 else if (
pitch_ > PITCH_LIMIT_HIGH )
87 yaw_ = fmod(
yaw_, Ogre::Math::TWO_PI );
104 return global_focal_point;
115 Ogre::Vector3 pos( x, y, z );
119 Ogre::Vector3 vec = pos - global_focal_point;
120 pos =
relative_node_->getOrientation() * vec + global_focal_point;
126 camera_->lookAt( global_focal_point );
160 return camera_->getOrientation();
177 if ( direction.dotProduct( Ogre::Vector3::NEGATIVE_UNIT_Z ) < 0 )
188 Ogre::Vector3 direction = orientation * (Ogre::Vector3::NEGATIVE_UNIT_Z *
distance_);
198 Ogre::Vector3 position =
camera_->getPosition();
199 Ogre::Quaternion orientation( w, x, y, z );
201 Ogre::Vector3 direction = orientation * (Ogre::Vector3::NEGATIVE_UNIT_Z *
distance_);
230 Ogre::Quaternion orientation =
camera_->getOrientation();
234 orientation =
relative_node_->getOrientation().Inverse() * orientation;
244 Ogre::Vector3 pos( x, y, z );
254 Ogre::Vector3 focal_point = point;
255 Ogre::Vector3 camera_position =
camera_->getPosition();
262 focal_point = rel_orient.Inverse() * ( focal_point - rel_pos );
263 camera_position = rel_orient.Inverse() * ( camera_position - rel_pos );
266 distance_ = focal_point.distance( camera_position );
275 pitch( -diff_y*0.005 );
280 float fovY =
camera_->getFOVy().valueRadians();
281 float fovX = 2.0f * atan( tan( fovY / 2.0
f ) *
camera_->getAspectRatio() );
283 int width =
camera_->getViewport()->getActualWidth();
284 int height =
camera_->getViewport()->getActualHeight();
286 move( -((
float)diff_x / (
float)width) *
distance_ * tan( fovX / 2.0
f ) * 2.0
f, ((
float)diff_y / (
float)height) *
distance_ * tan( fovY / 2.0f ) * 2.0f, 0.0f );
346 std::istringstream iss(str);
365 std::ostringstream oss;
virtual Ogre::Vector3 getPosition()=0
Get the position of this camera.
virtual void fromString(const std::string &str)
Loads the camera's configure from the supplied string (generated through toString()) ...
virtual void mouseLeftDown(int x, int y)
void setFocalPoint(const Ogre::Vector3 &focal_point)
Set the focal point of the camera. Keeps the pitch/yaw/distance the same.
float distance_
The camera's distance from the focal point.
Ogre::Vector3 focal_point_
The camera's focal point.
static const float YAW_START
virtual void yaw(float angle)
Yaw the camera.
Generic interface for a camera.
virtual void roll(float angle)
Roll the camera.
virtual void pitch(float angle)
Pitch the camera.
void calculatePitchYawFromPosition(const Ogre::Vector3 &position)
Calculates pitch and yaw values given a new position and the current focal point. ...
void normalizeYaw()
Normalizes the camera's yaw in the range [0, 2*pi)
virtual Ogre::Vector3 getPosition()
Get the position of this camera.
virtual void setPosition(float x, float y, float z)
Set the position of the camera.
TFSIMD_FORCE_INLINE const tfScalar & y() const
OrbitCamera(Ogre::SceneManager *scene_manager)
virtual std::string toString()
Returns a string representation of the camera's configuration.
virtual void mouseMiddleDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift)
Handle a middle mouse button drag.
virtual void setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
Ogre::Camera * camera_
Ogre camera associated with this camera object.
virtual void mouseRightDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift)
Handle a right mouse button drag.
Ogre::SceneNode * relative_node_
virtual void scrollWheel(int diff, bool ctrl, bool alt, bool shift)
Handle a scrollwheel change.
void zoom(float amount)
Move in/out from the focal point, ie. adjust distance_ by amount.
virtual void update()
Calculates the camera's position and orientation from the yaw, pitch, distance and focal point...
virtual void lookAt(const Ogre::Vector3 &point)
Point the camera at the specified point.
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of this object.
virtual void mouseMiddleDown(int x, int y)
TFSIMD_FORCE_INLINE Vector3()
virtual Ogre::Quaternion getOrientation()
Get the orientation of this camera.
Shape * focal_point_object_
virtual void mouseRightDown(int x, int y)
TFSIMD_FORCE_INLINE const tfScalar & x() const
float pitch_
The camera's pitch (rotation around the x-axis), in radians.
void normalizePitch()
Normalizes the camera's pitch, preventing it from reaching vertical (or turning upside down) ...
TFSIMD_FORCE_INLINE const tfScalar & z() const
virtual void mouseRightUp(int x, int y)
virtual void move(float x, float y, float z)
Move the camera relative to its orientation.
virtual Ogre::Quaternion getOrientation()=0
Get the orientation of this camera.
static const float PITCH_LIMIT_HIGH
virtual void setOrientation(float x, float y, float z, float w)
Set the orientation of the camera from a quaternion.
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
virtual void mouseMiddleUp(int x, int y)
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
static const float PITCH_LIMIT_LOW
float yaw_
The camera's yaw (rotation around the y-axis), in radians.
virtual void mouseLeftDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift)
Handle a left mouse button drag.
Ogre::Vector3 getGlobalFocalPoint()
virtual void mouseLeftUp(int x, int y)
static const float PITCH_START
virtual void setScale(const Ogre::Vector3 &scale)
Set the scale of the object. Always relative to the identity orientation of the object.
virtual void setFrom(CameraBase *camera)
Set the position/orientation of this camera from another camera.