Skip to content
Snippets Groups Projects
Commit b5eeb941 authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Added controller overlay (Filler Images for now)

parent 7dedccdb
Branches
No related tags found
No related merge requests found
Showing
with 345 additions and 9 deletions
//------------------------------------------------------------------------------
// Project Phoenix
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualization Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the 3-Clause BSD License (the "License");
// you may not use this file except in compliance with the License.
// See the file LICENSE for the full text.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
#include <string>
#include "controller_overlay.hpp"
#include "phx/rendering/components/material_handle.hpp"
#include "phx/rendering/components/transform.hpp"
#include "phx/resources/loaders/scene_loader.hpp"
#include "phx/resources/resource_utils.hpp"
#include "phx/resources/types/image.hpp"
#include "phx/suppress_warnings.hpp"
SUPPRESS_WARNINGS_BEGIN
#include "glm/gtc/matrix_transform.hpp"
SUPPRESS_WARNINGS_END
namespace phx {
ControllerOverlay::ControllerOverlay(phx::Entity* controller,
phx::Scene* scene) {
auto controller_overlay = phx::SceneLoader::InsertModelIntoScene(
"models/opticalBench/controller_overlay/Controller_Buttons.obj", scene);
controller_overlay->GetFirstComponent<phx::Transform>()->SetParent(
controller->GetFirstComponent<phx::Transform>());
// select entitys
auto transform = controller_overlay->GetFirstComponent<phx::Transform>();
for (auto i = 0u; i < transform->GetChildCount(); i++) {
auto entity = transform->GetChild(i)->GetEntity();
auto handle = entity->GetFirstComponent<phx::MaterialHandle>();
if (handle->GetMaterial()->GetName().compare("Grip_Left") == 0)
grip_left_ = entity;
else if (handle->GetMaterial()->GetName().compare("Grip_Right") == 0)
grip_right_ = entity;
else if (handle->GetMaterial()->GetName().compare("Trigger") == 0)
grip_trigger_ = entity;
else if (handle->GetMaterial()->GetName().compare("Trackpad") == 0)
grip_trackpad_ = entity;
}
// store/load images
grip_images_.push_back(grip_left_->GetFirstComponent<phx::MaterialHandle>()
->GetMaterial()
->GetAmbientImage());
grip_images_.push_back(phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/Grip_Select.png"));
grip_images_.push_back(phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/Grip1.png"));
grip_images_.push_back(phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/Grip2.png"));
grip_images_.push_back(phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/Grip3.png"));
trigger_images_.push_back(
grip_trigger_->GetFirstComponent<phx::MaterialHandle>()
->GetMaterial()
->GetAmbientImage());
trigger_images_.push_back(phx::ResourceUtils::LoadResourceFromFile<
phx::Image>(
"models/opticalBench/controller_overlay/menu_images/Trigger_Grab.png"));
trigger_images_.push_back(
phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/"
"Trigger_Grabbed.png"));
trackpad_images_.push_back(
grip_trackpad_->GetFirstComponent<phx::MaterialHandle>()
->GetMaterial()
->GetAmbientImage());
trackpad_images_.push_back(
phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
"models/opticalBench/controller_overlay/menu_images/"
"Trackpad_Rotate.png"));
}
std::string ControllerOverlay::ToString() const { return "Controller Overlay"; }
void ControllerOverlay::SetGripMode(GripMode m) {
if (m == current_grip_mode_) return;
switch (m) {
case EMPTY:
setEntityImage(grip_left_, grip_images_[3]);
setEntityImage(grip_right_, grip_images_[3]);
break;
case ROTATION:
setEntityImage(grip_left_, grip_images_[4]);
setEntityImage(grip_right_, grip_images_[4]);
break;
case TRANSLATION:
setEntityImage(grip_left_, grip_images_[2]);
setEntityImage(grip_right_, grip_images_[2]);
break;
case RESET:
setEntityImage(grip_left_, grip_images_[0]);
setEntityImage(grip_right_, grip_images_[0]);
break;
case SELECT:
setEntityImage(grip_left_, grip_images_[1]);
setEntityImage(grip_right_, grip_images_[1]);
break;
};
current_grip_mode_ = m;
}
void ControllerOverlay::SetTrackpadRotate(bool activate) {
if (activate == current_trackpad_rotate_) return;
if (activate) {
setEntityImage(grip_trackpad_, trackpad_images_[1]);
} else {
setEntityImage(grip_trackpad_, trackpad_images_[0]);
}
current_trackpad_rotate_ = activate;
}
void ControllerOverlay::SetTrackpadAngle(float angle) {
if (current_angle_ == angle) return;
grip_trackpad_->GetFirstComponent<phx::Transform>()->SetLocalMatrix(
glm::translate(glm::mat4(), glm::vec3(0, -0.00509f, 0.04835f)) *
glm::rotate(glm::mat4(), angle, glm::vec3(0, 0.9935f, 0.1138f)) *
glm::translate(glm::mat4(), glm::vec3(0, 0.00509f, -0.04835f)));
current_angle_ = angle;
}
void ControllerOverlay::SetTriggerMode(TriggerMode m) {
if (m == current_trigger_mode_) return;
switch (m) {
case NORMAL:
setEntityImage(grip_trigger_, trigger_images_[0]);
break;
case GRAB:
setEntityImage(grip_trigger_, trigger_images_[1]);
break;
case GRABBED:
setEntityImage(grip_trigger_, trigger_images_[2]);
break;
};
current_trigger_mode_ = m;
}
void phx::ControllerOverlay::setEntityImage(
phx::Entity* e, phx::ResourcePointer<phx::Image> i) {
e->GetFirstComponent<phx::MaterialHandle>()->GetMaterial()->SetAmbientImage(
i);
}
} // namespace phx
//------------------------------------------------------------------------------
// Project Phoenix
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualization Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the 3-Clause BSD License (the "License");
// you may not use this file except in compliance with the License.
// See the file LICENSE for the full text.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
#ifndef OPTICAL_BENCH_CONTROLLER_OVERLAY_HPP_
#define OPTICAL_BENCH_CONTROLLER_OVERLAY_HPP_
#include <functional>
#include <string>
#include <vector>
#include "phx/core/component.hpp"
#include "phx/core/entity.hpp"
#include "phx/core/scene.hpp"
#include "phx/resources/resource_pointer.hpp"
#include "phx/resources/types/image.hpp"
#include "phx/suppress_warnings.hpp"
namespace phx {
class ControllerOverlay : public Component {
public:
enum GripMode {
EMPTY = 0,
ROTATION = 1,
TRANSLATION = 2,
RESET = 3,
SELECT = 4
};
enum TriggerMode { NORMAL = 0, GRAB = 1, GRABBED = 2 };
explicit ControllerOverlay(phx::Entity* entity, phx::Scene* scene);
virtual ~ControllerOverlay() = default;
std::string ToString() const override;
void SetGripMode(GripMode m);
void SetTrackpadRotate(bool activate);
void SetTrackpadAngle(float angle);
void SetTriggerMode(TriggerMode m);
private:
phx::Entity* grip_left_;
phx::Entity* grip_right_;
phx::Entity* grip_trigger_;
phx::Entity* grip_trackpad_;
GripMode current_grip_mode_ = GripMode::RESET;
TriggerMode current_trigger_mode_ = TriggerMode::NORMAL;
bool current_grip_select_ = false;
bool current_trackpad_rotate_ = false;
float current_angle_ = 0.0f;
std::vector<phx::ResourcePointer<phx::Image>> grip_images_;
std::vector<phx::ResourcePointer<phx::Image>> trigger_images_;
std::vector<phx::ResourcePointer<phx::Image>> trackpad_images_;
void setEntityImage(phx::Entity* e, phx::ResourcePointer<phx::Image> i);
};
} // namespace phx
#endif // OPTICAL_BENCH_CONTROLLER_OVERLAY_HPP_
......@@ -21,6 +21,7 @@
//------------------------------------------------------------------------------
#include "hmd_navigation_behavior.hpp"
#include "controller_overlay.hpp"
#include "ray_pass.hpp"
#include "selection_mark_handler.hpp"
#include "selector.hpp"
......@@ -101,6 +102,11 @@ HMDNavigationBehavior::HMDNavigationBehavior(
phx::RuntimeComponent<phx::RIGHT_CONTROLLER>>()[0]
->GetFirstComponent<phx::Transform>();
auto controller_entity = scene_->GetEntitiesWithComponents<
phx::RuntimeComponent<phx::RIGHT_CONTROLLER>>()[0];
controller_overlay_ = controller_entity->AddComponent<phx::ControllerOverlay>(
controller_entity, scene);
// Prepare helpers
pointer_rod_ = phx::SceneLoader::InsertModelIntoScene(
"models/opticalBench/rod/pointerRod.obj", scene);
......@@ -135,7 +141,7 @@ void HMDNavigationBehavior::OnUpdate() {
static bool trigger_pressed = false;
// Change selected or grabbed entities
// Change selected or hovered entities
if (right_controller_->GetAxesValue(phx::VRController::AXES_TRIGGER).x ==
1.0f) {
if (!trigger_pressed) { // Trigger pressed
......@@ -153,20 +159,54 @@ void HMDNavigationBehavior::OnUpdate() {
}
// update rotator
static float angle = 0;
if (last_selected_ != nullptr &&
last_selected_->GetFirstComponent<phx::TurnHandler>() != nullptr) {
last_selected_->GetFirstComponent<phx::TurnHandler>()->Turn(
getTouchpadRotationDelta());
controller_overlay_->SetTrackpadRotate(true);
float delta = getTouchpadRotationDelta();
last_selected_->GetFirstComponent<phx::TurnHandler>()->Turn(delta);
angle += delta;
} else {
controller_overlay_->SetTrackpadRotate(false);
angle = 0;
}
controller_overlay_->SetTrackpadAngle(-angle);
if (select_->GetIntersectionDistance() < INFINITY &&
select_->GetIntersectionDistance() > 0.05f) {
select_->GetIntersectionDistance() >= 0.0f) {
pointer_rod_->GetFirstComponent<phx::Transform>()->SetLocalScale(
glm::vec3(1, 1, select_->GetIntersectionDistance()));
glm::vec3(1, 1, select_->GetIntersectionDistance() + 0.015f)); //+15mm
} else {
pointer_rod_->GetFirstComponent<phx::Transform>()->SetLocalScale(
glm::vec3(1, 1, 0.05f));
}
// Change Grip Images
if (!trigger_pressed) {
if (manipulationHelperAttachable(select_->GetHovered())) {
controller_overlay_->SetGripMode(phx::ControllerOverlay::SELECT);
} else if (last_selected_ == nullptr) {
controller_overlay_->SetGripMode(phx::ControllerOverlay::RESET);
} else if (last_selected_ != nullptr &&
manipulationHelperAttachable(last_selected_)) {
controller_overlay_->SetGripMode(
static_cast<phx::ControllerOverlay::GripMode>(grip_mode % 3));
}
} else {
controller_overlay_->SetGripMode(phx::ControllerOverlay::RESET);
}
// Change Trigger Images
if (trigger_pressed && select_->GetGrabbed() != nullptr &&
select_->GetGrabbed()->GetFirstComponent<phx::Selector>() != nullptr) {
controller_overlay_->SetTriggerMode(phx::ControllerOverlay::GRABBED);
} else if (!trigger_pressed && select_->GetHovered() != nullptr &&
select_->GetHovered()->GetFirstComponent<phx::Selector>() !=
nullptr) {
controller_overlay_->SetTriggerMode(phx::ControllerOverlay::GRAB);
} else {
controller_overlay_->SetTriggerMode(phx::ControllerOverlay::NORMAL);
}
}
void HMDNavigationBehavior::update_helpers() {
......@@ -262,15 +302,22 @@ void HMDNavigationBehavior::updateInsersectionData() {
void HMDNavigationBehavior::buttonChange(
phx::VRController::ButtonId& id, phx::VRController::ButtonEvent& event) {
if (id == phx::VRController::ButtonId::k_EButton_Grip &&
event == phx::VRController::ButtonEvent::BUTTON_PRESSED &&
select_->GetGrabbed() == nullptr) {
if (select_->GetHovered() == nullptr) {
event == phx::VRController::ButtonEvent::BUTTON_PRESSED) {
if (select_->GetHovered() == nullptr &&
manipulationHelperAttachable(last_selected_)) {
grip_mode = grip_mode + 1 % 3;
update_helpers();
} else {
setLastSelected(select_->GetHovered());
update_helpers();
if (grip_mode == 0) grip_mode = 1; // Hover without feedback sucks
update_helpers();
}
}
}
bool HMDNavigationBehavior::manipulationHelperAttachable(phx::Entity* e) {
return e != nullptr && e->GetFirstComponent<phx::Selector>() != nullptr &&
e->GetFirstComponent<phx::Selector>()->manipulation_helper_attachable_;
}
......@@ -23,6 +23,7 @@
#ifndef OPTICAL_BENCH_HMD_NAVIGATION_BEHAVIOR_HPP_
#define OPTICAL_BENCH_HMD_NAVIGATION_BEHAVIOR_HPP_
#include "controller_overlay.hpp"
#include "phx/core/engine.hpp"
#include "phx/core/entity.hpp"
#include "phx/core/scene.hpp"
......@@ -65,6 +66,7 @@ class HMDNavigationBehavior : public phx::Behavior {
phx::VRController* right_controller_;
phx::Transform* right_controller_transform_;
phx::ControllerOverlay* controller_overlay_;
unsigned int grip_mode = 0;
void update_helpers();
......@@ -78,6 +80,7 @@ class HMDNavigationBehavior : public phx::Behavior {
void updateInsersectionData();
void buttonChange(phx::VRController::ButtonId& id,
phx::VRController::ButtonEvent& event);
bool manipulationHelperAttachable(phx::Entity* e);
};
#endif // OPTICAL_BENCH_HMD_NAVIGATION_BEHAVIOR_HPP_
resources/models/opticalBench/controller_overlay/Button_Menu.png

129 B

resources/models/opticalBench/controller_overlay/Button_Power.png

129 B

Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
resources/models/opticalBench/controller_overlay/Grip.png

129 B

resources/models/opticalBench/controller_overlay/Trackpad.png

129 B

resources/models/opticalBench/controller_overlay/Trigger.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Grip1.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Grip2.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Grip3.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Grip_Select.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Trackpad_Rotate.png

130 B

resources/models/opticalBench/controller_overlay/menu_images/Trigger_Grab.png

129 B

resources/models/opticalBench/controller_overlay/menu_images/Trigger_Grabbed.png

129 B

File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment