/** * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) { bodyA = b1; bodyB = b2; groundAnchorA = ga1; groundAnchorB = ga2; localAnchorA = bodyA.getLocalPoint(anchor1); localAnchorB = bodyB.getLocalPoint(anchor2); Vec2 d1 = anchor1.sub(ga1); lengthA = d1.length(); Vec2 d2 = anchor2.sub(ga2); lengthB = d2.length(); ratio = r; assert (ratio > Settings.EPSILON); } }
for (int i = 0; i < targetLengths.length; ++i) { final int next = (i == targetLengths.length - 1) ? 0 : i + 1; float dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length(); targetLengths[i] = dist;
/** * Initialize the bodies, anchors, and length using the world anchors. * * @param b1 First body * @param b2 Second body * @param anchor1 World anchor on first body * @param anchor2 World anchor on second body */ public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { bodyA = b1; bodyB = b2; localAnchorA.set(bodyA.getLocalPoint(anchor1)); localAnchorB.set(bodyB.getLocalPoint(anchor2)); Vec2 d = anchor2.sub(anchor1); length = d.length(); } }
/** * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) { bodyA = b1; bodyB = b2; groundAnchorA = ga1; groundAnchorB = ga2; localAnchorA = bodyA.getLocalPoint(anchor1); localAnchorB = bodyB.getLocalPoint(anchor2); Vec2 d1 = anchor1.sub(ga1); lengthA = d1.length(); Vec2 d2 = anchor2.sub(ga2); lengthB = d2.length(); ratio = r; assert (ratio > Settings.EPSILON); } }
public void MoveProxy() { for (int i = 0; i < e_actorCount; ++i) { int j = MathUtils.abs(rand.nextInt() % e_actorCount); Actor actor = m_actors[j]; if (actor.proxyId == -1) { continue; } AABB aabb0 = new AABB(actor.aabb); MoveAABB(actor.aabb); Vec2 displacement = actor.aabb.getCenter().sub(aabb0.getCenter()); m_tree.moveProxy(actor.proxyId, new AABB(actor.aabb), displacement); return; } }
for (int i = 0; i < targetLengths.length; ++i) { final int next = (i == targetLengths.length - 1) ? 0 : i + 1; float dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length(); targetLengths[i] = dist;
@Override public void mouseDragged(MouseEvent arg0) { mouse.set(arg0.getX(), arg0.getY()); if (screenDragButtonDown) { TestbedTest currTest = model.getCurrTest(); if (currTest == null) { return; } Vec2 diff = oldDragMouse.sub(mouse); currTest.getCamera().moveWorld(diff); oldDragMouse.set(mouse); } else if (mouseJointButtonDown) { controller.queueMouseDrag(new Vec2(mouse), TestbedTest.MOUSE_JOINT_BUTTON); } else if (model.getCodedKeys()[KeyEvent.VK_SHIFT]) { controller.queueMouseDrag(new Vec2(arg0.getX(), arg0.getY()), TestbedTest.BOMB_SPAWN_BUTTON); } else { controller.queueMouseDrag(new Vec2(mouse), arg0.getButton()); } } });
/** * Initialize the bodies, anchors, and length using the world anchors. * * @param b1 First body * @param b2 Second body * @param anchor1 World anchor on first body * @param anchor2 World anchor on second body */ public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { bodyA = b1; bodyB = b2; localAnchorA.set(bodyA.getLocalPoint(anchor1)); localAnchorB.set(bodyB.getLocalPoint(anchor2)); Vec2 d = anchor2.sub(anchor1); length = d.length(); } }
public void MoveAABB(AABB aabb) { Vec2 d = new Vec2(); d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f); d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f); // d.x = 2.0f; // d.y = 0.0f; aabb.lowerBound.addLocal(d); aabb.upperBound.addLocal(d); Vec2 c0 = aabb.lowerBound.add(aabb.upperBound).mulLocal(.5f); Vec2 min = new Vec2(); min.set(-worldExtent, 0.0f); Vec2 max = new Vec2(); max.set(worldExtent, 2.0f * worldExtent); Vec2 c = MathUtils.clamp(c0, min, max); aabb.lowerBound.addLocal(c.sub(c0)); aabb.upperBound.addLocal(c.sub(c0)); }
@Override public void step(TestbedSettings settings) { // TODO Auto-generated method stub super.step(settings); // Traverse the contact results. Apply a force on shapes // that overlap the sensor. for (int i = 0; i < e_count; ++i) { if (m_touching[i].tf == false) { continue; } Body body = m_bodies[i]; Body ground = m_sensor.getBody(); CircleShape circle = (CircleShape) m_sensor.getShape(); Vec2 center = ground.getWorldPoint(circle.m_p); Vec2 position = body.getPosition(); Vec2 d = center.sub(position); if (d.lengthSquared() < Settings.EPSILON * Settings.EPSILON) { continue; } d.normalize(); Vec2 F = d.mulLocal(100f); body.applyForce(F, position); } }
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); }
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA); p2 = jd.bodyB.getWorldPoint(jd.localAnchorB); d = p2.sub(p1); jd.length = d.length(); m_joints[0] = getWorld().createJoint(jd); p1 = jd.bodyA.getWorldPoint(jd.localAnchorA); p2 = jd.bodyB.getWorldPoint(jd.localAnchorB); d = p2.sub(p1); jd.length = d.length(); m_joints[1] = getWorld().createJoint(jd); p1 = jd.bodyA.getWorldPoint(jd.localAnchorA); p2 = jd.bodyB.getWorldPoint(jd.localAnchorB); d = p2.sub(p1); jd.length = d.length(); m_joints[2] = getWorld().createJoint(jd); p1 = jd.bodyA.getWorldPoint(jd.localAnchorA); p2 = jd.bodyB.getWorldPoint(jd.localAnchorB); d = p2.sub(p1); jd.length = d.length(); m_joints[3] = getWorld().createJoint(jd); p1 = jd.bodyA.getWorldPoint(jd.localAnchorA); p2 = jd.bodyB.getWorldPoint(jd.localAnchorB); d = p2.sub(p1); jd.length = d.length(); m_joints[4] = getWorld().createJoint(jd);
/** * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) { bodyA = b1; bodyB = b2; groundAnchorA = ga1; groundAnchorB = ga2; localAnchorA = bodyA.getLocalPoint(anchor1); localAnchorB = bodyB.getLocalPoint(anchor2); Vec2 d1 = anchor1.sub(ga1); lengthA = d1.length(); Vec2 d2 = anchor2.sub(ga2); lengthB = d2.length(); ratio = r; assert (ratio > Settings.EPSILON); } }
/** * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) { bodyA = b1; bodyB = b2; groundAnchorA = ga1; groundAnchorB = ga2; localAnchorA = bodyA.getLocalPoint(anchor1); localAnchorB = bodyB.getLocalPoint(anchor2); Vec2 d1 = anchor1.sub(ga1); lengthA = d1.length(); Vec2 d2 = anchor2.sub(ga2); lengthB = d2.length(); ratio = r; assert (ratio > Settings.EPSILON); } }
Vec2 p = m_rayCastInput.p2.sub(m_rayCastInput.p1) .mulLocal(m_rayActor.fraction).addLocal(m_rayCastInput.p1); getDebugDraw().drawPoint(p, 6.0f, cr);
public void MoveProxy() { for (int i = 0; i < e_actorCount; ++i) { int j = MathUtils.abs(rand.nextInt() % e_actorCount); Actor actor = m_actors[j]; if (actor.proxyId == -1) { continue; } AABB aabb0 = new AABB(actor.aabb); MoveAABB(actor.aabb); Vec2 displacement = actor.aabb.getCenter().sub(aabb0.getCenter()); m_tree.moveProxy(actor.proxyId, new AABB(actor.aabb), displacement); return; } }
/** * Initialize the bodies, anchors, and length using the world anchors. * * @param b1 First body * @param b2 Second body * @param anchor1 World anchor on first body * @param anchor2 World anchor on second body */ public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { bodyA = b1; bodyB = b2; localAnchorA.set(bodyA.getLocalPoint(anchor1)); localAnchorB.set(bodyB.getLocalPoint(anchor2)); Vec2 d = anchor2.sub(anchor1); length = d.length(); } }
/** * Initialize the bodies, anchors, and length using the world * anchors. * @param b1 First body * @param b2 Second body * @param anchor1 World anchor on first body * @param anchor2 World anchor on second body */ public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { bodyA = b1; bodyB = b2; localAnchorA.set(bodyA.getLocalPoint(anchor1)); localAnchorB.set(bodyB.getLocalPoint(anchor2)); Vec2 d = anchor2.sub(anchor1); length = d.length(); } }
public void MoveAABB(AABB aabb) { Vec2 d = new Vec2(); d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f); d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f); // d.x = 2.0f; // d.y = 0.0f; aabb.lowerBound.addLocal(d); aabb.upperBound.addLocal(d); Vec2 c0 = aabb.lowerBound.add(aabb.upperBound).mulLocal(.5f); Vec2 min = new Vec2(); min.set(-worldExtent, 0.0f); Vec2 max = new Vec2(); max.set(worldExtent, 2.0f * worldExtent); Vec2 c = MathUtils.clamp(c0, min, max); aabb.lowerBound.addLocal(c.sub(c0)); aabb.upperBound.addLocal(c.sub(c0)); }