File: SelectionPolicies.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (139 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#pragma once

#include "math/AABB.h"
#include "ilightnode.h"
#include "iorthoview.h"

/**
  SelectionPolicy for SelectByBounds
  Returns true if
*/
class SelectionPolicy_Complete_Tall
{
public:
	bool evaluate(const AABB& box, const scene::INodePtr& node) const
	{
		// Get the AABB of the visited instance
		AABB other = node->worldAABB();

		// greebo: Perform a special selection test for lights
		// as the small diamond should be tested against selection only
		ILightNodePtr light = Node_getLightNode(node);

		if (light )
		{
			other = light->getSelectAABB();
		}

		// Determine the viewtype
		OrthoOrientation viewType = GlobalOrthoViewManager().getActiveViewType();

		unsigned int axis1 = 0;
		unsigned int axis2 = 1;

		// Determine which axes have to be compared
		switch (viewType) {
			case OrthoOrientation::XY:
				axis1 = 0;
				axis2 = 1;
			break;
			case OrthoOrientation::YZ:
				axis1 = 1;
				axis2 = 2;
			break;
			case OrthoOrientation::XZ:
				axis1 = 0;
				axis2 = 2;
			break;
		};

		// Check if the AABB is contained
		auto dist1 = fabs(other.origin[axis1] - box.origin[axis1]) + fabs(other.extents[axis1]);
		auto dist2 = fabs(other.origin[axis2] - box.origin[axis2]) + fabs(other.extents[axis2]);

		return (dist1 < fabs(box.extents[axis1]) && dist2 < fabs(box.extents[axis2]));
	}
};

/**
  SelectionPolicy for SelectByBounds
  Returns true if box and the AABB of instance intersect
*/
class SelectionPolicy_Touching
{
public:
	bool evaluate(const AABB& box, const scene::INodePtr& node) const {
		const AABB& other(node->worldAABB());

		for (unsigned int i = 0; i < 3; ++i) {
            if (std::abs(box.origin[i] - other.origin[i]) > (box.extents[i] + other.extents[i])) {
				return false;
			}
		}

		return true;
	}
};

/**
  SelectionPolicy for SelectByBounds
  Returns true if the AABB of instance is inside box
*/
class SelectionPolicy_Inside
{
public:
	bool evaluate(const AABB& box, const scene::INodePtr& node) const
	{
		AABB other = node->worldAABB();

		// greebo: Perform a special selection test for lights
		// as the small diamond should be tested against selection only
		ILightNodePtr light = Node_getLightNode(node);

		if (light )
		{
			other = light->getSelectAABB();
		}

		for (unsigned int i = 0; i < 3; ++i) {
			if (std::abs(box.origin[i] - other.origin[i]) > (box.extents[i] - other.extents[i])) {
				return false;
			}
		}

		return true;
	}
};

/**
  SelectionPolicy for SelectByBounds
  Returns true if the AABB of instance is completely inside box.
  Bounding boxes with their planes flush on the selection box are discarded.
*/
class SelectionPolicy_FullyInside
{
public:
    bool evaluate(const AABB& box, const scene::INodePtr& node) const
    {
        AABB other = node->worldAABB();

        // greebo: Perform a special selection test for lights
        // as the small diamond should be tested against selection only
        ILightNodePtr light = Node_getLightNode(node);

        if (light)
        {
            other = light->getSelectAABB();
        }

        for (unsigned int i = 0; i < 3; ++i)
        {
            if (std::abs(box.origin[i] - other.origin[i]) >= (box.extents[i] - other.extents[i]))
            {
                return false;
            }
        }

        return true;
    }
};