| 596 | } |
| 597 | |
| 598 | void physicsUpdate() { |
| 599 | // Creates a joint to drag any grabable object on the scene |
| 600 | const Vector2f mousePos( KM->getMousePos().asFloat() ); |
| 601 | mMousePoint = cVectNew( mousePos.x, mousePos.y ); |
| 602 | cVect newPoint = tovect( cpvlerp( tocpv( mMousePoint_last ), tocpv( mMousePoint ), 0.25 ) ); |
| 603 | mMouseBody->setPos( newPoint ); |
| 604 | mMouseBody->setVel( ( newPoint - mMousePoint_last ) * (cpFloat)mWindow->getFPS() ); |
| 605 | mMousePoint_last = newPoint; |
| 606 | |
| 607 | if ( KM->isMouseLeftPressed() ) { |
| 608 | if ( NULL == mMouseJoint ) { |
| 609 | cVect point = cVectNew( mousePos.x, mousePos.y ); |
| 610 | |
| 611 | Shape* shape = mSpace->pointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); |
| 612 | |
| 613 | if ( NULL != shape ) { |
| 614 | mMouseJoint = eeNew( PivotJoint, ( mMouseBody, shape->getBody(), cVectZero, |
| 615 | shape->getBody()->world2Local( point ) ) ); |
| 616 | |
| 617 | mMouseJoint->setMaxForce( 50000.0f ); |
| 618 | mSpace->addConstraint( mMouseJoint ); |
| 619 | } |
| 620 | } |
| 621 | } else if ( NULL != mMouseJoint ) { |
| 622 | mSpace->removeConstraint( mMouseJoint ); |
| 623 | eeSAFE_DELETE( mMouseJoint ); |
| 624 | } |
| 625 | |
| 626 | mDemo[mCurDemo].update(); |
| 627 | mSpace->update(); |
| 628 | mSpace->draw(); |
| 629 | } |
| 630 | |
| 631 | void physicsDestroy() { |
| 632 | mDemo[mCurDemo].destroy(); |