34 #include <OgreCamera.h> 35 #include <OgrePlane.h> 36 #include <OgreQuaternion.h> 38 #include <OgreSceneNode.h> 39 #include <OgreVector3.h> 40 #include <OgreViewport.h> 65 mouse_ray.setOrigin(
target_scene_node_->convertWorldToLocalPosition( mouse_ray.getOrigin() ) );
66 mouse_ray.setDirection(
target_scene_node_->convertWorldToLocalOrientation( Ogre::Quaternion::IDENTITY ) * mouse_ray.getDirection() );
68 Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0 );
70 std::pair<bool, Ogre::Real> intersection = mouse_ray.intersects(ground_plane);
71 if (!intersection.first)
76 intersection_3d = mouse_ray.getPoint(intersection.second);
84 setStatus(
"<b>Left-Click:</b> Move X/Y. <b>Right-Click:</b>: Zoom." );
88 setStatus(
"<b>Left-Click:</b> Rotate. <b>Middle-Click:</b> Move X/Y. <b>Right-Click:</b>: Move Z. <b>Shift</b>: More options." );
95 if( event.
type == QEvent::MouseButtonPress )
100 else if( event.
type == QEvent::MouseButtonRelease )
105 else if( event.
type == QEvent::MouseMove )
107 diff_x =
event.x -
event.last_x;
108 diff_y =
event.y -
event.last_y;
112 if( event.
left() && !
event.shift() )
116 pitch( -diff_y*0.005 );
118 else if( event.
middle() || (
event.left() &&
event.shift()) )
122 int width =
event.viewport->getActualWidth();
123 int height =
event.viewport->getActualHeight();
125 Ogre::Ray mouse_ray =
event.viewport->getCamera()->getCameraToViewportRay( event.
x / (
float) width,
126 event.
y / (
float) height );
128 Ogre::Ray last_mouse_ray =
129 event.viewport->getCamera()->getCameraToViewportRay( event.
last_x / (
float) width,
130 event.
last_y / (
float) height );
132 Ogre::Vector3 last_intersect, intersect;
137 Ogre::Vector3 motion = last_intersect - intersect;
142 float motion_distance_limit = 1;
143 if( motion.length() > motion_distance_limit )
146 motion *= motion_distance_limit;
153 else if( event.
right() )
165 int diff =
event.wheel_delta;
180 Ogre::Camera* source_camera = source_view->
getCamera();
182 Ogre::Ray camera_dir_ray( source_camera->getRealPosition(), source_camera->getRealDirection() );
183 Ogre::Ray camera_down_ray( source_camera->getRealPosition(), -1.0 * source_camera->getRealUp() );
190 float l_a = source_camera->getPosition().distance( b );
191 float l_b = source_camera->getPosition().distance( a );
196 camera_dir_ray.setOrigin( source_camera->getRealPosition() - source_camera->getRealUp() * distance *
CAMERA_OFFSET );
197 Ogre::Vector3 new_focal_point;
213 Ogre::Vector3 camera_position =
camera_->getPosition();
215 new_focal_point.z = 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. ...
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...
bool intersectGroundPlane(Ogre::Ray mouse_ray, Ogre::Vector3 &intersection_3d)
Like the orbit view controller, but focal point moves only in the x-y plane.
virtual bool setVector(const Ogre::Vector3 &vector)
virtual void handleMouseEvent(ViewportMouseEvent &evt)
void emitConfigChanged()
Subclasses should call this whenever a change is made which would change the results of toString()...
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
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
static const float CAMERA_OFFSET
virtual void updateCamera()
bool add(const Ogre::Vector3 &offset)
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 setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
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...
bool setFloat(float new_value)
Float-typed "SLOT" version of setValue().
VectorProperty * focal_point_property_
The point around which the camera "orbits".
virtual void onInitialize()
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set.
Ogre::Camera * getCamera() const
void setStatus(const QString &message)
virtual void onInitialize()
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set.
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
virtual void updateCamera()
Ogre::SceneNode * target_scene_node_
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
DisplayContext * context_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)