Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5338: Move JumpToObject algorithm to JumpToObjectTool.
  • Loading branch information
codereader committed Sep 26, 2020
1 parent 9f305aa commit feec10b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
20 changes: 0 additions & 20 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -28,7 +28,6 @@
#include "selection/Device.h"
#include "selection/SelectionTest.h"
#include "FloorHeightWalker.h"
#include "ObjectFinder.h"

#include "debugging/debugging.h"
#include "debugging/gl.h"
Expand Down Expand Up @@ -400,24 +399,6 @@ int CamWnd::getId()
return _id;
}

void CamWnd::jumpToObject(SelectionTest& selectionTest)
{
// 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
AABB 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().focusCamera(found.origin, _camera.getCameraAngles());
GlobalXYWndManager().setOrigin(found.origin);
}
}

void CamWnd::changeFloor(const bool up)
{
float current = _camera.getCameraOrigin()[2] - 48;
Expand All @@ -437,7 +418,6 @@ void CamWnd::changeFloor(const bool up)
const Vector3& org = _camera.getCameraOrigin();
_camera.setCameraOrigin(Vector3(org[0], org[1], current + 48));

_camera.updateModelview();
update();
GlobalCamera().movedNotify();
}
Expand Down
2 changes: 0 additions & 2 deletions radiant/camera/CamWnd.h
Expand Up @@ -145,8 +145,6 @@ class CamWnd :
void disableFreeMove() override;
bool freeMoveEnabled() const override;

void jumpToObject(SelectionTest& selectionTest);

// Enables/disables the (ordinary) camera movement (non-freelook)
void addHandlersMove();
void removeHandlersMove();
Expand Down
22 changes: 16 additions & 6 deletions radiant/camera/tools/JumpToObjectTool.h
@@ -1,8 +1,11 @@
#pragma once

#include "imousetool.h"
#include "iscenegraph.h"
#include "iorthoview.h"
#include "i18n.h"
#include "../GlobalCameraWndManager.h"
#include "ObjectFinder.h"

namespace ui
{
Expand All @@ -27,15 +30,23 @@ class JumpToObjectTool :
{
try
{
CameraMouseToolEvent& camEvent = dynamic_cast<CameraMouseToolEvent&>(ev);
auto& camEvent = dynamic_cast<CameraMouseToolEvent&>(ev);

SelectionTestPtr selectionTest = camEvent.getView().createSelectionTestForPoint(camEvent.getDevicePosition());
auto selectionTest = camEvent.getView().createSelectionTestForPoint(camEvent.getDevicePosition());

CamWndPtr cam = GlobalCamera().getActiveCamWnd();
// Find a suitable target node
camera::ObjectFinder finder(*selectionTest);
GlobalSceneGraph().root()->traverse(finder);

if (cam != NULL)
if (finder.getNode())
{
cam->jumpToObject(*selectionTest);
// 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().focusCamera(found.origin, camEvent.getView().getCameraAngles());
GlobalXYWndManager().setOrigin(found.origin);
}

return Result::Finished;
Expand All @@ -45,7 +56,6 @@ class JumpToObjectTool :
}

return Result::Ignored; // not handled

}

Result onMouseMove(Event& ev) override
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -375,10 +375,10 @@
<ClInclude Include="..\..\radiant\ApplicationContext.h" />
<ClInclude Include="..\..\radiant\camera\FloorHeightWalker.h" />
<ClInclude Include="..\..\radiant\camera\GlobalCameraWndManager.h" />
<ClInclude Include="..\..\radiant\camera\ObjectFinder.h" />
<ClInclude Include="..\..\radiant\camera\tools\CameraMouseToolEvent.h" />
<ClInclude Include="..\..\radiant\camera\tools\FreeMoveTool.h" />
<ClInclude Include="..\..\radiant\camera\tools\JumpToObjectTool.h" />
<ClInclude Include="..\..\radiant\camera\tools\ObjectFinder.h" />
<ClInclude Include="..\..\radiant\camera\tools\PanViewTool.h" />
<ClInclude Include="..\..\radiant\camera\tools\ShaderClipboardTools.h" />
<ClInclude Include="..\..\radiant\clipboard\ClipboardModule.h" />
Expand Down
4 changes: 2 additions & 2 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1308,8 +1308,8 @@
<ClInclude Include="..\..\radiant\camera\FloorHeightWalker.h">
<Filter>src\camera</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\camera\ObjectFinder.h">
<Filter>src\camera</Filter>
<ClInclude Include="..\..\radiant\camera\tools\ObjectFinder.h">
<Filter>src\camera\tools</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit feec10b

Please sign in to comment.