Vec3D<> CVX_Voxel::force() { //forces from internal bonds Vec3D<> totalForce(0,0,0); for (int i=0; i<6; i++){ if (links[i]) totalForce += links[i]->force(isNegative((linkDirection)i)); //total force in LCS } totalForce = orient.RotateVec3D(totalForce); //other forces totalForce += extForce; //external forces totalForce -= velocity()*mat->globalDampingTranslateC(); //global damping if (isGravityEnabled()) totalForce.z -= mat->_mass*9.80665; //gravity, according to f=mg if (isFloorEnabled()) addFloorForces(&totalForce); //adds forces from interacting with the floor //Collisions: todo return totalForce; }
void PhysicsBody::setDynamic(bool dynamic) { if (dynamic != _dynamic) { _dynamic = dynamic; if (dynamic) { cpBodySetMass(_info->getBody(), _mass); cpBodySetMoment(_info->getBody(), _moment); if (_world != nullptr) { // reset the gravity enable if (isGravityEnabled()) { _gravityEnabled = false; setGravityEnable(true); } cpSpaceAddBody(_world->_info->getSpace(), _info->getBody()); } } else { if (_world != nullptr) { cpSpaceRemoveBody(_world->_info->getSpace(), _info->getBody()); } // avoid incorrect collion simulation. cpBodySetMass(_info->getBody(), PHYSICS_INFINITY); cpBodySetMoment(_info->getBody(), PHYSICS_INFINITY); cpBodySetVel(_info->getBody(), cpvzero); cpBodySetAngVel(_info->getBody(), 0.0f); resetForces(); } } }