Skip to content

Commit 18541ee

Browse files
authored
Create new cursor node in onInitialize function (#9)
1 parent 2417bf0 commit 18541ee

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/rviz_tool_cursor/rviz_tool_cursor.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,19 @@ ToolCursor::~ToolCursor()
130130

131131
void ToolCursor::onInitialize()
132132
{
133-
if(cursor_node_ != nullptr)
134-
{
135-
// Initialize the scene node
136-
cursor_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
133+
// Initialize the scene node
134+
cursor_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
137135

138-
// Create the visual tool object
139-
Ogre::MovableObject* obj = createToolVisualization();
136+
// Create the visual tool object
137+
Ogre::MovableObject* obj = createToolVisualization();
140138

141-
// Attach the tool visualization to the scene
142-
cursor_node_->attachObject(obj);
143-
cursor_node_->setVisible(false);
139+
// Attach the tool visualization to the scene
140+
cursor_node_->attachObject(obj);
141+
cursor_node_->setVisible(false);
144142

145-
// Set the cursors
146-
hit_cursor_ = cursor_;
147-
std_cursor_ = rviz::getDefaultCursor();
148-
}
143+
// Set the cursors
144+
hit_cursor_ = cursor_;
145+
std_cursor_ = rviz::getDefaultCursor();
149146
}
150147

151148
void ToolCursor::activate()
@@ -217,7 +214,7 @@ int ToolCursor::processMouseEvent(rviz::ViewportMouseEvent& event)
217214

218215
// Project the tool visualization onto the ground
219216
Ogre::Plane plane (Ogre::Vector3::UNIT_Z, 0.0f);
220-
rviz::getPointOnPlaneFromWindowXY(event.viewport, plane, event.x, event.y, position);
217+
rviz::getPointOnPlaneFromWindowXY(event.viewport, plane, event.x, event.y, position);
221218
cursor_node_->setOrientation(1.0f, 0.0f, 0.0f, 0.0f);
222219
cursor_node_->setPosition(position);
223220
}

0 commit comments

Comments
 (0)