/** * Apply an angular impulse. * * @param impulse the angular impulse (in meter/sec) */ public void applyBodyAngularImpulse(float impulse) { getBody().applyAngularImpulse(impulse); }
/** * Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body. * * @param force the world force vector (in meter/sec) * @param point the world position of the point of application (in meter) */ public void applyBodyForce(Vec2 force, Vec2 point) { getBody().applyForce(force, point); }
/** * Apply a force at a world point. * If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. * This wakes up the body. * * @param force the world force vector, usually in Newtons (N) * @param point the world position of the point of application */ public void applyForce(Vec2 force, Vec2 point) { applyForceToCenter(force); m_torque += (point.x - m_sweep.c.x) * force.y - (point.y - m_sweep.c.y) * force.x; }
BodyType typeA = bA.getType(); BodyType typeB = bB.getType(); assert (typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); boolean activeA = bA.isAwake() && typeA != BodyType.STATIC; boolean activeB = bB.isAwake() && typeB != BodyType.STATIC; boolean collideA = bA.isBullet() || typeA != BodyType.DYNAMIC; boolean collideB = bB.isBullet() || typeB != BodyType.DYNAMIC; bA.advance(minAlpha); bB.advance(minAlpha); bA.m_sweep.set(backup1); bB.m_sweep.set(backup2); bA.synchronizeTransform(); bB.synchronizeTransform(); continue; bA.setAwake(true); bB.setAwake(true); for (int i = 0; i < 2; ++i) { Body body = tempBodies[i]; if (body.getType() == BodyType.DYNAMIC) { for (ContactEdge ce = body.m_contactList; ce != null; ce = ce.next) { if (island.m_bodyCount == island.m_bodyCapacity) { if (other.getType() == BodyType.DYNAMIC && !body.isBullet() && !other.isBullet()) {
/** * Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body. * * @param impulse the world impulse vector (in meter/sec) * @param point the world position of the point of application (in meter) * @param wake if this impulse should wake up the body */ public void applyBodyLinearImpulse(Vec2 impulse, Vec2 point, boolean wake) { getBody().applyLinearImpulse(impulse, point, wake); }
/** * Creates a fixture from a shape and attach it to this body. * This is a convenience function. * Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. * If the density is non-zero, this function automatically updates the mass of the body. * Note: this function is locked during callbacks. * * * @param shape the shape to be cloned. * @param density the shape density (set to zero for static bodies). */ public Fixture createFixture(Shape shape, float density) { fixDef.setShape(shape); fixDef.setDensity(density); return createFixture(fixDef); }
/** * Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body. * * @param torque the force (in meter) */ public void applyBodyTorque(float torque) { getBody().applyTorque(torque); }
/** * Destroy a rigid body. * This automatically deletes all associated shapes and joints. * This function is locked during callbacks. * * @param body body to destroy */ public void destroyBody(Body body) { assertNotLocked(); body.destroy(); bodies.removeValueByIdentity(body); // jbox2dTODO djm recycle body }
/** * Create a rigid body given a definition. * No reference to the definition is retained. * This function is locked during callbacks. * * @param def body definition * @return rigid body */ public Body createBody(BodyDef def) { assertNotLocked(); Body b = new Body(def, this); bodies.add(b); return b; }
Body(BodyDef bd, World world) { checkValid(bd);
BodyType typeA = bA.getType(); BodyType typeB = bB.getType(); assert (typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); boolean activeA = bA.isAwake() && typeA != BodyType.STATIC; boolean activeB = bB.isAwake() && typeB != BodyType.STATIC; boolean collideA = bA.isBullet() || typeA != BodyType.DYNAMIC; boolean collideB = bB.isBullet() || typeB != BodyType.DYNAMIC; bA.advance(minAlpha); bB.advance(minAlpha); bA.m_sweep.set(backup1); bB.m_sweep.set(backup2); bA.synchronizeTransform(); bB.synchronizeTransform(); continue; bA.setAwake(true); bB.setAwake(true); for (int i = 0; i < 2; ++i) { Body body = tempBodies[i]; if (body.getType() == BodyType.DYNAMIC) { for (ContactEdge ce = body.m_contactList; ce != null; ce = ce.next) { if (island.m_bodyCount == island.m_bodyCapacity) { if (other.getType() == BodyType.DYNAMIC && !body.isBullet() && !other.isBullet()) {
/** * Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body. * * @param impulse the world impulse vector (in meter/sec) * @param point the world position of the point of application (in meter) * @param wake if this impulse should wake up the body */ public void applyBodyLinearImpulse(Vec2 impulse, Vec2 point, boolean wake) { getBody().applyLinearImpulse(impulse, point, wake); }
/** * Creates a fixture from a shape and attach it to this body. * This is a convenience function. * Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. * If the density is non-zero, this function automatically updates the mass of the body. * Note: this function is locked during callbacks. * * * @param shape the shape to be cloned. * @param density the shape density (set to zero for static bodies). */ public Fixture createFixture(Shape shape, float density) { fixDef.setShape(shape); fixDef.setDensity(density); return createFixture(fixDef); }
/** * Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body. * * @param torque the force (in meter) */ public void applyBodyTorque(float torque) { getBody().applyTorque(torque); }
/** * Destroy a rigid body. * This automatically deletes all associated shapes and joints. * This function is locked during callbacks. * * @param body body to destroy */ public void destroyBody(Body body) { assertNotLocked(); body.destroy(); bodies.removeValueByIdentity(body); // jbox2dTODO djm recycle body }
/** * Create a rigid body given a definition. * No reference to the definition is retained. * This function is locked during callbacks. * * @param def body definition * @return rigid body */ public Body createBody(BodyDef def) { assertNotLocked(); Body b = new Body(def, this); bodies.add(b); return b; }
Body(BodyDef bd, World world) { checkValid(bd);
f.x = -f.x; f.y = -f.y; b.applyLinearImpulse(f, p, true);
private void createFixtures(Entity e) { BoundingBoxComponent bbox = e.getBoundingBoxComponent(); PhysicsComponent physics = e.getComponent(PhysicsComponent.class); // TODO: same fixture def for every fixture? FixtureDef fd = physics.fixtureDef; for (HitBox box : bbox.hitBoxesProperty()) { Shape b2Shape = createShape(box, e); // we use definitions from user, but override shape fd.setShape(b2Shape); Fixture fixture = physics.body.createFixture(fd); fixture.setHitBox(box); } }
/** * Apply a force at a world point. * If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. * This wakes up the body. * * @param force the world force vector, usually in Newtons (N) * @param point the world position of the point of application */ public void applyForce(Vec2 force, Vec2 point) { applyForceToCenter(force); m_torque += (point.x - m_sweep.c.x) * force.y - (point.y - m_sweep.c.y) * force.x; }