Skip to content

Commit 67b0e4f

Browse files
authored
Fix chipmunk2D debug draw issues, resize designSize, removed DrawInfo (#3050)
* improve Chipmunk2D designSize, drawPolygon, drawSegment for better DebugDrawing * removed DrawInfo() => its not really useful
1 parent 41aae3f commit 67b0e4f

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

extensions/physics-nodes/src/physics-nodes/PhysicsDebugNodeChipmunk2D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void DrawShape(cpShape* shape, DrawNode* renderer)
9595
case CP_SEGMENT_SHAPE:
9696
{
9797
cpSegmentShape* seg = (cpSegmentShape*)shape;
98-
renderer->drawSegment(cpVert2Point(seg->ta), cpVert2Point(seg->tb), cpfmax(seg->r, 1.0), color);
98+
renderer->drawSegment(cpVert2Point(seg->ta), cpVert2Point(seg->tb), cpfmax(seg->r*4, 1.0), color);
9999
}
100100
break;
101101
case CP_POLY_SHAPE:
@@ -109,7 +109,7 @@ static void DrawShape(cpShape* shape, DrawNode* renderer)
109109
pPoints[i] = cpVert2Point(poly->planes[i].v0);
110110
if (cpfmax(poly->r, 1.0) > 1.0)
111111
{
112-
renderer->drawPolygon(pPoints, num, Color4F{}, poly->r, color);
112+
renderer->drawPolygon(pPoints, num, Color4F{}, poly->r*2, color);
113113
}
114114
else
115115
{

tests/cpp-tests/Source/ChipmunkTestBed/ChipmunkTestBed.cpp

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ cpBool ChipmunkDemoRightDown = cpFalse;
9191
cpBool ChipmunkDemoLeftDown = cpFalse;
9292
double ChipmunkDemoTime;
9393

94-
cpBody* mouse_body = cpBodyNewKinematic();
94+
cpBody* mouse_body = cpBodyNewKinematic();
9595
static cpConstraint* mouse_joint = nullptr;
9696

9797
char const* ChipmunkDemoMessageString = nullptr;
@@ -102,7 +102,7 @@ cpShapeFilter NOT_GRABBABLE_FILTER = {CP_NO_GROUP, ~GRABBABLE_MASK_BIT, ~GRABBAB
102102

103103
ax::DrawNode* drawCP = nullptr;
104104

105-
void ChipmunkDemoDefaultDrawImpl(cpSpace* space){};
105+
void ChipmunkDemoDefaultDrawImpl(cpSpace* space) {};
106106

107107
void ChipmunkDebugDrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor fillColor)
108108
{
@@ -174,44 +174,6 @@ static int max_arbiters = 0;
174174
static int max_points = 0;
175175
static int max_constraints = 0;
176176

177-
void ChipmunkTestBed::DrawInfo()
178-
{
179-
int arbiters = _space->arbiters->num;
180-
int points = 0;
181-
182-
for (int i = 0; i < arbiters; i++)
183-
points += ((cpArbiter*)(_space->arbiters->arr[i]))->count;
184-
185-
int constraints = (_space->constraints->num + points) * _space->iterations;
186-
187-
max_arbiters = arbiters > max_arbiters ? arbiters : max_arbiters;
188-
max_points = points > max_points ? points : max_points;
189-
max_constraints = constraints > max_constraints ? constraints : max_constraints;
190-
191-
char buffer[1024];
192-
constexpr auto format =
193-
"Arbiters: {} ({}) - "
194-
"Contact Points: {} ({})\n"
195-
"Other Constraints: {}, Iterations: {}\n"
196-
"Constraints x Iterations: {} ({})\n"
197-
"Time:{:5.2f}s, KE:{:5.2e}"sv;
198-
199-
cpArray* bodies = _space->dynamicBodies;
200-
cpFloat ke = 0.0f;
201-
for (int i = 0; i < bodies->num; i++)
202-
{
203-
cpBody* body = (cpBody*)bodies->arr[i];
204-
if (body->m == INFINITY || body->i == INFINITY)
205-
continue;
206-
207-
ke += body->m * cpvdot(body->v, body->v) + body->i * body->w * body->w;
208-
}
209-
210-
auto msg = fmt::format_to_z(buffer, format, arbiters, max_arbiters, points, max_points, _space->constraints->num, _space->iterations,
211-
constraints, max_constraints, ChipmunkDemoTime, (ke < 1e-10f ? 0.0f : ke));
212-
213-
drawInfo->setString(msg);
214-
}
215177

216178
static char PrintStringBuffer[1024 * 8];
217179
static char* PrintStringCursor;
@@ -308,9 +270,9 @@ ChipmunkTestBed::ChipmunkTestBed()
308270
{
309271
// halx99: since axmol init scene default camera at 'initWithXXX' function, only change design size at scene
310272
// construct is ok see also: https://github.com/axmolengine/axmol/commit/581a7921554c09746616759d5a5ca6ce9d3eaa22
311-
auto director = Director::getInstance();
312-
auto renderView = director->getRenderView();
313-
Size designSize(g_designSize.width * 0.85, g_designSize.height * 0.85);
273+
auto director = Director::getInstance();
274+
auto renderView = director->getRenderView();
275+
Size designSize(g_designSize.width * 1.5, g_designSize.height * 1.5);
314276
renderView->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
315277

316278
// creating a keyboard event listener
@@ -395,11 +357,11 @@ void ChipmunkTestBed::initPhysics()
395357

396358
void ChipmunkTestBed::update(float delta)
397359
{
398-
//#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
399-
// cpSpaceStep(_space, delta);
400-
//#else
401-
// cpHastySpaceStep(_space, delta);
402-
//#endif
360+
// #if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
361+
// cpSpaceStep(_space, delta);
362+
// #else
363+
// cpHastySpaceStep(_space, delta);
364+
// #endif
403365
}
404366

405367
void ChipmunkTestBed::createResetButton()
@@ -484,8 +446,8 @@ bool ChipmunkTestBed::onMouseUp(Event* event)
484446

485447
bool ChipmunkTestBed::onMouseMove(Event* event)
486448
{
487-
EventMouse* e = (EventMouse*)event;
488-
auto pt = e->getLocation();
449+
EventMouse* e = (EventMouse*)event;
450+
auto pt = e->getLocation();
489451
ChipmunkDemoMouse.x = pt.x - physicsDebugNodeOffset.x;
490452
ChipmunkDemoMouse.y = pt.y - physicsDebugNodeOffset.y;
491453

@@ -502,7 +464,6 @@ void ChipmunkTestBed::updateInit(ChipmunkDemo tt)
502464
drawCP->clear();
503465
updateMouseBody();
504466
ChipmunkDemoTime += tt.timestep;
505-
ChipmunkTestBed::DrawInfo();
506467
tt.updateFunc(_space, tt.timestep);
507468
}
508469

tests/cpp-tests/Source/ChipmunkTestBed/ChipmunkTestBed.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class ChipmunkTestBed : public TestCase
5151
bool onMouseDown(ax::Event* event);
5252
bool onMouseUp(ax::Event* event);
5353
bool onMouseMove(ax::Event* event);
54-
void DrawInfo();
5554
void updateInit(ChipmunkDemo tt);
5655

5756
cpSpace* _space; // strong ref

0 commit comments

Comments
 (0)