Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5338: Move ObjectFinder to separate file
  • Loading branch information
codereader committed Sep 26, 2020
1 parent 54ae23f commit 40da556
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 47 deletions.
54 changes: 7 additions & 47 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -28,6 +28,7 @@
#include "selection/Device.h"
#include "selection/SelectionTest.h"
#include "FloorHeightWalker.h"
#include "ObjectFinder.h"

#include "debugging/debugging.h"
#include "debugging/gl.h"
Expand All @@ -48,53 +49,10 @@ namespace
const char* const FAR_CLIP_DISABLED_TEXT = N_(" (currently disabled in preferences)");
}

class ObjectFinder :
public scene::NodeVisitor
{
scene::INodePtr _node;
SelectionTest& _selectionTest;

// To store the best intersection candidate
SelectionIntersection _bestIntersection;
public:
// Constructor
ObjectFinder(SelectionTest& test) :
_selectionTest(test)
{}

// Return the found node
const scene::INodePtr& getNode() const {
return _node;
}

// The visitor function
bool pre(const scene::INodePtr& node) {
// Check if the node is filtered
if (node->visible()) {
SelectionTestablePtr selectionTestable = Node_getSelectionTestable(node);

if (selectionTestable != NULL) {
bool occluded;
selection::OccludeSelector selector(_bestIntersection, occluded);
selectionTestable->testSelect(selector, _selectionTest);

if (occluded) {
_node = node;
}
}
}
else {
return false; // don't traverse filtered nodes
}

return true;
}
};

inline Vector2 windowvector_for_widget_centre(wxutil::GLWidget& widget)
{
wxSize size = widget.GetSize();
return Vector2(static_cast<float>(size.GetWidth() / 2), static_cast<float>(size.GetHeight() / 2));
return Vector2(static_cast<Vector2::ElementType>(size.GetWidth() / 2), static_cast<Vector2::ElementType>(size.GetHeight() / 2));
}

// ---------- CamWnd Implementation --------------------------------------------------
Expand Down Expand Up @@ -425,12 +383,14 @@ int CamWnd::getId()
return _id;
}

void CamWnd::jumpToObject(SelectionTest& selectionTest) {
void CamWnd::jumpToObject(SelectionTest& selectionTest)
{
// Find a suitable target node
ObjectFinder finder(selectionTest);
camera::ObjectFinder finder(selectionTest);
GlobalSceneGraph().root()->traverse(finder);

if (finder.getNode() != NULL) {
if (finder.getNode())
{
// A node has been found, get the bounding box
AABB found = finder.getNode()->worldAABB();

Expand Down
60 changes: 60 additions & 0 deletions radiant/camera/ObjectFinder.h
@@ -0,0 +1,60 @@
#pragma once

#include "inode.h"
#include "iselectiontest.h"
#include "selection/OccludeSelector.h"

namespace camera
{

class ObjectFinder :
public scene::NodeVisitor
{
private:
scene::INodePtr _node;
SelectionTest& _selectionTest;

// To store the best intersection candidate
SelectionIntersection _bestIntersection;

public:
// Constructor
ObjectFinder(SelectionTest& test) :
_selectionTest(test)
{}

const scene::INodePtr& getNode() const
{
return _node;
}

// The visitor function
bool pre(const scene::INodePtr& node)
{
// Check if the node is filtered
if (node->visible())
{
auto selectionTestable = Node_getSelectionTestable(node);

if (selectionTestable)
{
bool occluded;
selection::OccludeSelector selector(_bestIntersection, occluded);
selectionTestable->testSelect(selector, _selectionTest);

if (occluded)
{
_node = node;
}
}
}
else
{
return false; // don't traverse filtered nodes
}

return true;
}
};

}
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -376,6 +376,7 @@
<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" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1314,6 +1314,9 @@
<ClInclude Include="..\..\radiant\camera\FloorHeightWalker.h">
<Filter>src\camera</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\camera\ObjectFinder.h">
<Filter>src\camera</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 40da556

Please sign in to comment.