MCPcopy Create free account
hub / github.com/SpartanJ/eepp / physicsUpdate

Function physicsUpdate

src/examples/physics/physics.cpp:598–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596}
597
598void 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
631void physicsDestroy() {
632 mDemo[mCurDemo].destroy();

Callers 2

initMethod · 0.85
mainLoopFunction · 0.85

Calls 14

setPosMethod · 0.80
setVelMethod · 0.80
getFPSMethod · 0.80
isMouseLeftPressedMethod · 0.80
pointQueryFirstMethod · 0.80
world2LocalMethod · 0.80
setMaxForceMethod · 0.80
addConstraintMethod · 0.80
removeConstraintMethod · 0.80
asFloatMethod · 0.45
getMousePosMethod · 0.45
getBodyMethod · 0.45

Tested by 1

initMethod · 0.68