From 1aedbec4d71f4adc10ca73d508ee674bcfaf8f29 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 1 Apr 2019 13:13:41 -0500 Subject: [PATCH] Get landscape app to respond to clicks --- demo/magicleap/manifest.xml | 5 ++ demo/magicleap/src/landscape.cpp | 97 +++++++++++++++++++++++++++++--- demo/magicleap/src/landscape.h | 11 +++- 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index 80240ff1..9ed77b74 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -24,6 +24,11 @@ ml:visible_name="Pathfinder Immersive Demo" ml:binary_name="bin/PathfinderImmersiveDemo" ml:type="Fullscreen"> + + + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 7b0d52d8..4f60dbd9 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -17,12 +19,10 @@ int main(int argc, char **argv) return myApp.run(); } -const char* QUAD_NAMES[1] = { - "quad1" -}; +const int NUM_QUADS = 1; -const char* PANEL_NAMES[1] = { - "uiPanel1" +const char* QUAD_NAMES[NUM_QUADS] = { + "quad1" }; PathfinderDemo::PathfinderDemo() { @@ -84,6 +84,7 @@ int PathfinderDemo::init() { return 1; } + /* // Create the EGL surface for it to draw to lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); if (!plane_id) { @@ -98,6 +99,7 @@ int PathfinderDemo::init() { return 1; } quad_node->setRenderResource(plane_id); + */ return 0; } @@ -141,21 +143,34 @@ bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { // Place your event handling here. lumin::ServerEventType typ = event->getServerEventType(); switch (typ) { - case lumin::ServerEventType::kControlPose6DofInputEvent: + case lumin::ServerEventType::kControlPose6DofInputEvent: { requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); return false; + } case lumin::ServerEventType::kRayCastEvent: { lumin::RayCastEventData* raycast_event = static_cast(event); std::shared_ptr raycast_result = raycast_event->getHitData(); switch (raycast_result->getType()) { case lumin::RaycastResultType::kQuadNode: { std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); - focus_node = quad_result->getNodeId(); + focus_node_ = quad_result->getNodeId(); return false; } - default: - focus_node = lumin::INVALID_NODE_ID; + default: { + focus_node_ = lumin::INVALID_NODE_ID; return false; + } + } + } + case lumin::ServerEventType::kGestureInputEvent: { + lumin::GestureInputEventData* gesture_event = static_cast(event); + switch (gesture_event->getGesture()) { + case lumin::input::GestureType::TriggerClick: { + return onClick(); + } + default: { + return false; + } } } default: @@ -163,3 +178,67 @@ bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { } } +bool PathfinderDemo::onClick() { + lumin::RootNode* root_node = prism_->getRootNode(); + for (int i=0; ifindNode(QUAD_NAMES[i], root_node); + if (node->getNodeId() == focus_node_) { + dispatch(svg_filenames_[i]); + return true; + } + } + return false; +} + +void PathfinderDemo::dispatch(char* svg_filename) { + ML_LOG(Info, "Dispatching %s", svg_filename); + + MLDispatchPacket* dispatcher; + if (MLResult_Ok != MLDispatchAllocateEmptyPacket(&dispatcher)) { + ML_LOG(Error, "Failed to allocate dispatcher"); + return; + } + + if (MLResult_Ok != MLDispatchAllocateFileInfoList(dispatcher, 1)) { + ML_LOG(Error, "Failed to allocate file info list"); + return; + } + + MLFileInfo* file_info; + if (MLResult_Ok != MLDispatchGetFileInfoByIndex(dispatcher, 0, &file_info)) { + ML_LOG(Error, "Failed to get file info"); + return; + } + + if (MLResult_Ok != MLFileInfoSetFileName(file_info, svg_filename)) { + ML_LOG(Error, "Failed to set filename"); + return; + } + + if (MLResult_Ok != MLFileInfoSetMimeType(file_info, "image/svg")) { + ML_LOG(Error, "Failed to set mime type"); + return; + } + + if (MLResult_Ok != MLDispatchAddFileInfo(dispatcher, file_info)) { + ML_LOG(Error, "Failed to add file info"); + return; + } + + MLResult result = MLDispatchTryOpenApplication(dispatcher); + if (MLResult_Ok != result) { + ML_LOG(Error, "Failed to dispatch: %s", MLDispatchGetResultString(result)); + return; + } + + // https://forum.magicleap.com/hc/en-us/community/posts/360043198492-Calling-MLDispatchReleaseFileInfoList-causes-a-dynamic-link-error + // if (MLResult_Ok != MLDispatchReleaseFileInfoList(dispatcher, false)) { + // ML_LOG(Error, "Failed to deallocate file info list"); + // return; + // } + + if (MLResult_Ok != MLDispatchReleasePacket(&dispatcher, false, false)) { + ML_LOG(Error, "Failed to deallocate dispatcher"); + return; + } +} diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index a4191e32..40833f67 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -83,10 +83,15 @@ protected: void spawnInitialScenes(); /** - * Respond to a cube face being activated + * Respond to a click */ - void onActivate(int face); + bool onClick(); + /** + * Dispatch an SVG file to the immersive app + */ + void dispatch(char* svg_filename); + /** * Run application login */ @@ -102,7 +107,7 @@ private: PrismSceneManager* prismSceneManager_ = nullptr; uint64_t svg_filecount_ = 0; char** svg_filenames_ = nullptr; - lumin::NodeIDType focus_node = lumin::INVALID_NODE_ID; + lumin::NodeIDType focus_node_ = lumin::INVALID_NODE_ID; }; extern "C" uint64_t magicleap_pathfinder_svg_filecount();