PSMoveService
Renderer.h
1 #ifndef RENDERER_H
2 #define RENDERER_H
3 
4 //-- includes -----
5 #include <glm/glm.hpp>
6 
7 //-- typedefs -----
8 typedef union SDL_Event SDL_Event;
9 
10 //-- macros -----
11 #if defined(__clang__) || defined(__GNUC__)
12 #define RENDERER_PRINTFARGS(FMT) __attribute__((format(printf, FMT, (FMT+1))))
13 #else
14 #define RENDERER_PRINTFARGS(FMT)
15 #endif
16 
17 //-- definitions -----
18 class Renderer
19 {
20 public:
21  Renderer();
22  ~Renderer();
23 
24  bool init();
25  void destroy();
26 
27  bool onSDLEvent(const SDL_Event *event);
28 
29  void renderBegin();
30  void renderStageBegin();
31  void renderStageEnd();
32  void renderUIBegin();
33  void renderUIEnd();
34  void renderEnd();
35 
36  static bool getIsRenderingStage()
37  { return m_instance != nullptr && m_instance->m_isRenderingStage; }
38  static bool getIsRenderingUI()
39  { return m_instance != nullptr && m_instance->m_isRenderingUI; }
40  static float getWindowWidth()
41  { return static_cast<float>(m_instance->m_windowWidth); }
42  static float getWindowHeight()
43  { return static_cast<float>(m_instance->m_windowHeight); }
44  static float getWindowAspectRatio()
45  { return static_cast<float>(m_instance->m_windowWidth) / static_cast<float>(m_instance->m_windowHeight); }
46 
47  void setProjectionMatrix(const glm::mat4 &matrix)
48  { m_projectionMatrix= matrix; }
49  void setCameraViewMatrix(const glm::mat4 &matrix)
50  { m_cameraViewMatrix= matrix; }
51 
52  static const glm::mat4 &getCurrentProjectionMatrix()
53  { return m_instance->m_projectionMatrix; }
54  static const glm::mat4 &getCurrentCameraViewMatrix()
55  { return m_instance->m_cameraViewMatrix; }
56 
57 private:
58  bool m_sdlapi_initialized;
59 
60  struct SDL_Window *m_window;
61  int m_windowWidth, m_windowHeight;
62 
63  void *m_glContext;
64 
65  glm::mat4 m_projectionMatrix;
66  glm::mat4 m_cameraViewMatrix;
67 
68  bool m_isRenderingStage;
69  bool m_isRenderingUI;
70 
71  // imgui state
72  double m_Time;
73  bool m_MousePressed[3];
74  float m_MouseWheel;
75  unsigned int m_FontTexture;
76 
77  static Renderer *m_instance;
78 };
79 
80 //-- drawing methods -----
81 void drawArrow(const glm::mat4 &transform, const glm::vec3 &start, const glm::vec3 &end, const float headFraction, const glm::vec3 &color);
82 void drawTextAtWorldPosition(const glm::mat4 &transform, const glm::vec3 &position, const char *format, ...) RENDERER_PRINTFARGS(3);
83 void drawFullscreenTexture(const unsigned int texture_id);
84 void drawTrackingProjection(const struct PSMoveScreenLocation *centerProjection, const struct PSMoveTrackingProjection *projection, float trackerWidth, float trackerHeight);
85 void drawTransformedVolume(const glm::mat4 &transform, const struct PSMoveVolume *volume, const glm::vec3 &color);
86 void drawTransformedAxes(const glm::mat4 &transform, float scale);
87 void drawTransformedAxes(const glm::mat4 &transform, float xScale, float yScale, float zScale);
88 void drawTransformedBox(const glm::mat4 &transform, const glm::vec3 &half_extents, const glm::vec3 &color);
89 void drawTransformedBox(const glm::mat4 &transform, const glm::vec3 &box_min, const glm::vec3 &box_max, const glm::vec3 &color);
90 void drawTransformedTexturedCube(const glm::mat4 &transform, int textureId, float scale);
91 void drawTransformedFrustum(const glm::mat4 &transform, const struct PSMoveFrustum *frustum, const glm::vec3 &color);
92 void drawPointCloud(const glm::mat4 &transform, const glm::vec3 &color, const float *points, const int point_count);
93 void drawEllipsoid(
94  const glm::mat4 &transform, const glm::vec3 &color,
95  const glm::mat3 &basis, const glm::vec3 &center, const glm::vec3 &extents,
96  const int subdiv= 64);
97 void drawLineStrip(const glm::mat4 &transform, const glm::vec3 &color, const float *points, const int point_count);
98 void drawPoseArrayStrip(const struct PSMovePose *poses, const int poseCount, const glm::vec3 &color);
99 void drawDK2Model(const glm::mat4 &transform);
100 void drawPSMoveModel(const glm::mat4 &transform, const glm::vec3 &color);
101 void drawPSNaviModel(const glm::mat4 &transform);
102 void drawPSDualShock4Model(const glm::mat4 &transform, const glm::vec3 &color);
103 void drawPS3EyeModel(const glm::mat4 &transform);
104 
105 #endif // RENDERER_H
detail::tmat4x4< T > scale(detail::tmat4x4< T > const &m, detail::tvec3< T > const &v)
Builds a scale 4 * 4 matrix created from 3 scalars.
Definition: matrix_transform.inl:82
Definition: Renderer.h:18
Definition: ClientGeometry.h:176
Definition: type_mat2x2.hpp:45
A screen location in the space [-frameWidth/2, -frameHeight/2]x[frameWidth/2, frameHeight/2].
Definition: ClientGeometry.h:117
OpenGL Mathematics (glm.g-truc.net)
detail::tmat4x4< T > frustum(T const &left, T const &right, T const &bottom, T const &top, T const &near, T const &far)
Creates a frustum matrix.
Definition: ClientGeometry.h:186
Definition: type_mat2x2.hpp:39
Definition: ClientGeometry.h:164
Definition: ClientGeometry.h:214
Definition: type_mat2x2.hpp:49