void PhysicsBody::applyForce(const Vec2& force, const Vec2& offset) { if (_dynamic && _mass != PHYSICS_INFINITY) { cpBodyApplyForceAtLocalPoint(_cpBody, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset)); } }
int applykeys(Ship* s, bool* keylist) { if (keylist[0]) cpBodyApplyForceAtLocalPoint(s->body, cpv(0, 1e7), cpv(0.5, 0)); if (keylist[1]) cpBodyApplyForceAtLocalPoint(s->body, cpv(0, -1e6), cpv(0.5, 3)); if (keylist[2]) { cpBodyApplyForceAtLocalPoint(s->body, cpv(1e6, 0), cpv(0, 0)); cpBodyApplyForceAtLocalPoint(s->body, cpv(-1e6, 0), cpv(1, 3)); } if (keylist[3]) { cpBodyApplyForceAtLocalPoint(s->body, cpv(1e6, 0), cpv(0, 3)); cpBodyApplyForceAtLocalPoint(s->body, cpv(-1e6, 0), cpv(1, 0)); } if (keylist[4]) { cpBodyApplyForceAtLocalPoint(s->body, cpv(-1e6, 0), cpv(1, 3)); cpBodyApplyForceAtLocalPoint(s->body, cpv(-1e6, 0), cpv(1, 0)); } if (keylist[5]) { cpBodyApplyForceAtLocalPoint(s->body, cpv(1e6, 0), cpv(0, 3)); cpBodyApplyForceAtLocalPoint(s->body, cpv(1e6, 0), cpv(0, 0)); } if (keylist[6] && last_time_updated - s->last_fired > 1) { cpVect tip = cpBodyLocalToWorld(s->body, nosev + cpv(0, 0.1)); cpVect base = cpBodyLocalToWorld(s->body, cpv(0.5, 0)); cpVect newvel = cpvnormalize(tip - base) * shell_muzzle_vel + cpBodyGetVelocityAtLocalPoint(s->body, nosev); Shell* newshell = addshell(tip, newvel, cpBodyGetAngle(s->body)); cpBodyApplyImpulseAtLocalPoint(s->body, cpv(0, -1)*cpBodyGetMass(newshell->body)*shell_muzzle_vel, cpv(0.5, 3)); s->last_fired = last_time_updated; } return 0; }
void RigidBody2D::AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys) { switch (coordSys) { case CoordSys_Global: cpBodyApplyForceAtWorldPoint(m_handle, cpv(force.x, force.y), cpv(point.x, point.y)); break; case CoordSys_Local: cpBodyApplyForceAtLocalPoint(m_handle, cpv(force.x, force.y), cpv(point.x, point.y)); break; } }
void Body::addForce(glm::vec2 force, glm::vec2 offset){ cpBodyApplyForceAtLocalPoint(body, toChipmunk(force), toChipmunk(offset)); }