Radium Engine  1.5.0
Gizmo.hpp
1 #pragma once
2 
3 #include <vector>
4 
5 #include <Core/Types.hpp>
6 #include <Core/Utils/Color.hpp>
7 #include <Core/Utils/Index.hpp>
8 
9 #include <Core/Asset/Camera.hpp>
10 #include <Engine/Data/RenderParameters.hpp>
11 #include <Engine/RadiumEngine.hpp>
12 #include <Engine/Rendering/RenderObject.hpp>
13 #include <Engine/Scene/CameraComponent.hpp>
14 
15 namespace Ra {
16 namespace Engine {
17 
18 namespace Data {
19 class PlainMaterial;
20 } // namespace Data
21 
22 namespace Scene {
23 class Component;
24 } // namespace Scene
25 
26 namespace Rendering {
27 class RenderTechnique;
28 class RenderObject;
29 } // namespace Rendering
30 } // namespace Engine
31 
32 namespace Gui {
41 class Gizmo
42 {
43  public:
44  enum Mode {
45  LOCAL,
46  GLOBAL,
47  };
48 
49  public:
50  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52  const Core::Transform& worldTo,
53  const Core::Transform& t,
54  Mode mode );
55 
56  virtual ~Gizmo();
57 
58  // shows or hides the gizmos drawables.
59  void show( bool on );
60 
62  virtual void
63  updateTransform( Mode mode, const Core::Transform& worldTo, const Core::Transform& t ) = 0;
64 
66  virtual void selectConstraint( int drawableIndex ) = 0;
67 
69  virtual bool isSelected() = 0;
70 
73  virtual void setInitialState( const Core::Asset::Camera& cam,
74  const Core::Vector2& initialXY ) = 0;
75 
78  virtual Core::Transform mouseMove( const Core::Asset::Camera& cam,
79  const Core::Vector2& nextXY,
80  bool stepped = false,
81  bool whole = false ) = 0;
82 
83  protected:
85  static bool findPointOnAxis( const Core::Asset::Camera& cam,
86  const Core::Vector3& origin,
87  const Core::Vector3& axis,
88  const Core::Vector2& pix,
89  Core::Vector3& pointOut,
90  std::vector<Scalar>& hits );
91 
93  static bool findPointOnPlane( const Core::Asset::Camera& cam,
94  const Core::Vector3& origin,
95  const Core::Vector3& axis,
96  const Core::Vector2& pix,
97  Core::Vector3& pointOut,
98  std::vector<Scalar>& hits );
99 
101  inline const std::vector<Engine::Rendering::RenderObject*>& ros() const { return m_ros; }
102 
105 
112  static std::shared_ptr<Engine::Rendering::RenderTechnique> makeRenderTechnique( int color );
113 
118  static std::array<std::shared_ptr<Ra::Engine::Data::PlainMaterial>, 3> s_material;
119 
120  protected:
121  Core::Transform m_worldTo;
122  Core::Transform m_transform;
124  Mode m_mode;
125 
136  {
137  public:
139  explicit UiSelectionControler(
140  std::shared_ptr<Ra::Engine::Data::PlainMaterial>& material,
141  const Core::Utils::Color& selectedColor = Core::Utils::Color::Yellow() );
142  UiSelectionControler() = delete;
143  UiSelectionControler( const UiSelectionControler& ) = delete;
144  ~UiSelectionControler() override = default;
146  void updateGL() override;
148  void toggleState();
150  void setState();
152  void clearState();
153 
154  private:
156  std::shared_ptr<Ra::Engine::Data::PlainMaterial> m_associatedMaterial;
158  Core::Utils::Color m_selectedColor;
160  bool m_selected { false };
161  };
162 
165 
166  private:
167  std::vector<Engine::Rendering::RenderObject*> m_ros;
168 };
169 } // namespace Gui
170 } // namespace Ra
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
Definition: Camera.hpp:16
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
void setState()
Set the state of the controler to true.
Definition: Gizmo.cpp:121
void toggleState()
Swap the state of the controler.
Definition: Gizmo.cpp:117
void clearState()
Set the state of the controler to false.
Definition: Gizmo.cpp:125
void updateGL() override
Inherited.
Definition: Gizmo.cpp:110
static std::array< std::shared_ptr< Ra::Engine::Data::PlainMaterial >, 3 > s_material
Definition: Gizmo.hpp:118
Mode m_mode
local or global.
Definition: Gizmo.hpp:124
virtual void updateTransform(Mode mode, const Core::Transform &worldTo, const Core::Transform &t)=0
Called every time the underlying transform may have changed.
static bool findPointOnAxis(const Core::Asset::Camera &cam, const Core::Vector3 &origin, const Core::Vector3 &axis, const Core::Vector2 &pix, Core::Vector3 &pointOut, std::vector< Scalar > &hits)
Find a mouse-designed point on a 3D axis.
Definition: Gizmo.cpp:51
Core::Transform m_worldTo
World to local space where the transform lives.
Definition: Gizmo.hpp:121
static bool findPointOnPlane(const Core::Asset::Camera &cam, const Core::Vector3 &origin, const Core::Vector3 &axis, const Core::Vector2 &pix, Core::Vector3 &pointOut, std::vector< Scalar > &hits)
Find a mouse-designed point on a 3D plane.
Definition: Gizmo.cpp:70
static std::shared_ptr< Engine::Rendering::RenderTechnique > makeRenderTechnique(int color)
Definition: Gizmo.cpp:88
virtual void selectConstraint(int drawableIndex)=0
Called when one of the drawables of the gizmo has been selected.
const std::vector< Engine::Rendering::RenderObject * > & ros() const
read access to the gizmo render objects id
Definition: Gizmo.hpp:101
Core::Transform m_transform
Transform to be edited.
Definition: Gizmo.hpp:122
void addRenderObject(Engine::Rendering::RenderObject *ro)
add a render object to display the Gizmo
Definition: Gizmo.cpp:83
virtual void setInitialState(const Core::Asset::Camera &cam, const Core::Vector2 &initialXY)=0
virtual bool isSelected()=0
return the selection state of the gizmo: true if the gizmo is selected, false if not.
Gizmo::UiSelectionControler * getControler(int ro)
Returns the controler (ShaderParametersProvider) associated to the given gizmo component.
Definition: Gizmo.cpp:97
virtual Core::Transform mouseMove(const Core::Asset::Camera &cam, const Core::Vector2 &nextXY, bool stepped=false, bool whole=false)=0
Engine::Scene::Component * m_comp
Engine Ui component.
Definition: Gizmo.hpp:123
Definition: Cage.cpp:3