more correct proxy classification for multiple views

This commit is contained in:
Andrew Meadows 2018-03-07 08:41:01 -08:00
parent 43920b548f
commit 03a5a6f4e0

View file

@ -62,10 +62,9 @@ void Space::copyViews(std::vector<View>& copy) const {
copy = _views;
}
// TODO?: move this to an algorithm/job?
void Space::categorizeAndGetChanges(std::vector<Space::Change>& changes) {
uint32_t numProxies = (uint32_t)_proxies.size();
uint32_t numViews = (uint32_t)_views.size();
uint32_t numProxies = _proxies.size();
uint32_t numViews = _views.size();
for (uint32_t i = 0; i < numProxies; ++i) {
Proxy& proxy = _proxies[i];
if (proxy.region < Region::INVALID) {
@ -74,21 +73,11 @@ void Space::categorizeAndGetChanges(std::vector<Space::Change>& changes) {
uint8_t region = Region::UNKNOWN;
for (uint32_t j = 0; j < numViews; ++j) {
auto& view = _views[j];
glm::vec3 distance2(glm::distance2(proxyCenter, glm::vec3(view.regions[0])), glm::distance2(proxyCenter, glm::vec3(view.regions[1])), glm::distance2(proxyCenter, glm::vec3(view.regions[2])));
glm::vec3 regionRadii2(view.regions[0].w + proxyRadius, view.regions[1].w + proxyRadius, view.regions[2].w + proxyRadius);
regionRadii2 *= regionRadii2;
auto touchTests = glm::lessThanEqual(distance2, regionRadii2);
if (glm::any(touchTests)) {
if (touchTests.x) {
region = Region::R1;
break;
} else if (touchTests.y) {
region = Region::R2;
break;
} else {
region = Region::R3;
// for each 'view' we need only increment 'k' below the current value of 'region'
for (uint8_t k = 0; k < region; ++k) {
float touchDistance = proxyRadius + view.regions[k].w;
if (distance2(proxyCenter, glm::vec3(view.regions[k])) < touchDistance * touchDistance) {
region = k;
break;
}
}
@ -124,10 +113,8 @@ void Space::deleteProxy(int32_t proxyId) {
}
uint32_t Space::copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const {
auto numCopied = std::min(numDestProxies, (uint32_t)_proxies.size());
memcpy(proxies, _proxies.data(), numCopied * sizeof(Proxy));
return numCopied;
}