1 #pragma once
2 
3 #include "math/matrix.h"
4 #include "math/Vector3.h"
5 #include "selectable.h"
6 
7 #include "../camera/view.h"
8 #include "BestPoint.h"
9 #include "SelectionBox.h"
10 
11 class SelectionVolume : public SelectionTest {
12   Matrix4 _local2view;
13   const View& _view;
14   clipcull_t _cull;
15   Vector3 _near;
16   Vector3 _far;
17 public:
SelectionVolume(const View & view)18   SelectionVolume(const View& view): _view(view) {}
19 
getVolume()20   const VolumeTest& getVolume() const {
21     return _view;
22   }
23 
getNear()24   const Vector3& getNear() const {
25     return _near;
26   }
27 
getFar()28   const Vector3& getFar() const {
29     return _far;
30   }
31 
32   void BeginMesh(const Matrix4& localToWorld, bool twoSided);
33   void TestPoint(const Vector3& point, SelectionIntersection& best);
34   void TestPolygon(const VertexPointer& vertices, std::size_t count, SelectionIntersection& best);
35   void TestLineLoop(const VertexPointer& vertices, std::size_t count, SelectionIntersection& best);
36   void TestLineStrip(const VertexPointer& vertices, std::size_t count, SelectionIntersection& best);
37   void TestLines(const VertexPointer& vertices, std::size_t count, SelectionIntersection& best);
38   void TestTriangles(const VertexPointer& vertices, const IndexPointer& indices, SelectionIntersection& best);
39   void TestQuads(const VertexPointer& vertices, const IndexPointer& indices, SelectionIntersection& best);
40   void TestQuadStrip(const VertexPointer& vertices, const IndexPointer& indices, SelectionIntersection& best);
41 };
42 
43 // --------------------------------------------------------------------------------
44 
45 class testselect_entity_visible : public scene::Graph::Walker {
46   Selector& _selector;
47   SelectionTest& _test;
48 public:
testselect_entity_visible(Selector & selector,SelectionTest & test)49   testselect_entity_visible(Selector& selector, SelectionTest& test)
50     : _selector(selector), _test(test) {}
51 
52   bool pre(const scene::Path& path, scene::Instance& instance) const;
53   void post(const scene::Path& path, scene::Instance& instance) const;
54 };
55 
56 class testselect_primitive_visible : public scene::Graph::Walker {
57   Selector& _selector;
58   SelectionTest& _test;
59 public:
testselect_primitive_visible(Selector & selector,SelectionTest & test)60   testselect_primitive_visible(Selector& selector, SelectionTest& test)
61     : _selector(selector), _test(test) {}
62 
63   bool pre(const scene::Path& path, scene::Instance& instance) const;
64   void post(const scene::Path& path, scene::Instance& instance) const;
65 };
66 
67 class testselect_component_visible : public scene::Graph::Walker {
68   Selector& _selector;
69   SelectionTest& _test;
70   SelectionSystem::EComponentMode _mode;
71 public:
testselect_component_visible(Selector & selector,SelectionTest & test,SelectionSystem::EComponentMode mode)72   testselect_component_visible(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
73     : _selector(selector), _test(test), _mode(mode) {}
74 
75   bool pre(const scene::Path& path, scene::Instance& instance) const;
76 };
77 
78 class testselect_component_visible_selected : public scene::Graph::Walker {
79   Selector& _selector;
80   SelectionTest& _test;
81   SelectionSystem::EComponentMode _mode;
82 public:
testselect_component_visible_selected(Selector & selector,SelectionTest & test,SelectionSystem::EComponentMode mode)83   testselect_component_visible_selected(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
84     : _selector(selector), _test(test), _mode(mode) {}
85 
86   bool pre(const scene::Path& path, scene::Instance& instance) const;
87 };
88 
89 // --------------------------------------------------------------------------------
90 
91 void Scene_TestSelect_Primitive(Selector& selector, SelectionTest& test, const VolumeTest& volume);
92 void Scene_TestSelect_Component(Selector& selector, SelectionTest& test, const VolumeTest& volume, SelectionSystem::EComponentMode componentMode);
93 void Scene_TestSelect_Component_Selected(Selector& selector, SelectionTest& test, const VolumeTest& volume, SelectionSystem::EComponentMode componentMode);
94 
ConstructSelectionTest(View & view,const SelectionRectangle & selection_box)95 inline void ConstructSelectionTest(View& view, const SelectionRectangle& selection_box) {
96 	view.EnableScissor(selection_box.min[0], selection_box.max[0],
97 						selection_box.min[1], selection_box.max[1]);
98 }
99