Skip to content

Commit c76b50c

Browse files
committed
clean up
1 parent 1bc2113 commit c76b50c

17 files changed

+677
-683
lines changed

samples/draw.c

Lines changed: 321 additions & 321 deletions
Large diffs are not rendered by default.

samples/draw.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
typedef struct Camera
99
{
10-
b2Vec2 m_center;
11-
float m_zoom;
12-
float m_width;
13-
float m_height;
10+
b2Vec2 center;
11+
float zoom;
12+
float width;
13+
float height;
1414
} Camera;
1515

1616
typedef struct Draw Draw;
@@ -24,32 +24,26 @@ Camera GetDefaultCamera( void );
2424
void ResetView( Camera* camera );
2525
b2Vec2 ConvertScreenToWorld( Camera* camera, b2Vec2 screenPoint );
2626
b2Vec2 ConvertWorldToScreen( Camera* camera, b2Vec2 worldPoint );
27-
void BuildProjectionMatrix( Camera* camera, float* m, float zBias );
2827
b2AABB GetViewBounds( Camera* camera );
2928

3029
Draw* CreateDraw( void );
3130
void DestroyDraw( Draw* draw );
3231

3332
void DrawPoint( Draw* draw, b2Vec2 p, float size, b2HexColor color );
3433
void DrawLine( Draw* draw, b2Vec2 p1, b2Vec2 p2, b2HexColor color );
35-
3634
void DrawCircle( Draw* draw, b2Vec2 center, float radius, b2HexColor color );
3735
void DrawSolidCircle( Draw* draw, b2Transform transform, float radius, b2HexColor color );
38-
3936
void DrawSolidCapsule( Draw* draw, b2Vec2 p1, b2Vec2 p2, float radius, b2HexColor color );
40-
4137
void DrawPolygon( Draw* draw, const b2Vec2* vertices, int vertexCount, b2HexColor color );
4238
void DrawSolidPolygon( Draw* draw, b2Transform transform, const b2Vec2* vertices, int vertexCount, float radius,
4339
b2HexColor color );
44-
4540
void DrawTransform( Draw* draw, b2Transform transform, float scale );
4641
void DrawBounds( Draw* draw, b2AABB aabb, b2HexColor color );
47-
4842
void DrawScreenString( Draw* draw, float x, float y, b2HexColor color, const char* string, ... );
4943
void DrawWorldString( Draw* draw, Camera* camera, b2Vec2 p, b2HexColor color, const char* string, ... );
5044

51-
5245
void FlushDraw( Draw* draw, Camera* camera );
46+
5347
void DrawBackground( Draw* draw, Camera* camera );
5448

5549
#ifdef __cplusplus

samples/main.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ static void DestroyUI()
186186

187187
static void ResizeWindowCallback( GLFWwindow*, int width, int height )
188188
{
189-
s_context.camera.m_width = float( width );
190-
s_context.camera.m_height = float( height );
189+
s_context.camera.width = float( width );
190+
s_context.camera.height = float( height );
191191
}
192192

193193
static void KeyCallback( GLFWwindow* window, int key, int scancode, int action, int mods )
@@ -216,7 +216,7 @@ static void KeyCallback( GLFWwindow* window, int key, int scancode, int action,
216216
}
217217
else
218218
{
219-
s_context.camera.m_center.x -= 0.5f;
219+
s_context.camera.center.x -= 0.5f;
220220
}
221221
break;
222222

@@ -229,7 +229,7 @@ static void KeyCallback( GLFWwindow* window, int key, int scancode, int action,
229229
}
230230
else
231231
{
232-
s_context.camera.m_center.x += 0.5f;
232+
s_context.camera.center.x += 0.5f;
233233
}
234234
break;
235235

@@ -242,7 +242,7 @@ static void KeyCallback( GLFWwindow* window, int key, int scancode, int action,
242242
}
243243
else
244244
{
245-
s_context.camera.m_center.y -= 0.5f;
245+
s_context.camera.center.y -= 0.5f;
246246
}
247247
break;
248248

@@ -255,7 +255,7 @@ static void KeyCallback( GLFWwindow* window, int key, int scancode, int action,
255255
}
256256
else
257257
{
258-
s_context.camera.m_center.y += 0.5f;
258+
s_context.camera.center.y += 0.5f;
259259
}
260260
break;
261261

@@ -365,8 +365,8 @@ static void MouseMotionCallback( GLFWwindow* window, double xd, double yd )
365365
if ( s_rightMouseDown )
366366
{
367367
b2Vec2 diff = b2Sub( pw, s_clickPointWS );
368-
s_context.camera.m_center.x -= diff.x;
369-
s_context.camera.m_center.y -= diff.y;
368+
s_context.camera.center.x -= diff.x;
369+
s_context.camera.center.y -= diff.y;
370370
s_clickPointWS = ConvertScreenToWorld( &s_context.camera, ps );
371371
}
372372
}
@@ -381,11 +381,11 @@ static void ScrollCallback( GLFWwindow* window, double dx, double dy )
381381

382382
if ( dy > 0 )
383383
{
384-
s_context.camera.m_zoom /= 1.1f;
384+
s_context.camera.zoom /= 1.1f;
385385
}
386386
else
387387
{
388-
s_context.camera.m_zoom *= 1.1f;
388+
s_context.camera.zoom *= 1.1f;
389389
}
390390
}
391391

@@ -397,8 +397,8 @@ static void UpdateUI()
397397
float menuWidth = 13.0f * fontSize;
398398
if ( s_context.showUI )
399399
{
400-
ImGui::SetNextWindowPos( { s_context.camera.m_width - menuWidth - 0.5f * fontSize, 0.5f * fontSize } );
401-
ImGui::SetNextWindowSize( { menuWidth, s_context.camera.m_height - fontSize } );
400+
ImGui::SetNextWindowPos( { s_context.camera.width - menuWidth - 0.5f * fontSize, 0.5f * fontSize } );
401+
ImGui::SetNextWindowSize( { menuWidth, s_context.camera.height - fontSize } );
402402

403403
ImGui::Begin( "Tools", &s_context.showUI,
404404
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse );
@@ -609,7 +609,7 @@ int main( int, char** )
609609
else
610610
{
611611
s_context.window =
612-
glfwCreateWindow( int( s_context.camera.m_width ), int( s_context.camera.m_height ), buffer, nullptr, nullptr );
612+
glfwCreateWindow( int( s_context.camera.width ), int( s_context.camera.height ), buffer, nullptr, nullptr );
613613
}
614614

615615
if ( s_context.window == nullptr )
@@ -659,18 +659,18 @@ int main( int, char** )
659659
if ( glfwGetKey( s_context.window, GLFW_KEY_Z ) == GLFW_PRESS )
660660
{
661661
// Zoom out
662-
s_context.camera.m_zoom = b2MinFloat( 1.005f * s_context.camera.m_zoom, 100.0f );
662+
s_context.camera.zoom = b2MinFloat( 1.005f * s_context.camera.zoom, 100.0f );
663663
}
664664
else if ( glfwGetKey( s_context.window, GLFW_KEY_X ) == GLFW_PRESS )
665665
{
666666
// Zoom in
667-
s_context.camera.m_zoom = b2MaxFloat( 0.995f * s_context.camera.m_zoom, 0.5f );
667+
s_context.camera.zoom = b2MaxFloat( 0.995f * s_context.camera.zoom, 0.5f );
668668
}
669669

670670
int width, height;
671671
glfwGetWindowSize( s_context.window, &width, &height );
672-
s_context.camera.m_width = width;
673-
s_context.camera.m_height = height;
672+
s_context.camera.width = width;
673+
s_context.camera.height = height;
674674

675675
int bufferWidth, bufferHeight;
676676
glfwGetFramebufferSize( s_context.window, &bufferWidth, &bufferHeight );
@@ -688,10 +688,10 @@ int main( int, char** )
688688
// ImGui_ImplGlfw_CursorPosCallback( s_context.window, cursorPosX / s_windowScale, cursorPosY / s_windowScale );
689689

690690
ImGuiIO& io = ImGui::GetIO();
691-
io.DisplaySize.x = s_context.camera.m_width;
692-
io.DisplaySize.y = s_context.camera.m_height;
693-
io.DisplayFramebufferScale.x = bufferWidth / s_context.camera.m_width;
694-
io.DisplayFramebufferScale.y = bufferHeight / s_context.camera.m_height;
691+
io.DisplaySize.x = s_context.camera.width;
692+
io.DisplaySize.y = s_context.camera.height;
693+
io.DisplayFramebufferScale.x = bufferWidth / s_context.camera.width;
694+
io.DisplayFramebufferScale.y = bufferHeight / s_context.camera.height;
695695

696696
ImGui::NewFrame();
697697

@@ -708,9 +708,9 @@ int main( int, char** )
708708

709709
s_sample->Step();
710710

711-
DrawScreenString( s_context.draw, 5.0f, s_context.camera.m_height - 10.0f, b2_colorSeaGreen,
711+
DrawScreenString( s_context.draw, 5.0f, s_context.camera.height - 10.0f, b2_colorSeaGreen,
712712
"%.1f ms - step %d - camera (%g, %g, %g)", 1000.0f * frameTime, s_sample->m_stepCount,
713-
s_context.camera.m_center.x, s_context.camera.m_center.y, s_context.camera.m_zoom );
713+
s_context.camera.center.x, s_context.camera.center.y, s_context.camera.zoom );
714714

715715
FlushDraw( s_context.draw, &s_context.camera );
716716

0 commit comments

Comments
 (0)