| 388 | } |
| 389 | |
| 390 | bool ChipmunkTestBed::onMouseDown(Event* event) |
| 391 | { |
| 392 | EventMouse* e = (EventMouse*)event; |
| 393 | |
| 394 | if ((int)e->getMouseButton() == 0) |
| 395 | { |
| 396 | ChipmunkDemoLeftDown = cpTrue; |
| 397 | // give the mouse click a little radius to make it easier to click small shapes. |
| 398 | cpFloat radius = 5.0; |
| 399 | |
| 400 | cpPointQueryInfo info = {0}; |
| 401 | cpShape* shape = cpSpacePointQueryNearest(_space, ChipmunkDemoMouse, radius, GRAB_FILTER, &info); |
| 402 | |
| 403 | if (shape && cpBodyGetMass(cpShapeGetBody(shape)) < INFINITY) |
| 404 | { |
| 405 | // Use the closest point on the surface if the click is outside of the shape. |
| 406 | cpVect nearest = (info.distance > 0.0f ? info.point : ChipmunkDemoMouse); |
| 407 | |
| 408 | cpBody* body = cpShapeGetBody(shape); |
| 409 | mouse_joint = cpPivotJointNew2(mouse_body, body, cpvzero, cpBodyWorldToLocal(body, nearest)); |
| 410 | mouse_joint->maxForce = 50000.0f; |
| 411 | mouse_joint->errorBias = cpfpow(1.0f - 0.15f, 60.0f); |
| 412 | cpSpaceAddConstraint(_space, mouse_joint); |
| 413 | } |
| 414 | } |
| 415 | else if ((int)e->getMouseButton() == 1) |
| 416 | { |
| 417 | if (mouse_joint) |
| 418 | { |
| 419 | cpSpaceRemoveConstraint(_space, mouse_joint); |
| 420 | cpConstraintFree(mouse_joint); |
| 421 | mouse_joint = nullptr; |
| 422 | } |
| 423 | ChipmunkDemoRightDown = cpTrue; |
| 424 | ChipmunkDemoRightClick = cpTrue; |
| 425 | } |
| 426 | |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | bool ChipmunkTestBed::onMouseUp(Event* event) |
| 431 | { |
nothing calls this directly
no test coverage detected