Skip to content
Open
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 @@ -69,9 +69,9 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC FrameViewController : public FPSViewController

void reset() override;

void yaw(float angle);
void resetOrientation();

void pitch(float angle);
void update(float dt, float ros_dt) override;

protected:
void onTargetFrameChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ inline QString fmtAxis(int i)
return QString("%1%2 axis").arg(QChar(i % 2 ? '+' : '-')).arg(QChar('x' + (i - 1) / 2));
}

inline Ogre::Vector3 getAxis(int option)
{
Ogre::Vector3 axis(0, 0, 0);
if (option >= 1 && option <= 6) {
axis[(option - 1) / 2] = (option % 2) ? +1 : -1;
}
return axis;
}

static const Ogre::Quaternion ROBOT_TO_CAMERA_ROTATION =
Ogre::Quaternion(Ogre::Radian(-Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_Y) *
Ogre::Quaternion(Ogre::Radian(-Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_Z);
Expand All @@ -83,6 +92,7 @@ FrameViewController::FrameViewController()
void FrameViewController::onInitialize()
{
FPSViewController::onInitialize();
invert_z_->show();
changedAxis();
}

Expand Down Expand Up @@ -118,7 +128,7 @@ void FrameViewController::setAxisFromCamera()
void FrameViewController::changedAxis()
{
rememberAxis(axis_property_->getOptionInt());
reset();
resetOrientation();
}

inline void FrameViewController::rememberAxis(int current)
Expand All @@ -131,22 +141,42 @@ inline void FrameViewController::rememberAxis(int current)
void FrameViewController::reset()
{
camera_scene_node_->setPosition(Ogre::Vector3::ZERO);
Ogre::Vector3 axis(0, 0, 0);
resetOrientation();
}

void FrameViewController::resetOrientation()
{
int option = previous_axis_;
if (option >= 1 && option <= 6) {
axis[(option - 1) / 2] = (option % 2) ? +1 : -1;
Ogre::Quaternion q;
if (option == 2) { // special case for the -X axis
// Create a rotation of 180 degrees around the Z axis
q = Ogre::Quaternion(Ogre::Radian(Ogre::Math::PI), Ogre::Vector3::UNIT_Z);
} else {
q = Ogre::Vector3::UNIT_X.getRotationTo(axis);
}
camera_scene_node_->setOrientation(q * ROBOT_TO_CAMERA_ROTATION);
Ogre::Quaternion q;
if (option == 2) { // special case for the -X axis
// Create a rotation of 180 degrees around the Z axis
q = Ogre::Quaternion(Ogre::Radian(Ogre::Math::PI), Ogre::Vector3::UNIT_Z);
} else {
Ogre::Vector3 axis = getAxis(option);
q = Ogre::Vector3::UNIT_X.getRotationTo(axis);
}
camera_scene_node_->setOrientation(q * ROBOT_TO_CAMERA_ROTATION);
setPropertiesFromCamera(camera_);
}

void FrameViewController::update(float dt, float ros_dt)
{
FPSViewController::update(dt, ros_dt);

// continuously track the orientation of the reference frame
if (getNewTransform()) {
Ogre::Quaternion quat = reference_orientation_;

// use "z inversion" to switch to flipped frame around current axis
if (invert_z_->getBool()) {
Ogre::Vector3 axis = getAxis(previous_axis_);
quat = quat * Ogre::Quaternion(Ogre::Radian(Ogre::Math::PI), axis);
}

target_scene_node_->setOrientation(quat);
}
}

void FrameViewController::handleMouseEvent(rviz_common::ViewportMouseEvent & event)
{
if (locked_property_->getBool()) {
Expand Down