void Object::step(const float& t) { if (!_fixed) { /*glm::vec3 tOld = _transform._t; glm::vec3 wOld = _transform._w; glm::vec3 vLinOld = _linearVelocity; glm::vec3 vAngOld = _angularVelocity;*/ // note the ORDER OF OPERATIONS applyLinearImpulse(); applyAngularImpulse(); applyLinearAcceleration(t); applyAngularAcceleration(t); /*if (vLinOld != _linearVelocity) { _transform._t = tOld; _transform._w = wOld; _linearVelocity = vLinOld; _angularVelocity = vAngOld; applyLinearImpulse(); applyAngularImpulse(); applyLinearAcceleration(t); applyAngularAcceleration(t); }*/ } }
//=========================================== // Box2dPhysics::applyLinearImpulse //=========================================== void Box2dPhysics::applyLinearImpulse(const Vec2f& impulse) { if (!m_init) throw PhysicsException("Instance of Box2dPhysics is not initialised", __FILE__, __LINE__); applyLinearImpulse(impulse, Vec2f(m_body->GetWorldCenter().x * m_worldUnitsPerMetre, m_body->GetWorldCenter().y * m_worldUnitsPerMetre)); }
void Character::jump(float vel) { float force = (vel/5.0f + 8.0f) * m_body->GetMass(); setYLinearVelocity(0.0f); applyLinearImpulse(0.0f, force); for(Entity* ent : m_underfoot) ent->applyLinearImpulse(0.0f, -force); }
void init(gecom::Scene* s) override { gecom::Entity::init(s); addComponent<gecom::DrawableComponent>(std::make_shared<ProjectileDrawable>(shared_from_this())); auto phys = std::make_shared<ProjectilePhysics>(shared_from_this(), half_width, half_height); phys->registerWithWorld(getWorld()); /*gecom::log("proj") << "impulse: " << impulse;*/ phys->applyLinearImpulse(m_dir); addComponent<gecom::B2PhysicsComponent > (phys); }
/** * @brief Body::applyLinearImpulse * @param f */ void Body::applyLinearImpulse(float x, float y) { applyLinearImpulse(vec2(x, y)); }