Skip to content
Snippets Groups Projects
Select Git revision
  • 7dedccdb195077e01b5a390da26ad9b3b386f351
  • stable default protected
  • MA_Pape_2018
  • MA_2018_Lopatin
  • feature/mesh_viewer
  • feature/#468_access_isosurface_scalar
  • feature/#459_default_primitives
  • master protected
  • feature/#470_Create_a_color_lookup_table
  • feature/#473_resize_companion_window
  • feature/#462_do_not_use_arb_extensions
  • feature/#495_Provide_data_for_larger_isosurfaces
  • feature/#323_default_image
  • feature/#480_Create_a_smaller_test_mesh_for_combustion_demo
  • feature/#236_Get_Integration_tests_running_on_CI
  • feature/#447_Copy_standard_assets_to_build_folder
  • 447-copy-standard-assets-to-build-folder-and-remove-resource-path
  • feature/#445_mesh_render_settings_component
  • feature/#251_Make_sure_tests_cpp_is_compiled_once
  • feature/#455_Remove_navigation_and_improve_interaction_for_combustion_demo
  • feature/446_strange_txt_files
  • v18.06.0
  • v18.05.0
  • #251_bad
  • #251_good
  • v18.03.0
  • v18.02.0
  • v18.01.0
  • v17.12.0
  • v17.11.0
  • v17.10.0
  • v17.09.0
  • v17.07.0
33 results

laser_menu.cpp

Blame
  • Sebastian Pape's avatar
    Sebastian Pape authored
    7dedccdb
    History
    laser_menu.cpp 4.56 KiB
    #include "laser_menu.hpp"
    
    #include "menu_helper.hpp"
    #include "ray_pass.hpp"
    #include "selector.hpp"
    #include "text.hpp"
    
    #include "phx/rendering/components/material_handle.hpp"
    #include "phx/rendering/components/transform.hpp"
    #include "phx/rendering/rendering_system.hpp"
    #include "phx/resources/loaders/scene_loader.hpp"
    #include "phx/resources/resource_utils.hpp"
    #include "phx/resources/types/material.hpp"
    #include "phx/resources/types/model.hpp"
    #include "phx/suppress_warnings.hpp"
    
    SUPPRESS_WARNINGS_BEGIN
    #include "glm/glm.hpp"
    #include "glm/gtx/rotate_vector.hpp"
    #include "glm/gtx/string_cast.hpp"
    SUPPRESS_WARNINGS_END
    
    LaserMenu::LaserMenu(phx::Scene* scene, phx::Engine* engine) {
      entity_ = phx::SceneLoader::InsertModelIntoScene(
          "models/opticalBench/menu/Tablet.obj", scene);
    
      auto rayPass = engine->GetSystem<phx::RenderingSystem>()
                         ->GetFrameGraph()
                         ->GetRenderPasses<phx::RayPass>()
                         .at(0);
    
      auto image = phx::ResourceUtils::LoadResourceFromFile<phx::Image>(
          "models/opticalBench/menu/Screen_Laser.png");
      auto transform = entity_->GetFirstComponent<phx::Transform>();
      for (auto i = 0u; i < transform->GetChildCount(); i++) {
        auto handle = transform->GetChild(i)
                          ->GetEntity()
                          ->GetFirstComponent<phx::MaterialHandle>();
        if (handle->GetMaterial()->GetName().compare("Screen") == 0) {
          handle->SetMaterial(MenuHelper::cloneMaterial(handle->GetMaterial(),
                                                        "LaserMenuScreenMaterial"));
          handle->GetMaterial()->SetAmbientImage(image);
          break;
        }
      }
    
      MenuHelper::createButtonPairVertical(up_p_, down_p_, text_p_, -0.1f, -0.05f,
                                           scene, engine, entity_);
      up_p_->SetOnPress([rayPass, this](phx::Transform*, glm::mat4) {
        rayPass->NextLaserPattern();
        text_p_->SetText(rayPass->GetCurrentPatternName());
      });
      down_p_->SetOnPress([rayPass, this](phx::Transform*, glm::mat4) {
        rayPass->PreviousLaserPattern();
        text_p_->SetText(rayPass->GetCurrentPatternName());
      });
      text_p_->SetText(rayPass->GetCurrentPatternName());
    
      // TIR
      switch_tir_ = new MenuSwitch(engine, scene, rayPass->GetRayTIR());
      switch_tir_->SetOnSwitch([this, rayPass](bool a) {
        rayPass->setRayTIR(a);
        text_tir_->SetText((a ? "on" : "off"));
      });
      switch_tir_->GetTransform()->SetParent(
          entity_->GetFirstComponent<phx::Transform>(), false);
      switch_tir_->GetTransform()->SetLocalTranslation(
          glm::vec3(0.0f, -0.075f, 0.1f));
    
      auto text_entity = scene->CreateEntity();
      text_entity->AddComponent<phx::Transform>()
          ->Translate(glm::vec3(-0.001f, -0.05f, 0.1f))
          .SetLocalRotationEuler(glm::vec3(180, -90, 0))
          .SetParent(entity_->GetFirstComponent<phx::Transform>());
      text_tir_ = text_entity->AddComponent<phx::Text>("", 0.006f);
      text_tir_->SetText(((rayPass->GetRayTIR()) ? "on" : "off"));
      text_tir_->SetGradient(glm::vec4(0), glm::vec4(0));
    
      // target write
    
      switch_tw_ = new MenuSwitch(engine, scene, rayPass->getTargetBufferWrite());
      switch_tw_->SetOnSwitch([this, rayPass](bool a) {
        rayPass->setTargetBufferWrite(a);
        text_tw_->SetText((a ? "on" : "off"));
      });
      switch_tw_->GetTransform()->SetParent(
          entity_->GetFirstComponent<phx::Transform>(), false);
      switch_tw_->GetTransform()->SetLocalTranslation(
          glm::vec3(0.0f, -0.025f, 0.0f));
    
      auto text_entity2 = scene->CreateEntity();
      text_entity2->AddComponent<phx::Transform>()
          ->Translate(glm::vec3(-0.001f, -0.05f, 0.0f))
          .SetLocalRotationEuler(glm::vec3(180, -90, 0))
          .SetParent(entity_->GetFirstComponent<phx::Transform>());
      text_tw_ = text_entity2->AddComponent<phx::Text>("", 0.006f);
      text_tw_->SetText(((rayPass->getTargetBufferWrite()) ? "on" : "off"));
      text_tw_->SetGradient(glm::vec4(0), glm::vec4(0));
    
      // clear laser target
      clear_target_ = new MenuButton(engine, scene, MenuButton::RECTANGULAR);
      clear_target_->GetTransform()->SetParent(
          entity_->GetFirstComponent<phx::Transform>(), false);
      clear_target_->GetTransform()->SetLocalRotationEuler(glm::vec3(0, -90, 90));
      clear_target_->GetTransform()->SetLocalScale(glm::vec3(0.06f, 0.01f, 0.017f));
      clear_target_->GetTransform()->SetLocalTranslation(glm::vec3(0.0f,-0.075f,0.0f));
      clear_target_->SetHoldable(false);
      clear_target_->SetOnPress(
          [this, rayPass](phx::Transform*, glm::mat4) { rayPass->clearTargetBuffers(); });
    }
    
    LaserMenu::~LaserMenu() {
      delete switch_tir_;
      delete up_p_;
      delete down_p_;
      delete clear_target_;
      delete switch_tw_;
      delete text_tw_;
    }