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;
85 camera_->setProjectionType( Ogre::PT_PERSPECTIVE );
114 setStatus(
"<b>Left-Click:</b> Move X/Y. <b>Right-Click:</b>: Move Z. <b>Mouse Wheel:</b>: Zoom. " );
118 setStatus(
"<b>Left-Click:</b> Rotate. <b>Middle-Click:</b> Move X/Y. <b>Right-Click/Mouse Wheel:</b>: Zoom. <b>Shift</b>: More options." );
129 if( event.
type == QEvent::MouseButtonPress )
135 else if( event.
type == QEvent::MouseButtonRelease )
143 diff_x =
event.x -
event.last_x;
144 diff_y =
event.y -
event.last_y;
149 if( event.
left() && !
event.shift() )
153 pitch( -diff_y*0.005 );
156 else if( event.
middle() || (
event.shift() &&
event.left()) )
159 float fovY =
camera_->getFOVy().valueRadians();
160 float fovX = 2.0f * atan( tan( fovY / 2.0
f ) *
camera_->getAspectRatio() );
162 int width =
camera_->getViewport()->getActualWidth();
163 int height =
camera_->getViewport()->getActualHeight();
165 move( -((
float)diff_x / (
float)width) * distance * tan( fovX / 2.0
f ) * 2.0
f,
166 ((
float)diff_y / (
float)height) * distance * tan( fovY / 2.0f ) * 2.0f,
169 else if( event.
right() )
175 move(0.0
f, 0.0
f, diff_y * 0.1 * (distance / 10.0
f));
181 zoom( -diff_y * 0.1 * (distance / 10.0
f) );
193 int diff =
event.wheel_delta;
196 move( 0, 0, -diff * 0.001 * distance );
200 zoom( diff * 0.001 * distance );
216 Ogre::Camera* source_camera = source_view->
getCamera();
217 Ogre::Vector3 position = source_camera->getPosition();
218 Ogre::Quaternion orientation = source_camera->getOrientation();
220 if( source_view->
getClassId() ==
"rviz/Orbit" )
248 Ogre::Vector3 camera_position =
camera_->getPosition();
265 Ogre::Vector3 camera_z = Ogre::Vector3::UNIT_Z;
272 camera_z = -camera_z;
277 float x = distance * cos( yaw ) * cos( pitch ) + focal_point.x;
278 float y = distance * sin( yaw ) * cos( pitch ) + focal_point.y;
279 float z = distance * sin( pitch ) + focal_point.z;
282 Ogre::Vector3 pos( x, y, z );
313 distance_property = 1;
316 fshape_size * distance_property,
317 fshape_size * distance_property / 5.0 ) );
virtual ~OrbitViewController()
virtual void update(float dt, float ros_dt)
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
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. ...
virtual void mimic(ViewController *source_view)
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
virtual void mimic(ViewController *source_view)
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
FloatProperty * pitch_property_
The camera's pitch (rotation around the x-axis), in radians.
virtual bool setVector(const Ogre::Vector3 &vector)
static const float YAW_START
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.
void setCursor(CursorType cursor_type)
virtual float getFloat() const
virtual void handleMouseEvent(ViewportMouseEvent &evt)
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
virtual void updateCamera()
Property specialized to enforce floating point max/min.
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool add(const Ogre::Vector3 &offset)
static const float YAW_START
virtual void onTargetFrameChanged(const Ogre::Vector3 &old_reference_position, const Ogre::Quaternion &old_reference_orientation)
Override to implement the change in properties which nullifies the change in target frame...
virtual void setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
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.
bool add(float delta)
Add the given delta to the property value.
virtual bool getBool() const
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
virtual void update(float dt, float ros_dt)
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of this object.
FloatProperty * focal_shape_size_property_
The focal shape size.
Ogre::Camera * getCamera() const
void setStatus(const QString &message)
static const float PITCH_START
TFSIMD_FORCE_INLINE const tfScalar & x() const
virtual void onInitialize()
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set.
TFSIMD_FORCE_INLINE const tfScalar & z() const
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.
virtual Ogre::Vector3 getVector() const
Property specialized to provide getter for booleans.
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
virtual void onInitialize()
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set. This version calls updateTargetSceneNode().
Ogre::SceneNode * target_scene_node_
virtual void lookAt(const Ogre::Vector3 &point)
This should be implemented in each subclass to aim the camera at the given point in space (relative t...
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
DisplayContext * context_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
static const float DISTANCE_START
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.
void move(float x, float y, float z)