draw.h
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef DRAW_H
24 #define DRAW_H
25 
26 #define GLFW_INCLUDE_NONE
27 #include "glad/gl.h"
28 #include "GLFW/glfw3.h"
29 
30 #include "box2d/box2d.h"
31 
32 struct b2AABB;
33 struct GLRenderPoints;
34 struct GLRenderLines;
35 struct GLRenderTriangles;
36 struct GLFWwindow;
37 
38 //
39 struct Camera
40 {
42  {
43  m_center.Set(0.0f, 20.0f);
44  m_zoom = 1.0f;
45  m_width = 1280;
46  m_height = 800;
47  }
48 
49  b2Vec2 ConvertScreenToWorld(const b2Vec2& screenPoint);
50  b2Vec2 ConvertWorldToScreen(const b2Vec2& worldPoint);
51  void BuildProjectionMatrix(float* m, float zBias);
52 
54  float m_zoom;
57 };
58 
59 // This class implements debug drawing callbacks that are invoked
60 // inside b2World::Step.
61 class DebugDraw : public b2Draw
62 {
63 public:
64  DebugDraw();
65  ~DebugDraw();
66 
67  void Create();
68  void Destroy();
69 
70  void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override;
71 
72  void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override;
73 
74  void DrawCircle(const b2Vec2& center, float radius, const b2Color& color) override;
75 
76  void DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color) override;
77 
78  void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override;
79 
80  void DrawTransform(const b2Transform& xf) override;
81 
82  void DrawPoint(const b2Vec2& p, float size, const b2Color& color) override;
83 
84  void DrawString(int x, int y, const char* string, ...);
85 
86  void DrawString(const b2Vec2& p, const char* string, ...);
87 
88  void DrawAABB(b2AABB* aabb, const b2Color& color);
89 
90  void Flush();
91 
92  bool m_showUI;
96 };
97 
98 extern DebugDraw g_debugDraw;
99 extern Camera g_camera;
100 extern GLFWwindow* g_mainWindow;
101 
102 #endif
b2Vec2 ConvertScreenToWorld(const b2Vec2 &screenPoint)
Definition: draw.cpp:36
Definition: draw.h:39
The header of the GLFW 3 API.
f
int32 m_height
Definition: draw.h:56
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:1137
A 2D column vector.
Definition: b2_math.h:41
signed int int32
Definition: b2_types.h:28
GLRenderPoints * m_points
Definition: draw.h:93
Color for debug drawing. Each value has the range [0,1].
Definition: b2_draw.h:30
GLRenderTriangles * m_triangles
Definition: draw.h:95
DebugDraw g_debugDraw
Definition: draw.cpp:32
Definition: draw.h:61
Definition: b2_draw.h:48
bool m_showUI
Definition: draw.h:92
b2Vec2 m_center
Definition: draw.h:53
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
void BuildProjectionMatrix(float *m, float zBias)
Definition: draw.cpp:79
Camera()
Definition: draw.h:41
Camera g_camera
Definition: draw.cpp:33
float m_zoom
Definition: draw.h:54
An axis aligned bounding box.
Definition: b2_collision.h:168
b2Vec2 ConvertWorldToScreen(const b2Vec2 &worldPoint)
Definition: draw.cpp:57
GLFWwindow * g_mainWindow
Definition: main.cpp:42
GLRenderLines * m_lines
Definition: draw.h:94
int32 m_width
Definition: draw.h:55


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:20