Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BP_Scene.cpp « broad « src « solid « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0cd83ba3112df8ec86f13ff6eb160696b19362b (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * SOLID - Software Library for Interference Detection
 * 
 * Copyright (C) 2001-2003  Dtecta.  All rights reserved.
 *
 * This library may be distributed under the terms of the Q Public License
 * (QPL) as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * This library may be distributed and/or modified under the terms of the
 * GNU General Public License (GPL) version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Commercial use or any other use of this library not covered by either 
 * the QPL or the GPL requires an additional license from Dtecta. 
 * Please contact info@dtecta.com for enquiries about the terms of commercial
 * use of this library.
 */

#include "BP_Scene.h"
#include "BP_Proxy.h"

#include <algorithm>

BP_Proxy *BP_Scene::createProxy(void *object, 
								const DT_Vector3 min,
								const DT_Vector3 max)
{
	BP_Proxy *proxy = new BP_Proxy(object, *this);

	proxy->add(min, max, m_proxies);
	
	BP_ProxyList::iterator it;
	for (it = m_proxies.begin(); it != m_proxies.end(); ++it)
	{
		if ((*it).second == 3)
		{
			callBeginOverlap(proxy->getObject(), (*it).first->getObject());
		}
	}

	m_proxies.clear();

	return proxy;
}

void BP_Scene::destroyProxy(BP_Proxy *proxy)
{
	proxy->remove(m_proxies);
	
	BP_ProxyList::iterator it;
	for (it = m_proxies.begin(); it != m_proxies.end(); ++it)
	{
		if ((*it).second == 3)
		{
			callEndOverlap(proxy->getObject(), (*it).first->getObject());
		}
	}
	
	m_proxies.clear();

	delete proxy;
}

void *BP_Scene::rayCast(BP_RayCastCallback objectRayCast,
						void *client_data,
						const DT_Vector3 source, 
						const DT_Vector3 target, 
						DT_Scalar& lambda) const 
{
	void *client_object = 0;
	
	DT_Index index[3];
	index[0] = m_endpointList[0].stab(source[0], m_proxies);
	index[1] = m_endpointList[1].stab(source[1], m_proxies);
	index[2] = m_endpointList[2].stab(source[2], m_proxies);

	BP_ProxyList::iterator it;
	for (it = m_proxies.begin(); it != m_proxies.end(); ++it) 
	{
		if ((*it).second == 3 &&
            (*objectRayCast)(client_data, (*it).first->getObject(), source, target, &lambda))
		{
			client_object = (*it).first->getObject();
		}
	}

	DT_Vector3 delta;
	delta[0] = target[0] - source[0];
	delta[1] = target[1] - source[1];
	delta[2] = target[2] - source[2];
	
	DT_Vector3 lambdas;
	lambdas[0] = m_endpointList[0].nextLambda(index[0], source[0], delta[0]);
	lambdas[1] = m_endpointList[1].nextLambda(index[1], source[1], delta[1]);
	lambdas[2] = m_endpointList[2].nextLambda(index[2], source[2], delta[2]);
	int closest = lambdas[0] < lambdas[1] ? (lambdas[0] < lambdas[2] ? 0 : 2) : (lambdas[1] < lambdas[2] ? 1 : 2);
	
	while (lambdas[closest] < lambda)
	{
		if (delta[closest] < 0.0f)
		{
			const BP_Endpoint& endpoint = m_endpointList[closest][index[closest]];

			if (endpoint.getType() == BP_Endpoint::MAXIMUM) 
			{
				it = m_proxies.add(endpoint.getProxy());
				if ((*it).second == 3 &&
					(*objectRayCast)(client_data, (*it).first->getObject(), source, target, &lambda))
				{
					client_object = (*it).first->getObject();
				}
			}
			else
			{
				m_proxies.remove(endpoint.getProxy());
			}
		}
		else 
		{
			const BP_Endpoint& endpoint = m_endpointList[closest][index[closest] - 1];
			
			if (endpoint.getType() == BP_Endpoint::MINIMUM) 
			{
				it = m_proxies.add(endpoint.getProxy());
				if ((*it).second == 3 &&
					(*objectRayCast)(client_data, (*it).first->getObject(), source, target, &lambda))
				{
					client_object = (*it).first->getObject();
				}
			}
			else
			{
				m_proxies.remove(endpoint.getProxy());
			}
		}

		lambdas[closest] = m_endpointList[closest].nextLambda(index[closest], source[closest], delta[closest]);
		closest = lambdas[0] < lambdas[1] ?	(lambdas[0] < lambdas[2] ? 0 : 2) : (lambdas[1] < lambdas[2] ? 1 : 2);
	}

	m_proxies.clear();

	return client_object;
}