List of usage examples for com.badlogic.gdx.physics.box2d Body getWorldCenter
public Vector2 getWorldCenter()
From source file:com.agateau.pixelwheels.racer.Racer.java
License:Open Source License
private void applySimplifiedRacerCollision(Racer other) { Body body1 = getVehicle().getBody(); Body body2 = other.getVehicle().getBody(); mTmp.set(body2.getLinearVelocity()).sub(body1.getLinearVelocity()); float deltaV = mTmp.len(); final float k = GamePlay.instance.simplifiedCollisionKFactor * MathUtils.clamp(deltaV / GamePlay.instance.simplifiedCollisionMaxDeltaV, 0, 1); mTmp.set(body2.getWorldCenter()).sub(body1.getWorldCenter()).nor().scl(k); body2.applyLinearImpulse(mTmp, body2.getWorldCenter(), true); mTmp.scl(-1);/* w ww. ja v a 2 s .c o m*/ body1.applyLinearImpulse(mTmp, body1.getWorldCenter(), true); }
From source file:com.agateau.pixelwheels.racer.SpinningComponent.java
License:Open Source License
@Override public void act(float delta) { if (!mActive) { return;// ww w . j av a2 s. co m } Body body = mVehicle.getBody(); // Slow down body.applyLinearImpulse(body.getLinearVelocity().nor().scl(-body.getMass()), body.getWorldCenter(), true); // Spin float nextAngle = body.getAngle() + body.getAngularVelocity() * GameWorld.BOX2D_TIME_STEP; if (nextAngle > mTargetBodyAngle) { stopSpinning(); return; } float totalRotation = mTargetBodyAngle - nextAngle; float desiredAngularVelocity = totalRotation / GameWorld.BOX2D_TIME_STEP; if (desiredAngularVelocity < 0) { desiredAngularVelocity = MathUtils.clamp(desiredAngularVelocity, -MAX_ANGULAR_VELOCITY, -MIN_ANGULAR_VELOCITY); } else { desiredAngularVelocity = MathUtils.clamp(desiredAngularVelocity, MIN_ANGULAR_VELOCITY, MAX_ANGULAR_VELOCITY); } float impulse = body.getInertia() * (desiredAngularVelocity - body.getAngularVelocity()); body.applyAngularImpulse(impulse, true); }
From source file:com.agateau.pixelwheels.utils.Box2DUtils.java
License:Open Source License
public static void applyDrag(Body body, float factor) { Vector2 dragForce = body.getLinearVelocity().scl(-factor); body.applyForce(dragForce, body.getWorldCenter(), true); }
From source file:com.dongbat.game.util.PhysicsUtil.java
/** * Apply Linear Impulse to an entity// w w w .j a v a 2s. c o m * * @param world artemis world * @param entity entity that you want to apply * @param impulse impulse amount */ public static void applyImpulse(com.artemis.World world, Entity entity, Vector2 impulse) { Body body = getBody(world, entity); body.applyLinearImpulse(impulse, body.getWorldCenter(), true); }
From source file:com.dongbat.game.util.PhysicsUtil.java
/** * Apply Froce to an entity/*www . ja v a 2 s.c om*/ * * @param world artemis world * @param entity entity that you want to apply * @param force force amount */ public static void applyForce(com.artemis.World world, Entity entity, Vector2 force) { Body body = getBody(world, entity); body.applyForce(force, body.getWorldCenter(), true); }
From source file:com.dongbat.invasion.util.PhysicsUtil.java
public static void applyImpulse(Entity entity, Vector2 impulse) { Body body = getBody(entity); body.applyLinearImpulse(impulse, body.getWorldCenter(), true); }
From source file:com.dongbat.invasion.util.PhysicsUtil.java
public static void applyForce(Entity entity, Vector2 force) { Body body = getBody(entity); body.applyForce(force, body.getWorldCenter(), true); }
From source file:com.gmail.emersonmx.asteroids.system.PhysicSystem.java
License:Open Source License
private void processInputEntity(Entity entity, float deltaTime) { MovementComponent motion = motionMapper.get(entity); PhysicBodyComponent bodyComponent = physicBodyMapper.get(entity); Body body = bodyComponent.body; body.applyForce(motion.velocity, body.getWorldCenter(), true); motion.velocity.setZero();//ww w.j a v a 2s .co m body.setTransform(body.getPosition(), motion.direction.angleRad()); }
From source file:com.hatstick.fireman.physics.Box2DPhysicsWorld.java
License:Apache License
public void jumpBody(Body body, float height) { body.applyLinearImpulse(new Vector2(0, height), body.getWorldCenter(), true); }
From source file:com.laex.cg2d.render.util.ProtoBufTypeConversionUtil.java
License:Open Source License
/** * As distance joint def.// w w w . j ava 2 s.c o m * * @param bodyA the body a * @param bodyB the body b * @param _j the _j * @return the distance joint def */ public static DistanceJointDef asDistanceJointDef(Body bodyA, Body bodyB, CGJoint _j) { DistanceJointDef jdef = new DistanceJointDef(); jdef.collideConnected = _j.getDistanceJointDef().getCollideConnected(); jdef.dampingRatio = _j.getDistanceJointDef().getDampingRatio(); jdef.frequencyHz = _j.getDistanceJointDef().getFreqencyHz(); jdef.initialize(bodyA, bodyB, bodyA.getWorldCenter(), bodyB.getWorldCenter()); if (_j.getUseLocalAnchors()) { jdef.localAnchorA.set(Vector2Adapter.asVector2(_j.getLocalAnchorA())); jdef.localAnchorB.set(Vector2Adapter.asVector2(_j.getLocalAnchorB())); } return jdef; }