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 74 if (
pitch_ < PITCH_LIMIT_LOW)
78 else if (
pitch_ > PITCH_LIMIT_HIGH)
86 yaw_ = fmod(
yaw_, Ogre::Math::TWO_PI);
103 return global_focal_point;
114 Ogre::Vector3 pos(x, y, z);
118 Ogre::Vector3 vec = pos - global_focal_point;
119 pos =
relative_node_->getOrientation() * vec + global_focal_point;
125 camera_->lookAt(global_focal_point);
159 return camera_->getOrientation();
176 if (direction.dotProduct(Ogre::Vector3::NEGATIVE_UNIT_Z) < 0)
187 Ogre::Vector3 direction = orientation * (Ogre::Vector3::NEGATIVE_UNIT_Z *
distance_);
197 Ogre::Vector3 position =
camera_->getPosition();
198 Ogre::Quaternion orientation(w, x, y, z);
200 Ogre::Vector3 direction = orientation * (Ogre::Vector3::NEGATIVE_UNIT_Z *
distance_);
229 Ogre::Quaternion orientation =
camera_->getOrientation();
233 orientation =
relative_node_->getOrientation().Inverse() * orientation;
243 Ogre::Vector3 pos(x, y, z);
253 Ogre::Vector3 focal_point = point;
254 Ogre::Vector3 camera_position =
camera_->getPosition();
261 focal_point = rel_orient.Inverse() * (focal_point - rel_pos);
262 camera_position = rel_orient.Inverse() * (camera_position - rel_pos);
265 distance_ = focal_point.distance(camera_position);
274 pitch(-diff_y * 0.005);
279 float fovY =
camera_->getFOVy().valueRadians();
280 float fovX = 2.0f *
atan(
tan(fovY / 2.0
f) *
camera_->getAspectRatio());
282 int width =
camera_->getViewport()->getActualWidth();
283 int height =
camera_->getViewport()->getActualHeight();
286 ((
float)diff_y / (
float)height) *
distance_ *
tan(fovY / 2.0f) * 2.0f, 0.0f);
345 std::istringstream iss(str);
364 std::ostringstream oss;
void mouseRightUp(int x, int y) override
void mouseLeftDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift) override
Handle a left mouse button drag.
void setPosition(float x, float y, float z) override
Set the position of the camera.
std::string toString() override
Returns a string representation of the camera's configuration.
virtual Ogre::Vector3 getPosition()=0
Get the position of this camera.
void mouseLeftDown(int x, int y) override
void setFocalPoint(const Ogre::Vector3 &focal_point)
Set the focal point of the camera. Keeps the pitch/yaw/distance the same.
void yaw(float angle) override
Yaw the camera.
void mouseRightDown(int x, int y) override
float distance_
The camera's distance from the focal point.
Ogre::Vector3 focal_point_
The camera's focal point.
static const float YAW_START
void pitch(float angle) override
Pitch the camera.
Generic interface for a camera.
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
void move(float x, float y, float z) override
Move the camera relative to its orientation.
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)
void fromString(const std::string &str) override
Loads the camera's configure from the supplied string (generated through toString()) ...
void mouseRightDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift) override
Handle a right mouse button drag.
void scrollWheel(int diff, bool ctrl, bool alt, bool shift) override
Handle a scrollwheel change.
OrbitCamera(Ogre::SceneManager *scene_manager)
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
void setOrientation(float x, float y, float z, float w) override
Set the orientation of the camera from a quaternion.
void mouseMiddleUp(int x, int y) override
void mouseMiddleDrag(int diff_x, int diff_y, bool ctrl, bool alt, bool shift) override
Handle a middle mouse button drag.
Ogre::Camera * camera_
Ogre camera associated with this camera object.
Ogre::SceneNode * relative_node_
void zoom(float amount)
Move in/out from the focal point, ie. adjust distance_ by amount.
void mouseMiddleDown(int x, int y) override
Ogre::Vector3 getPosition() override
Get the position of this camera.
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
void setFrom(CameraBase *camera) override
Set the position/orientation of this camera from another camera.
void lookAt(const Ogre::Vector3 &point) override
Point the camera at the specified point.
Shape * focal_point_object_
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) ...
void update() override
Calculates the camera's position and orientation from the yaw, pitch, distance and focal point...
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
void roll(float angle) override
Roll the camera.
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
virtual Ogre::Quaternion getOrientation()=0
Get the orientation of this camera.
static const float PITCH_LIMIT_HIGH
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
static const float PITCH_LIMIT_LOW
void mouseLeftUp(int x, int y) override
float yaw_
The camera's yaw (rotation around the y-axis), in radians.
Ogre::Quaternion getOrientation() override
Get the orientation of this camera.
Ogre::Vector3 getGlobalFocalPoint()
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
static const float PITCH_START