Pioneer
ModelSpinner.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 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 #include "Shields.h"
14 #include "scenegraph/Model.h"
15 #include "scenegraph/ModelSkin.h"
16 
17 // TODO:
18 // - make this code reusable across multiple usecases (camera, rear-view mirror, UI preview, etc.)
19 // - Render more than a single model, e.g. attachments / equipment / shields (a scene, scenegraph hierarchy, etc.)
20 // - Add support for the usual post-processing chain (integrate with regular scene rendering)
21 // In essence, we want to make the regular main-scene rendering code modular and able to render
22 // arbitrary scenes to RTs that we can use in Pigui et. al.
23 // For now we'll do a basic implementation here to move the model spinner functionality to Pigui.
24 namespace PiGui {
25  class ModelSpinner : public RefCounted {
26  public:
27  ModelSpinner();
28 
29  // Set the ship we should be looking at.
30  void SetModel(SceneGraph::Model *model, const SceneGraph::ModelSkin &skin, unsigned int pattern);
31 
32  // Called to draw the model to the render target.
33  void Render();
34 
35  // Draws the model spinner widget and handles user interaction.
36  // Expected to be called during a Begin/End ImGui block.
37  // The modelspinner attempts to take all the available horizontal space
38  // in the window - use ImGui::BeginChild() to constrain the sizing.
39  void DrawPiGui();
40 
41  // Set the size of the texture to render.
42  void SetSize(vector2d size);
43 
44  // Retrieve the size of the rendered texture.
45  const vector2d GetSize() const { return static_cast<vector2d>(m_size); }
46 
47  // Get the screen-space position of the given tag in the model.
48  vector2d GetTagPos(const char *tagName);
49 
50  void SetSpinning(bool en) { m_spinning = en; }
51  bool GetSpinning() const { return m_spinning; }
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 
62  // Transform a model-space location into a screen-space position.
63  vector3f ModelSpaceToScreenSpace(vector3f modelSpaceVec);
64  matrix4x4f MakeModelViewMat();
65 
66  // The size of the render target.
67  vector2f m_size;
68  // Do we need to resize the render target next frame?
69  bool m_needsResize;
70 
71  // Shoulde we spinne?
72  bool m_spinning;
73 
74  // After the user manually rotates the model, hold that orientation for
75  // a second to let them look at it. Assumes Update() is called every
76  // frame while visible.
77  float m_pauseTime;
78 
79  // The rotation of the model.
80  vector2f m_rot;
81  float m_zoom;
82  float m_zoomTo;
83  };
84 } // namespace PiGui
Definition: Light.h:14
Definition: ModelSpinner.h:25
void SetSize(vector2d size)
Definition: ModelSpinner.cpp:86
bool GetSpinning() const
Definition: ModelSpinner.h:51
const vector2d GetSize() const
Definition: ModelSpinner.h:45
void SetModel(SceneGraph::Model *model, const SceneGraph::ModelSkin &skin, unsigned int pattern)
Definition: ModelSpinner.cpp:48
vector2d GetTagPos(const char *tagName)
Definition: ModelSpinner.cpp:145
void Render()
Definition: ModelSpinner.cpp:58
void DrawPiGui()
Definition: ModelSpinner.cpp:107
ModelSpinner()
Definition: ModelSpinner.cpp:17
void SetSpinning(bool en)
Definition: ModelSpinner.h:50
Definition: RefCounted.h:11
Definition: ModelSkin.h:22
Definition: Model.h:88
Definition: Background.h:14
Definition: LuaBody.cpp:29