MCPcopy Create free account
hub / github.com/axmolengine/axmol / onMouseDown

Method onMouseDown

tests/cpp-tests/Source/ChipmunkTestBed/ChipmunkTestBed.cpp:390–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388}
389
390bool 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
430bool ChipmunkTestBed::onMouseUp(Event* event)
431{

Callers

nothing calls this directly

Calls 8

cpSpacePointQueryNearestFunction · 0.85
cpBodyGetMassFunction · 0.85
cpShapeGetBodyFunction · 0.85
cpPivotJointNew2Function · 0.85
cpBodyWorldToLocalFunction · 0.85
cpSpaceAddConstraintFunction · 0.85
cpSpaceRemoveConstraintFunction · 0.85
cpConstraintFreeFunction · 0.85

Tested by

no test coverage detected