Refine search
public PolygonShape() { super(ShapeType.POLYGON); m_count = 0; m_vertices = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_vertices.length; i++) { m_vertices[i] = new Vec2(); } m_normals = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_normals.length; i++) { m_normals[i] = new Vec2(); } setRadius(Settings.polygonRadius); m_centroid.setZero(); }
Vec2.crossToOutUnsafe(wB, m_rB, Cdot); Cdot.addLocal(vB); temp.set(m_impulse).mulLocal(m_gamma).addLocal(m_C).addLocal(Cdot).negateLocal(); Mat22.mulToOutUnsafe(m_mass, temp, impulse); oldImpulse.set(m_impulse); m_impulse.addLocal(impulse); float maxImpulse = data.step.dt * m_maxForce; if (m_impulse.lengthSquared() > maxImpulse * maxImpulse) { m_impulse.mulLocal(maxImpulse / m_impulse.length()); impulse.set(m_impulse).subLocal(oldImpulse); wB += m_invIB * Vec2.cross(m_rB, impulse);
protected PrismaticJoint(IWorldPool argWorld, PrismaticJointDef def) { super(argWorld, def); m_localAnchorA = new Vec2(def.localAnchorA); m_localAnchorB = new Vec2(def.localAnchorB); m_localXAxisA = new Vec2(def.localAxisA); m_localXAxisA.normalize(); m_localYAxisA = new Vec2(); Vec2.crossToOutUnsafe(1f, m_localXAxisA, m_localYAxisA); m_referenceAngle = def.referenceAngle; m_impulse = new Vec3(); m_motorMass = 0.0f; m_motorImpulse = 0.0f; m_lowerTranslation = def.lowerTranslation; m_upperTranslation = def.upperTranslation; m_maxMotorForce = def.maxMotorForce; m_motorSpeed = def.motorSpeed; m_enableLimit = def.enableLimit; m_enableMotor = def.enableMotor; m_limitState = LimitState.INACTIVE; m_K = new Mat33(); m_axis = new Vec2(); m_perp = new Vec2(); }
@Override public synchronized void step(TestbedSettings settings) { super.step(settings); if (m_count < MAX_NUM) { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 10.0f); Body body = m_world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.125f, 0.125f); body.createFixture(shape, 1.0f); ++m_count; } }
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 initAxis() { BodyDef axisDef = new BodyDef(); axisDef.type = BodyType.STATIC; axisDef.position = new Vec2(3, 3); axis = world.createBody(axisDef); CircleShape axisShape = new CircleShape(); axisShape.setRadius(0.02f); axisShape.m_p.set(0, 0); FixtureDef axisFixture = new FixtureDef(); axisFixture.shape = axisShape; axis.createFixture(axisFixture); }
private void initReel() { BodyDef reelDef = new BodyDef(); reelDef.type = BodyType.DYNAMIC; reelDef.position = new Vec2(3, 3); reel = world.createBody(reelDef); FixtureDef fixture = new FixtureDef(); fixture.friction = 0.5f; fixture.restitution = 0.4f; fixture.density = 1; int parts = 30; for (int i = 0; i < parts; ++i) { PolygonShape shape = new PolygonShape(); double angle1 = i / (double) parts * 2 * Math.PI; double x1 = 2.7 * Math.cos(angle1); double y1 = 2.7 * Math.sin(angle1); double angle2 = (i + 1) / (double) parts * 2 * Math.PI; double x2 = 2.7 * Math.cos(angle2); double y2 = 2.7 * Math.sin(angle2); double angle = (angle1 + angle2) / 2; double x = 0.01 * Math.cos(angle); double y = 0.01 * Math.sin(angle); shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2), new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4); fixture.shape = shape; reel.createFixture(fixture); } }
for (Body b = m_bodyList; b != null; b = b.getNext()) { xf.set(b.getTransform()); for (Fixture f = b.getFixtureList(); f != null; f = f.getNext()) { if (b.isActive() == false) { color.set(0.5f, 0.5f, 0.3f); drawShape(f, xf, color, wireframe); } else if (b.getType() == BodyType.STATIC) { color.set(0.5f, 0.9f, 0.3f); drawShape(f, xf, color, wireframe); } else if (b.getType() == BodyType.KINEMATIC) { color.set(0.5f, 0.5f, 0.9f); drawShape(f, xf, color, wireframe); } else if (b.isAwake() == false) { color.set(0.5f, 0.5f, 0.5f); if (aabb != null) { Vec2[] vs = avs.get(4); vs[0].set(aabb.lowerBound.x, aabb.lowerBound.y); vs[1].set(aabb.upperBound.x, aabb.lowerBound.y); vs[2].set(aabb.upperBound.x, aabb.upperBound.y); vs[3].set(aabb.lowerBound.x, aabb.upperBound.y); m_debugDraw.drawPolygon(vs, 4, color); for (Body b = m_bodyList; b != null; b = b.getNext()) { xf.set(b.getTransform()); xf.p.set(b.getWorldCenter()); m_debugDraw.drawTransform(xf);
@Override public void initTest(boolean deserialized) { { BodyDef bd = new BodyDef(); Body ground = m_world.createBody(bd); ChainShape shape = new ChainShape(); Vec2[] vertices = new Vec2[] {new Vec2(-20, 0), new Vec2(20, 0), new Vec2(20, 40), new Vec2(-20, 40)}; shape.createLoop(vertices, 4); ground.createFixture(shape, 0.0f); } m_world.setParticleRadius(0.15f); m_world.setParticleDamping(0.2f); { PolygonShape shape = new PolygonShape(); shape.setAsBox(8, 10, new Vec2(-12, 10.1f), 0); ParticleGroupDef pd = new ParticleGroupDef(); pd.shape = shape; m_world.createParticleGroup(pd); } }
setAsBox(1.0f, 1.0f); return; Vec2 r = pool1.set(ps[ie]).subLocal(ps[hull[m]]); Vec2 v = pool2.set(ps[j]).subLocal(ps[hull[m]]); float c = Vec2.cross(r, v); if (c < 0.0f) { ie = j; if (c == 0.0f && v.lengthSquared() > r.lengthSquared()) { ie = j; m_vertices[i] = new Vec2(); m_vertices[i].set(ps[hull[i]]); final int i1 = i; final int i2 = i + 1 < m_count ? i + 1 : 0; edge.set(m_vertices[i2]).subLocal(m_vertices[i1]); assert (edge.lengthSquared() > Settings.EPSILON * Settings.EPSILON); Vec2.crossToOutUnsafe(edge, 1f, m_normals[i]); m_normals[i].normalize(); computeCentroidToOut(m_vertices, m_count, m_centroid);
public void createCircle() { float radius = 2.0f; CircleShape shape = new CircleShape(); shape.m_p.setZero(); shape.m_radius = radius; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 1.0f; fd.friction = 0.0f; Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random()); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = p; //bd.allowSleep = false; Body body = getWorld().createBody(bd); body.createFixture(fd); }
localPointA.set(m_proxyA.getVertex(cache.indexA[0])); localPointB.set(m_proxyB.getVertex(cache.indexB[0])); Transform.mulToOutUnsafe(xfa, localPointA, pointA); Transform.mulToOutUnsafe(xfb, localPointB, pointB); m_axis.set(pointB).subLocal(pointA); float s = m_axis.normalize(); return s; } else if (cache.indexA[0] == cache.indexA[1]) { localPointB1.set(m_proxyB.getVertex(cache.indexB[0])); localPointB2.set(m_proxyB.getVertex(cache.indexB[1])); temp.set(localPointB2).subLocal(localPointB1); Vec2.crossToOutUnsafe(temp, 1f, m_axis); m_axis.normalize(); m_localPoint.set(localPointB1).addLocal(localPointB2).mulLocal(.5f); Transform.mulToOutUnsafe(xfb, m_localPoint, pointB); localPointA.set(proxyA.getVertex(cache.indexA[0])); temp.set(pointA).subLocal(pointB); float s = Vec2.dot(temp, normal); if (s < 0.0f) { m_axis.negateLocal(); s = -s; localPointA1.set(m_proxyA.getVertex(cache.indexA[0])); localPointA2.set(m_proxyA.getVertex(cache.indexA[1]));
assert (m_world.isLocked() == false); if (m_world.isLocked() == true) { return; m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center); assert (m_I > 0.0f); m_invI = 1.0f / m_I; final Vec2 oldCenter = m_world.getPool().popVec2(); oldCenter.set(m_sweep.c); m_sweep.localCenter.set(massData.center); Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0); m_sweep.c.set(m_sweep.c0); final Vec2 temp = m_world.getPool().popVec2(); temp.set(m_sweep.c).subLocal(oldCenter); Vec2.crossToOut(m_angularVelocity, temp, temp); m_linearVelocity.addLocal(temp); m_world.getPool().pushVec2(2);
float distanceSqr1 = closestPoint.lengthSquared(); float distanceSqr2 = distanceSqr1; distanceSqr2 = closestPoint.lengthSquared(); if (d.lengthSquared() < Settings.EPSILON * Settings.EPSILON) { Rot.mulTransUnsafe(transformA.q, d.negateLocal(), temp); vertex.indexA = proxyA.getSupport(temp); Transform.mulToOutUnsafe(transformA, proxyA.getVertex(vertex.indexA), vertex.wA); Rot.mulTransUnsafe(transformB.q, d.negateLocal(), temp); vertex.indexB = proxyB.getSupport(temp); Transform.mulToOutUnsafe(transformB, proxyB.getVertex(vertex.indexB), vertex.wB); vertex.w.set(vertex.wB).subLocal(vertex.wA); normal.set(output.pointB).subLocal(output.pointA); normal.normalize(); temp.set(normal).mulLocal(rA); output.pointA.addLocal(temp); temp.set(normal).mulLocal(rB); output.pointB.subLocal(temp); } else { output.pointA.addLocal(output.pointB).mulLocal(.5f); output.pointB.set(output.pointA); output.distance = 0.0f;
Vec2.crossToOutUnsafe(wA, m_rA, vpA); vpA.addLocal(vA); Vec2.crossToOutUnsafe(wB, m_rB, vpB); vpB.addLocal(vB); float Cdot = Vec2.dot(m_u, vpB.subLocal(vpA));
public final void computeCentroidToOut(final Vec2[] vs, final int count, final Vec2 out) { assert (count >= 3); out.set(0.0f, 0.0f); float area = 0.0f; // pRef is the reference point for forming triangles. // It's location doesn't change the result (except for rounding error). final Vec2 pRef = pool1; pRef.setZero(); final Vec2 e1 = pool2; final Vec2 e2 = pool3; final float inv3 = 1.0f / 3.0f; for (int i = 0; i < count; ++i) { // Triangle vertices. final Vec2 p1 = pRef; final Vec2 p2 = vs[i]; final Vec2 p3 = i + 1 < count ? vs[i + 1] : vs[0]; e1.set(p2).subLocal(p1); e2.set(p3).subLocal(p1); final float D = Vec2.cross(e1, e2); final float triangleArea = 0.5f * D; area += triangleArea; // Area weighted centroid e1.set(p1).addLocal(p2).addLocal(p3).mulLocal(triangleArea * inv3); out.addLocal(e1); } // Centroid assert (area > Settings.EPSILON); out.mulLocal(1.0f / area); }
public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def) { super(argWorld.getPool(), def); world = argWorld; if (def.bodies.size() <= 2) { 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; djd.initialize(bodies[i], bodies[next], bodies[i].getWorldCenter(), bodies[next].getWorldCenter()); distanceJoints[i] = (DistanceJoint) world.createJoint(djd); normals[i] = new Vec2();