From 4709a3061d96d661040e56b9af3035493bdc8793 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 12 Aug 2019 11:26:46 -0500 Subject: [PATCH] Use the built-in laser pointer for magicleap --- support/magicleap/Servo2D/Servo2D.mlproject | 4 +-- .../Servo2D/code/inc.gen/Servo2D/Servo2D.h | 3 --- support/magicleap/Servo2D/code/inc/Servo2D.h | 5 ++-- .../Servo2D/code/src.gen/Servo2D/Servo2D.cpp | 11 +------- .../magicleap/Servo2D/code/src.gen/scenes.cpp | 4 +-- .../magicleap/Servo2D/code/src/Servo2D.cpp | 27 ++++--------------- .../Servo2D/pipeline/lap/project.json | 2 +- .../magicleap/Servo2D/scenes/Servo2D.design | 18 +------------ .../Servo2D/scenes/Servo2D.scene.xml | 3 +-- 9 files changed, 15 insertions(+), 62 deletions(-) diff --git a/support/magicleap/Servo2D/Servo2D.mlproject b/support/magicleap/Servo2D/Servo2D.mlproject index 8ae20de661a2c..d0cc2e92d77ac 100644 --- a/support/magicleap/Servo2D/Servo2D.mlproject +++ b/support/magicleap/Servo2D/Servo2D.mlproject @@ -2,9 +2,9 @@ + + - - \ No newline at end of file diff --git a/support/magicleap/Servo2D/code/inc.gen/Servo2D/Servo2D.h b/support/magicleap/Servo2D/code/inc.gen/Servo2D/Servo2D.h index 1ed3d155f5a8e..aea4afe8ff8c8 100644 --- a/support/magicleap/Servo2D/code/inc.gen/Servo2D/Servo2D.h +++ b/support/magicleap/Servo2D/code/inc.gen/Servo2D/Servo2D.h @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -40,7 +39,6 @@ namespace scenes { extern const std::string backButton; extern const std::string fwdButton; extern const std::string urlBar; - extern const std::string laser; } struct SpawnedScene : public SpawnedSceneBase { @@ -51,7 +49,6 @@ namespace scenes { lumin::ui::UiButton* backButton; lumin::ui::UiButton* fwdButton; lumin::ui::UiTextEdit* urlBar; - lumin::LineNode* laser; }; SpawnedSceneBase* createSpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root); diff --git a/support/magicleap/Servo2D/code/inc/Servo2D.h b/support/magicleap/Servo2D/code/inc/Servo2D.h index 2c1e0c8fd9af2..46962855dfecc 100644 --- a/support/magicleap/Servo2D/code/inc/Servo2D.h +++ b/support/magicleap/Servo2D/code/inc/Servo2D.h @@ -124,9 +124,10 @@ class Servo2D : public lumin::LandscapeApp { bool pointInsideViewport(glm::vec2 pt); /** - * Redraw the laser. Returns the laser endpoint, in viewport coordinates. + * Returns the intersection of the laser and the viewport, in viewport coordinates. + * Returns (-1, -1) if the laser does not intersect the viewport. */ - glm::vec2 redrawLaser(); + glm::vec2 laserPosition(); private: lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. diff --git a/support/magicleap/Servo2D/code/src.gen/Servo2D/Servo2D.cpp b/support/magicleap/Servo2D/code/src.gen/Servo2D/Servo2D.cpp index c8b6db955529c..5a57bb947aed6 100644 --- a/support/magicleap/Servo2D/code/src.gen/Servo2D/Servo2D.cpp +++ b/support/magicleap/Servo2D/code/src.gen/Servo2D/Servo2D.cpp @@ -34,7 +34,6 @@ namespace scenes { backButton = lumin::ui::UiButton::CastFrom(root->findChild(externalNodes::backButton)); fwdButton = lumin::ui::UiButton::CastFrom(root->findChild(externalNodes::fwdButton)); urlBar = lumin::ui::UiTextEdit::CastFrom(root->findChild(externalNodes::urlBar)); - laser = lumin::LineNode::CastFrom(root->findChild(externalNodes::laser)); } SpawnedScene::~SpawnedScene() { @@ -73,10 +72,6 @@ namespace scenes { urlBarHandlers(SpawnedScene& ss); }; urlBarHandlers urlBarHandlers_; - struct laserHandlers { - laserHandlers(SpawnedScene& ss); - }; - laserHandlers laserHandlers_; }; Handlers::contentPanelHandlers::contentPanelHandlers(SpawnedScene& ss) @@ -94,9 +89,6 @@ namespace scenes { Handlers::urlBarHandlers::urlBarHandlers(SpawnedScene& ss) { } - Handlers::laserHandlers::laserHandlers(SpawnedScene& ss) - { - } Handlers::Handlers(SpawnedScene& ss) : SpawnedSceneHandlers(ss), @@ -104,8 +96,7 @@ namespace scenes { contentHandlers_(ss), backButtonHandlers_(ss), fwdButtonHandlers_(ss), - urlBarHandlers_(ss), - laserHandlers_(ss) + urlBarHandlers_(ss) { } diff --git a/support/magicleap/Servo2D/code/src.gen/scenes.cpp b/support/magicleap/Servo2D/code/src.gen/scenes.cpp index 2728270cd6ca7..4281ecfacd0d7 100644 --- a/support/magicleap/Servo2D/code/src.gen/scenes.cpp +++ b/support/magicleap/Servo2D/code/src.gen/scenes.cpp @@ -33,7 +33,6 @@ namespace scenes { extern const std::string backButton = "backButton"; extern const std::string fwdButton = "fwdButton"; extern const std::string urlBar = "urlBar"; - extern const std::string laser = "laser"; } const SceneDescriptor::ExternalNodeReferences externalNodesMap = { @@ -41,8 +40,7 @@ namespace scenes { {"content", externalNodes::content}, {"backButton", externalNodes::backButton}, {"fwdButton", externalNodes::fwdButton}, - {"urlBar", externalNodes::urlBar}, - {"laser", externalNodes::laser} + {"urlBar", externalNodes::urlBar} }; const SceneDescriptor descriptor( diff --git a/support/magicleap/Servo2D/code/src/Servo2D.cpp b/support/magicleap/Servo2D/code/src/Servo2D.cpp index 7dfc8a4369390..062a6411e4e6d 100644 --- a/support/magicleap/Servo2D/code/src/Servo2D.cpp +++ b/support/magicleap/Servo2D/code/src/Servo2D.cpp @@ -25,9 +25,9 @@ const int VIEWPORT_H = 500; const float HIDPI = 1.0; // The prism dimensions (in m). -const float PRISM_W = 2.0; +const float PRISM_W = 0.75; const float PRISM_H = 0.75; -const float PRISM_D = 2.0; +const float PRISM_D = 0.05; // The length of the laser pointer (in m). const float LASER_LENGTH = 10.0; @@ -226,14 +226,6 @@ int Servo2D::init() { url_bar_->setKeyboardProperties(keyboard_properties); url_bar_->onFocusLostSub(std::bind(&Servo2D::urlBarEventListener, this)); - // Add the laser pointer - laser_ = lumin::LineNode::CastFrom(prism_->findNode(scenes::Servo2D::externalNodes::laser, root_node)); - if (!laser_) { - ML_LOG(Error, "Servo2D Failed to get laser"); - abort(); - return 1; - } - return 0; } @@ -264,7 +256,7 @@ void Servo2D::spawnInitialScenes() { } bool Servo2D::updateLoop(float fDelta) { - glm::vec2 pos = redrawLaser(); + glm::vec2 pos = laserPosition(); move_servo(servo_, pos.x, pos.y); heartbeat_servo(servo_); return true; @@ -311,7 +303,7 @@ bool Servo2D::pose6DofEventListener(lumin::ControlPose6DofInputEventData* event) return false; } -glm::vec2 Servo2D::redrawLaser() { +glm::vec2 Servo2D::laserPosition() { // Return (-1, -1) if the laser doesn't intersect z=0 glm::vec2 result = glm::vec2(-1.0, -1.0); @@ -333,18 +325,9 @@ glm::vec2 Servo2D::redrawLaser() { float ratio = 1.0 / (1.0 - (endpoint.z / position.z)); // The intersection point glm::vec3 intersection = ((1 - ratio) * position) + (ratio * endpoint); - // Is the intersection inside the viewport? result = viewportPosition(intersection); - if (pointInsideViewport(result)) { - color = glm::vec4(0.0, 1.0, 0.0, 1.0); - endpoint = intersection; - } } - laser_->clearPoints(); - laser_->addPoints(position); - laser_->addPoints(endpoint); - laser_->setColor(color); return result; } @@ -356,7 +339,7 @@ bool Servo2D::gestureEventListener(lumin::GestureInputEventData* event) { } // Only respond to trigger down if the laser is currently in the viewport - glm::vec2 pos = redrawLaser(); + glm::vec2 pos = laserPosition(); if ((typ == lumin::input::GestureType::TriggerDown) && !pointInsideViewport(pos)) { return false; } diff --git a/support/magicleap/Servo2D/pipeline/lap/project.json b/support/magicleap/Servo2D/pipeline/lap/project.json index 50368388ec7a8..67b9df0aa7247 100644 --- a/support/magicleap/Servo2D/pipeline/lap/project.json +++ b/support/magicleap/Servo2D/pipeline/lap/project.json @@ -22,7 +22,7 @@ "lap/types/file/png" ] }, - "checkpoint-hash": "b1a5b4c3dfe7a6c0a3068dd837adfa07364f5016ddef9e6698090ba3544ccf921abba715182f372e25d65a9b6b13fdf11f12e436482cc3bace76f56876bd2251", + "checkpoint-hash": "729ed9ee48ecc992e1906080e20f43fdc3f3b2a4cd76cdfc2bc249bfca1d9403b967ed1a6805b0b8c0e46a0bfd3d71c0a6a00fd7da651beef65f7431b7b314b3", "templates": [ "lap/template/passthru_material_from_kmat", "lap/template/passthru_model_from_fbx", diff --git a/support/magicleap/Servo2D/scenes/Servo2D.design b/support/magicleap/Servo2D/scenes/Servo2D.design index 583f7440eba54..a89d87b21563a 100644 --- a/support/magicleap/Servo2D/scenes/Servo2D.design +++ b/support/magicleap/Servo2D/scenes/Servo2D.design @@ -4,6 +4,7 @@ + @@ -152,23 +153,6 @@ - - - - - - - - - - - - - - - - - diff --git a/support/magicleap/Servo2D/scenes/Servo2D.scene.xml b/support/magicleap/Servo2D/scenes/Servo2D.scene.xml index f542b2611db7b..20c6006e1b88d 100644 --- a/support/magicleap/Servo2D/scenes/Servo2D.scene.xml +++ b/support/magicleap/Servo2D/scenes/Servo2D.scene.xml @@ -1,6 +1,6 @@ - + @@ -14,6 +14,5 @@ -