32 #include <OgreCamera.h> 33 #include <OgreQuaternion.h> 34 #include <OgreSceneManager.h> 35 #include <OgreSceneNode.h> 36 #include <OgreVector3.h> 37 #include <OgreViewport.h> 53 static const float YAW_START = Ogre::Math::HALF_PI * 0.5;
82 "The center point which the camera orbits.",
this);
89 camera_->setProjectionType(Ogre::PT_PERSPECTIVE);
119 "<b>Left-Click:</b> Move X/Y. <b>Right-Click:</b>: Move Z. <b>Mouse Wheel:</b>: Zoom. ");
123 setStatus(
"<b>Left-Click:</b> Rotate. <b>Middle-Click:</b> Move X/Y. <b>Right-Click/Mouse " 124 "Wheel:</b>: Zoom. <b>Shift</b>: More options.");
135 if (event.
type == QEvent::MouseButtonPress)
141 else if (event.
type == QEvent::MouseButtonRelease)
149 diff_x =
event.x -
event.last_x;
150 diff_y =
event.y -
event.last_y;
155 if (event.
left() && !
event.shift())
159 pitch(-diff_y * 0.005);
162 else if (event.
middle() || (
event.shift() &&
event.left()))
165 float fovY =
camera_->getFOVy().valueRadians();
166 float fovX = 2.0f *
atan(
tan(fovY / 2.0
f) *
camera_->getAspectRatio());
168 int width =
camera_->getViewport()->getActualWidth();
169 int height =
camera_->getViewport()->getActualHeight();
171 move(-((
float)diff_x / (
float)width) * distance *
tan(fovX / 2.0
f) * 2.0
f,
172 ((
float)diff_y / (
float)height) * distance *
tan(fovY / 2.0f) * 2.0f, 0.0f);
174 else if (event.
right())
180 move(0.0
f, 0.0
f, diff_y * 0.1 * (distance / 10.0
f));
186 zoom(-diff_y * 0.1 * (distance / 10.0
f));
198 int diff =
event.wheel_delta;
201 move(0, 0, -diff * 0.001 * distance);
205 zoom(diff * 0.001 * distance);
221 Ogre::Camera* source_camera = source_view->
getCamera();
222 Ogre::Vector3 position = source_camera->getPosition();
223 Ogre::Quaternion orientation = source_camera->getOrientation();
225 if (source_view->
getClassId() ==
"rviz/Orbit")
239 Ogre::Vector3 direction =
254 Ogre::Vector3 camera_position =
camera_->getPosition();
263 const Ogre::Quaternion& )
273 Ogre::Vector3 camera_z = Ogre::Vector3::UNIT_Z;
280 camera_z = -camera_z;
285 float x = distance *
cos(yaw) *
cos(pitch) + focal_point.x;
286 float y = distance *
sin(yaw) *
cos(pitch) + focal_point.y;
287 float z = distance *
sin(pitch) + focal_point.z;
290 Ogre::Vector3 pos(x, y, z);
321 distance_property = 1;
323 focal_shape_->
setScale(Ogre::Vector3(fshape_size * distance_property, fshape_size * distance_property,
324 fshape_size * distance_property / 5.0));
FloatProperty * distance_property_
The camera's distance from the focal point.
void calculatePitchYawFromPosition(const Ogre::Vector3 &position)
Calculates pitch and yaw values given a new position and the current focal point. ...
void update(float dt, float ros_dt) override
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
FloatProperty * pitch_property_
The camera's pitch (rotation around the x-axis), in radians.
void onTargetFrameChanged(const Ogre::Vector3 &old_reference_position, const Ogre::Quaternion &old_reference_orientation) override
Override to implement the change in properties which nullifies the change in target frame...
virtual bool setVector(const Ogre::Vector3 &vector)
static const float YAW_START
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
void mimic(ViewController *source_view) override
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
void updateFocalShapeSize()
Calculates the focal shape size and update it's geometry.
void zoom(float amount)
Move in/out from the focal point, ie. adjust #distance_ by amount.
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
void setCursor(CursorType cursor_type)
Ogre::Camera * getCamera() const
virtual Ogre::Vector3 getVector() const
virtual void updateCamera()
Property specialized to enforce floating point max/min.
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
bool add(const Ogre::Vector3 &offset)
static const float YAW_START
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
float mapAngleTo0_2Pi(float angle)
Return the input angle mapped back to the range 0 to 2*PI.
BoolProperty * focal_shape_fixed_size_property_
Whether the focal shape size is fixed or not.
void onInitialize() override
Do subclass-specific initialization.
bool add(float delta)
Add the given delta to the property value.
static const bool FOCAL_SHAPE_FIXED_SIZE
bool setFloat(float new_value)
Float-typed "SLOT" version of setValue().
virtual Property * subProp(const QString &sub_name)
Return the first child Property with the given name, or the FailureProperty if no child has the name...
An orbital camera, controlled by yaw, pitch, distance, and focal point.
Ogre::Vector3 reference_position_
VectorProperty * focal_point_property_
The point around which the camera "orbits".
static const float FOCAL_SHAPE_SIZE_START
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
FloatProperty * focal_shape_size_property_
The focal shape size.
void handleMouseEvent(ViewportMouseEvent &evt) override
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
void lookAt(const Ogre::Vector3 &point) override
This should be implemented in each subclass to aim the camera at the given point in space (relative t...
void setStatus(const QString &message)
static const float PITCH_START
void update(float dt, float ros_dt) override
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
void onInitialize() override
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set.
~OrbitViewController() override
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
FloatProperty * yaw_property_
The camera's yaw (rotation around the y-axis), in radians.
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
Property specialized to provide getter for booleans.
virtual float getFloat() const
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Ogre::SceneNode * target_scene_node_
void mimic(ViewController *source_view) override
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
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.
virtual bool getBool() const
DisplayContext * context_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
static const float DISTANCE_START
static const float PITCH_START
void move(float x, float y, float z)