1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#pragma once
#include "imousetool.h"
#include "iscenegraph.h"
#include "iorthoview.h"
#include "i18n.h"
#include "../CameraWndManager.h"
#include "ObjectFinder.h"
#include "math/AABB.h"
namespace ui
{
class JumpToObjectTool :
public MouseTool
{
public:
const std::string& getName() override
{
static std::string name("JumpToObjectTool");
return name;
}
const std::string& getDisplayName() override
{
static std::string displayName(_("Jump to Object"));
return displayName;
}
Result onMouseDown(Event& ev) override
{
try
{
auto& camEvent = dynamic_cast<CameraMouseToolEvent&>(ev);
auto selectionTest = camEvent.getView().createSelectionTestForPoint(camEvent.getDevicePosition());
// Find a suitable target node
camera::ObjectFinder finder(*selectionTest);
GlobalSceneGraph().root()->traverse(finder);
if (finder.getNode())
{
// A node has been found, get the bounding box
auto found = finder.getNode()->worldAABB();
// Focus the view at the center of the found AABB
// Set the camera and the views to the given point
GlobalCameraManager().focusAllCameras(found.origin, camEvent.getView().getCameraAngles());
GlobalOrthoViewManager().setOrigin(found.origin);
}
return Result::Finished;
}
catch (std::bad_cast&)
{
}
return Result::Ignored; // not handled
}
Result onMouseMove(Event& ev) override
{
return Result::Finished;
}
Result onMouseUp(Event& ev) override
{
return Result::Finished;
}
};
} // namespace
|