/** Set the linear velocity of the center of mass. */ public void setLinearVelocity (float vX, float vY) { tmp.set(vX, vY); body.setLinearVelocity(tmp); }
/** Set the linear velocity of the center of mass. */ public void setLinearVelocity (Vector2 v) { tmp.set(v.x, v.y); body.setLinearVelocity(tmp); }
public void launch() { m_body.setTransform(new Vec2(0.0f, 20.0f), 0.0f); m_angularVelocity = (float) Math.random() * 100 - 50; m_body.setLinearVelocity(new Vec2(0.0f, -100.0f)); m_body.setAngularVelocity(m_angularVelocity); }
public void launch() { m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f); m_body.setLinearVelocity(new Vec2()); m_body.setAngularVelocity(0.0f); m_x = MathUtils.randomFloat(-1.0f, 1.0f); m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f); m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f)); m_bullet.setAngularVelocity(0.0f); Distance.GJK_CALLS = 0; Distance.GJK_ITERS = 0; Distance.GJK_MAX_ITERS = 0; TimeOfImpact.toiCalls = 0; TimeOfImpact.toiIters = 0; TimeOfImpact.toiMaxIters = 0; TimeOfImpact.toiRootIters = 0; TimeOfImpact.toiMaxRootIters = 0; }
@Override public void step(TestbedSettings settings) { super.step(settings); addTextLine("Keys: (d) dynamic, (s) static, (k) kinematic"); // Drive the kinematic body. if (m_platform.getType() == BodyType.KINEMATIC) { Vec2 p = m_platform.getTransform().p; Vec2 v = m_platform.getLinearVelocity(); if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) { v.x = -v.x; m_platform.setLinearVelocity(v); } } }
@Override public void keyPressed(char argKeyChar, int argKeyCode) { switch (argKeyChar) { case 'd': m_platform.setType(BodyType.DYNAMIC); break; case 's': m_platform.setType(BodyType.STATIC); break; case 'k': m_platform.setType(BodyType.KINEMATIC); m_platform.setLinearVelocity(new Vec2(-m_speed, 0.0f)); m_platform.setAngularVelocity(0.0f); break; } }
@Override public void step(TestbedSettings settings) { super.step(settings); Vec2 p = circle.getTransform().p; Vec2 v = circle.getLinearVelocity(); if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) { v.x = -v.x; circle.setLinearVelocity(v); } int[] flagsBuffer = m_world.getParticleFlagsBuffer(); for (int i = 0; i < m_world.getParticleCount(); i++) { flagsBuffer[i] = flags; } addTextLine("'a' Clear"); addTextLine("'e' Elastic " + ((flags & ParticleType.b2_elasticParticle) != 0)); addTextLine("'q' Powder " + ((flags & ParticleType.b2_powderParticle) != 0)); addTextLine("'t' Tensile " + ((flags & ParticleType.b2_tensileParticle) != 0)); addTextLine("'v' Viscous " + ((flags & ParticleType.b2_viscousParticle) != 0)); }
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }
@Override public void keyPressed(char argKeyChar, int argKeyCode) { switch (argKeyChar) { case ',': if (m_bullet != null) { getWorld().destroyBody(m_bullet); m_bullet = null; } { CircleShape shape = new CircleShape(); shape.m_radius = 0.25f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 20.0f; fd.restitution = 0.05f; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.bullet = true; bd.position.set(-31.0f, 5.0f); m_bullet = getWorld().createBody(bd); m_bullet.createFixture(fd); m_bullet.setLinearVelocity(new Vec2(400.0f, 0.0f)); } break; } }
private void launchBomb(Vec2 position, Vec2 velocity) { if (bomb != null) { m_world.destroyBody(bomb); bomb = null; } // todo optimize this BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(position); bd.bullet = true; bomb = m_world.createBody(bd); bomb.setLinearVelocity(velocity); CircleShape circle = new CircleShape(); circle.m_radius = 0.3f; FixtureDef fd = new FixtureDef(); fd.shape = circle; fd.density = 20f; fd.restitution = 0; Vec2 minV = new Vec2(position); Vec2 maxV = new Vec2(position); minV.subLocal(new Vec2(.3f, .3f)); maxV.addLocal(new Vec2(.3f, .3f)); aabb.lowerBound.set(minV); aabb.upperBound.set(maxV); bomb.createFixture(fd); }
private void add_Box_Face() { float random_x = (float) (28 + (int)(Math.random() * ((this.CAMERA_WIDTH - 28*2) + 1))); final Body rectangle_face_body; rectangle_face[this.mSpriteCounter] = new Sprite(random_x, y, this.mRectangleFaceTextureRegion, this.getVertexBufferObjectManager()); rectangle_face_body = PhysicsFactory.createBoxBody(this.m_PhysicsWorld, rectangle_face[this.mSpriteCounter], BodyType.DynamicBody, this.BOX_FIXTURE_DEF); rectangle_face_body.setUserData("target"); rectangle_face_body.setLinearVelocity(0, -5); this.m_PhysicsWorld.registerPhysicsConnector(new PhysicsConnector(rectangle_face[this.mSpriteCounter], rectangle_face_body, true, false)); this.mscene.attachChild(rectangle_face[this.mSpriteCounter]); }
PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2(10, 10), false); Rectangle test = new Rectangle(100, 100, 50, 50, getVertexBufferObjectManager()); FixtureDef wallFixtureDef = PhysicsFactory .createFixtureDef(0, 0f, 0.5f); Body body = PhysicsFactory.createBoxBody(physicsWorld, test, BodyType.DynamicBody, wallFixtureDef); physicsWorld.registerPhysicsConnector(new PhysicsConnector(test, body)); body.setLinearVelocity(100, 100); yourScene.registerUpdateHandler(physicsWorld); yourScene.attachChild(test);
m_body.setLinearVelocity(new Vec2(0.0f, -100.0f)); m_body.setAngularVelocity(m_angularVelocity);
Body b = getWorld().createBody(bd); b.createFixture(fd); b.setLinearVelocity(new Vec2(-25f, -25f)); b.setAngularVelocity(6.7f); b = getWorld().createBody(bd); b.createFixture(fd); b.setLinearVelocity(new Vec2(35f, -10f)); b.setAngularVelocity(-8.3f);
private void dampenLiquid() { for (int i=0; i<liquid.length; ++i) { Body b = liquid[i]; b.setLinearVelocity(b.getLinearVelocity().mul(0.995f)); } }
m_bullet.createFixture(box, 100.0f); m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
m_character = body.createFixture(shape, 20.0f); body.setLinearVelocity(new Vec2(0.0f, -50.0f));
public void launch() { m_body.setTransform(new Vec2(0.0f, 20.0f), 0.0f); m_angularVelocity = (float) Math.random() * 100 - 50; m_body.setLinearVelocity(new Vec2(0.0f, -100.0f)); m_body.setAngularVelocity(m_angularVelocity); }
body.setLinearVelocity(new Vec2(-8.0f * w, 0.0f));
shape.m_radius = 1; body.createFixture(shape, 0.1f); body.setLinearVelocity(new Vec2(-6, 0.0f));