Box2D 2.4.1
A 2D physics engine for games
b2_draw.h
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 B2_DRAW_H
24#define B2_DRAW_H
25
26#include "b2_api.h"
27#include "b2_math.h"
28
30struct B2_API b2Color
31{
32 b2Color() {}
33 b2Color(float rIn, float gIn, float bIn, float aIn = 1.0f)
34 {
35 r = rIn; g = gIn; b = bIn; a = aIn;
36 }
37
38 void Set(float rIn, float gIn, float bIn, float aIn = 1.0f)
39 {
40 r = rIn; g = gIn; b = bIn; a = aIn;
41 }
42
43 float r, g, b, a;
44};
45
48class B2_API b2Draw
49{
50public:
51 b2Draw();
52
53 virtual ~b2Draw() {}
54
55 enum
56 {
57 e_shapeBit = 0x0001,
58 e_jointBit = 0x0002,
59 e_aabbBit = 0x0004,
60 e_pairBit = 0x0008,
61 e_centerOfMassBit = 0x0010
62 };
63
65 void SetFlags(uint32 flags);
66
68 uint32 GetFlags() const;
69
71 void AppendFlags(uint32 flags);
72
74 void ClearFlags(uint32 flags);
75
77 virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
78
80 virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
81
83 virtual void DrawCircle(const b2Vec2& center, float radius, const b2Color& color) = 0;
84
86 virtual void DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color) = 0;
87
89 virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;
90
93 virtual void DrawTransform(const b2Transform& xf) = 0;
94
96 virtual void DrawPoint(const b2Vec2& p, float size, const b2Color& color) = 0;
97
98protected:
99 uint32 m_drawFlags;
100};
101
102#endif
Definition: b2_draw.h:49
uint32 GetFlags() const
Get the drawing flags.
virtual void DrawSegment(const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color)=0
Draw a line segment.
virtual void DrawPoint(const b2Vec2 &p, float size, const b2Color &color)=0
Draw a point.
virtual void DrawSolidCircle(const b2Vec2 &center, float radius, const b2Vec2 &axis, const b2Color &color)=0
Draw a solid circle.
virtual void DrawSolidPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)=0
Draw a solid closed polygon provided in CCW order.
void SetFlags(uint32 flags)
Set the drawing flags.
virtual void DrawCircle(const b2Vec2 &center, float radius, const b2Color &color)=0
Draw a circle.
void AppendFlags(uint32 flags)
Append flags to the current flags.
virtual void DrawPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)=0
Draw a closed polygon provided in CCW order.
virtual void DrawTransform(const b2Transform &xf)=0
void ClearFlags(uint32 flags)
Clear flags from the current flags.
Color for debug drawing. Each value has the range [0,1].
Definition: b2_draw.h:31
Definition: b2_math.h:339
A 2D column vector.
Definition: b2_math.h:42