Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to invert Z axis for orbit-based view controllers #1128

Merged
merged 2 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "rviz/display_context.h"
#include "rviz/ogre_helpers/orthographic.h"
#include "rviz/ogre_helpers/shape.h"
#include "rviz/properties/bool_property.h"
#include "rviz/properties/float_property.h"
#include "rviz/viewport_mouse_event.h"

Expand Down Expand Up @@ -64,6 +65,7 @@ void FixedOrientationOrthoViewController::onInitialize()

camera_->setProjectionType( Ogre::PT_ORTHOGRAPHIC );
camera_->setFixedYawAxis( false );
invert_z_->hide();
}

void FixedOrientationOrthoViewController::reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "rviz/viewport_mouse_event.h"
#include "rviz/geometry.h"
#include "rviz/ogre_helpers/shape.h"
#include "rviz/properties/bool_property.h"
#include "rviz/properties/float_property.h"
#include "rviz/properties/vector_property.h"

Expand Down Expand Up @@ -73,6 +74,7 @@ void FPSViewController::onInitialize()
{
FramePositionTrackingViewController::onInitialize();
camera_->setProjectionType( Ogre::PT_PERSPECTIVE );
invert_z_->hide();
}

void FPSViewController::reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ void OrbitViewController::updateCamera()
float distance = distance_property_->getFloat();
float yaw = yaw_property_->getFloat();
float pitch = pitch_property_->getFloat();
Ogre::Vector3 camera_z = Ogre::Vector3::UNIT_Z;

// If requested, turn the world upside down.
if(this->invert_z_->getBool())
{
yaw = -yaw;
pitch = -pitch;
camera_z = -camera_z;
}

Ogre::Vector3 focal_point = focal_point_property_->getVector();

Expand All @@ -273,7 +282,7 @@ void OrbitViewController::updateCamera()
Ogre::Vector3 pos( x, y, z );

camera_->setPosition(pos);
camera_->setFixedYawAxis(true, target_scene_node_->getOrientation() * Ogre::Vector3::UNIT_Z);
camera_->setFixedYawAxis(true, target_scene_node_->getOrientation() * camera_z);
camera_->setDirection(target_scene_node_->getOrientation() * (focal_point - pos));

focal_shape_->setPosition( focal_point );
Expand Down
7 changes: 7 additions & 0 deletions src/rviz/view_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ ViewController::ViewController()
stereo_focal_distance_ = new FloatProperty( "Stereo Focal Distance", 1.0f,
"Distance from eyes to screen. For stereo rendering.",
stereo_enable_, SLOT( updateStereoProperties() ), this );
invert_z_ = new BoolProperty( "Invert Z Axis", false,
"Invert camera's Z axis for Z-down environments/models.",
this, SLOT( updateStereoProperties() ) );
}

void ViewController::initialize( DisplayContext* context )
Expand Down Expand Up @@ -278,5 +281,9 @@ void ViewController::updateStereoProperties()
}
}

void ViewController::updateInvertZAxis()
{
// We don't seem to need to do anything here.
}

} // end namespace rviz
2 changes: 2 additions & 0 deletions src/rviz/view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private Q_SLOTS:

void updateNearClipDistance();
void updateStereoProperties();
void updateInvertZAxis();

protected:
/** @brief Do subclass-specific initialization. Called by
Expand Down Expand Up @@ -207,6 +208,7 @@ private Q_SLOTS:
BoolProperty* stereo_eye_swap_;
FloatProperty* stereo_eye_separation_;
FloatProperty* stereo_focal_distance_;
BoolProperty* invert_z_;

void setStatus( const QString & message );

Expand Down