diff --git a/ViroRenderer/VROInputControllerBase.cpp b/ViroRenderer/VROInputControllerBase.cpp index f130c98..e4f12ac 100755 --- a/ViroRenderer/VROInputControllerBase.cpp +++ b/ViroRenderer/VROInputControllerBase.cpp @@ -27,43 +27,16 @@ #include "VROTime.h" #include "VROPortal.h" -static bool sSceneBackgroundAdd = true; static bool sHasHoverEvents = true; - VROInputControllerBase::VROInputControllerBase(std::shared_ptr driver) : _driver(driver) { _scene = nullptr; } -/** - * OnButtonEvents are triggered on both controller-level and node-level event delegates whenever - * button-specific events has been triggered on the underlying hardware (corresponding - * VROInputController). - * - * For the case of ClickDown and ClickUp events, delegates are triggered with a unique deviceId - * and sourceId. For the case of Clicked Events, delegates are only triggered iff the last ClickDown - * input event matches the last ClickUp input event in terms of deviceId and sourceId. Note that - * these are always triggered after a clickdown-clickup as a separate event. - * - * NOTE: It is important to know the slight difference into how delegates are triggered. - * - * Controller-Level Event Delegate: When triggered, contains ButtonEvents of ALL deviceIDs at - * that point in time. This is to provide developers a single point from which to base business - * logic that may be dependent on multiple inputs at multiple times. - * - * Node-Level Event Delegates: When triggered, contains the ButtonEvents coming from - * the controller (with a unique device Id) that has focused on the node. Thus, ClickDown, - * ClickUp, Clicked events were done intentionally for that node, from a given controller. - */ void VROInputControllerBase::onButtonEvent(std::vector &events) { std::map> eventsByControllerId; std::map clickedEvents; std::vector clickedEventsAll; - - // For each button event: - // - populate it with the cached hit point done for this controller id - // - if it's a clickDown event, update lastTrackedButtonEvent (used for determining clicked) - // - if it's a clickUp event, compare with lastTrackedButtonEvent for (VROEventDelegate::ButtonEvent &event : events) { // If no required hit result is found, we can't trigger button events. if (_deviceControllerState.find(event.deviceId) == _deviceControllerState.end()) { @@ -147,11 +120,9 @@ void VROInputControllerBase::onButtonEvent(std::vector &events, bool shouldUpdatehitTests) { - shouldUpdatehitTests = shouldUpdatehitTests || sHasHoverEvents; - +void VROInputControllerBase::onMove(std::vector &events) { // Update all device input's transforms. - if (shouldUpdatehitTests && _scene != nullptr) { + if (_scene != nullptr) { for (VROEventDelegate::MoveEvent event : events) { VROVector3f origin = event.pos; VROVector3f controllerForward = event.rot.getMatrix().multiply(kBaseForward); @@ -169,9 +140,6 @@ void VROInputControllerBase::onMove(std::vector &ev onHover(events); } -/** - * Hovered Events are only tracked per device Id. - */ void VROInputControllerBase::onHover(std::vector &events) { if (!sHasHoverEvents) { return; @@ -217,14 +185,16 @@ void VROInputControllerBase::onHover(std::vector &e // Also notify the last hovered node that we have hovered 'off'. std::shared_ptr lastTrackedOnHoveredNode = _deviceControllerState[event.deviceId].lastTrackedOnHoveredNode; + std::shared_ptr lastTrackedOnHoverEventNode = _deviceControllerState[event.deviceId].lastTrackedOnHoverEventNode; if (lastTrackedOnHoveredNode != onHoveredNode && lastTrackedOnHoveredNode != nullptr) { event.isHovering = false; std::vector events2 = {event}; - if (lastTrackedOnHoveredNode->getEventDelegate() != nullptr) { - lastTrackedOnHoveredNode->getEventDelegate()->onHover(events2); + if (lastTrackedOnHoverEventNode != nullptr && lastTrackedOnHoverEventNode->getEventDelegate() != nullptr) { + lastTrackedOnHoverEventNode->getEventDelegate()->onHover(events2); } } - _deviceControllerState[event.deviceId].lastTrackedOnHoveredNode = onHoverEventNode; + _deviceControllerState[event.deviceId].lastTrackedOnHoveredNode = onHoveredNode; + _deviceControllerState[event.deviceId].lastTrackedOnHoverEventNode = onHoverEventNode; } } diff --git a/ViroRenderer/VROInputControllerBase.h b/ViroRenderer/VROInputControllerBase.h index cf49029..6005afb 100755 --- a/ViroRenderer/VROInputControllerBase.h +++ b/ViroRenderer/VROInputControllerBase.h @@ -49,6 +49,15 @@ For example, VROInputControllerDaydream maps the onTouchPadClick event onto a Viro onPrimaryClick event type within VROInputControllerBase, of which then notifies all VROEventDelegates about such an event. + + NOTE: There is a slight difference into how delegates are triggered. + 1) Controller-Level Event Delegate: When triggered, contains the event of ALL deviceIDs sources at + that point in time. This is to provide developers a single snapshot point of events, where the + events are triggered on the Controller itself via internal delegates. + + 2) Node-Level Event Delegates: When triggered, contains the events pertaining to the node + that can handle the event via getNodeToHandleEvent(). This is applied for Click and Hover events + only, where for example, click events are triggered on the Node. */ class VROInputControllerBase { public: @@ -115,7 +124,7 @@ class VROInputControllerBase { } void onButtonEvent(std::vector &events); - void onMove(std::vector &events, bool shouldUpdateHitTests); + void onMove(std::vector &events); void onHover(std::vector &events); /* @@ -154,13 +163,13 @@ class VROInputControllerBase { */ std::shared_ptr hitResult; - /* Tracked Events for state */ std::shared_ptr lastTrackedButtonEvent; std::shared_ptr lastTrackedHoverEvent; std::shared_ptr lastTrackedOnHoveredNode; + std::shared_ptr lastTrackedOnHoverEventNode; } TouchControllerLeft, TouchControllerRight; diff --git a/ViroRenderer/VRONode.cpp b/ViroRenderer/VRONode.cpp index 7c57e58..3efeac1 100755 --- a/ViroRenderer/VRONode.cpp +++ b/ViroRenderer/VRONode.cpp @@ -627,16 +627,16 @@ void VRONode::applyConstraints(const VRORenderContext &context, VROMatrix4f pare updated = true; } - /* +/* std::shared_ptr p = context.getPencil(); - VROVector3f s = VROVector3f(_worldUmbrellaBoundingBox.getMinX(), _worldUmbrellaBoundingBox.getMinY(), _worldUmbrellaBoundingBox.getMinZ()); - VROVector3f l = VROVector3f(_worldUmbrellaBoundingBox.getMaxX(), _worldUmbrellaBoundingBox.getMaxY(), _worldUmbrellaBoundingBox.getMaxZ()); + VROVector3f s = VROVector3f(_worldBoundingBox.getMinX(), _worldBoundingBox.getMinY(), _worldBoundingBox.getMinZ()); + VROVector3f l = VROVector3f(_worldBoundingBox.getMaxX(), _worldBoundingBox.getMaxY(), _worldBoundingBox.getMaxZ()); p->draw({s.x, s.y, s.z}, {l.x, s.y, s.z}); p->draw({l.x, s.y, s.z}, {l.x, l.y, s.z}); p->draw({l.x, l.y, s.z}, {s.x, l.y, s.z}); p->draw({s.x, l.y, s.z}, {s.x, s.y, s.z}); - */ +*/ /* Move down the tree. */