Pioneer
ModelSpinner.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #pragma once
5 
6 #include "RefCounted.h"
7 #include "graphics/Light.h"
8 
9 namespace Graphics {
10  class RenderTarget;
11 }
12 
13 // Forward declare this type from imgui.h
14 using ImTextureID = void *;
15 
16 #include "Shields.h"
17 #include "scenegraph/Model.h"
18 #include "scenegraph/ModelSkin.h"
19 
20 // TODO:
21 // - make this code reusable across multiple usecases (camera, rear-view mirror, UI preview, etc.)
22 // - Render more than a single model, e.g. attachments / equipment / shields (a scene, scenegraph hierarchy, etc.)
23 // - Add support for the usual post-processing chain (integrate with regular scene rendering)
24 // In essence, we want to make the regular main-scene rendering code modular and able to render
25 // arbitrary scenes to RTs that we can use in Pigui et. al.
26 // For now we'll do a basic implementation here to move the model spinner functionality to Pigui.
27 namespace PiGui {
28  class ModelSpinner : public RefCounted {
29  public:
30  ModelSpinner();
31 
32  // Set the ship we should be looking at.
33  void SetModel(SceneGraph::Model *model, const SceneGraph::ModelSkin &skin, unsigned int pattern);
34 
35  // Called to draw the model to the render target.
36  void Render();
37 
38  // Draws the model spinner widget and handles user interaction.
39  // Expected to be called during a Begin/End ImGui block.
40  // The modelspinner attempts to take all the available horizontal space
41  // in the window - use ImGui::BeginChild() to constrain the sizing.
42  void DrawPiGui();
43 
44  // Set the size of the texture to render.
45  void SetSize(vector2d size);
46 
47  // Retrieve the size of the rendered texture.
48  const vector2d GetSize() { return static_cast<vector2d>(m_size); }
49 
50  // Transform a model-space location into a screen-space position.
52 
53  private:
54  std::unique_ptr<Graphics::RenderTarget> m_renderTarget;
55  std::unique_ptr<SceneGraph::Model> m_model;
56  SceneGraph::ModelSkin m_skin;
57  std::unique_ptr<Shields> m_shields;
58  Graphics::Light m_light;
59 
60  void CreateRenderTarget();
61  ImTextureID GetTextureID();
62 
63  // The size of the render target.
64  vector2f m_size;
65  // Do we need to resize the render target next frame?
66  bool m_needsResize;
67 
68  // After the user manually rotates the model, hold that orientation for
69  // a second to let them look at it. Assumes Update() is called every
70  // frame while visible.
71  float m_pauseTime;
72 
73  // The rotation of the model.
74  vector2f m_rot;
75  };
76 } // namespace PiGui
void * ImTextureID
Definition: ModelSpinner.h:14
Definition: Light.h:14
Definition: ModelSpinner.h:28
vector2d ModelSpaceToScreenSpace(vector3d modelSpaceVec)
Definition: ModelSpinner.cpp:122
void SetSize(vector2d size)
Definition: ModelSpinner.cpp:89
void SetModel(SceneGraph::Model *model, const SceneGraph::ModelSkin &skin, unsigned int pattern)
Definition: ModelSpinner.cpp:42
void Render()
Definition: ModelSpinner.cpp:50
void DrawPiGui()
Definition: ModelSpinner.cpp:98
const vector2d GetSize()
Definition: ModelSpinner.h:48
ModelSpinner()
Definition: ModelSpinner.cpp:14
Definition: RefCounted.h:11
Definition: ModelSkin.h:22
Definition: Model.h:94
Definition: Background.h:13
Definition: LuaBody.cpp:28