Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


            return new Rectangle(center.x - 5, center.y - 5, 10, 10);
        if (shape.getType() == ShapeType.POLYGON) {
            java.awt.Polygon result = new java.awt.Polygon();
            PolygonShape pshape = (PolygonShape) shape;
            for (int i = 0; i < pshape.getVertexCount(); i++) {
                Vec2 v = pshape.getVertex(i);
                result.addPoint((int) (v.x * scale.x) + center.x,
                                (int) (v.y * scale.y) + center.y);
            }
            return result;
        }
View Full Code Here


  private final TimeOfImpact toi;
  private final Distance dist;

  public DefaultWorldPool(int argSize, int argContainerSize) {
    vecs = new OrderedStack<Vec2>(argSize, argContainerSize) {
      protected Vec2 newInstance() { return new Vec2(); }
    };
    vec3s = new OrderedStack<Vec3>(argSize, argContainerSize) {
      protected Vec3 newInstance() { return new Vec3(); }
    };
    mats = new OrderedStack<Mat22>(argSize, argContainerSize) {
View Full Code Here

  public final Vec2[] getVec2Array(int argLength) {
    if (!avecs.containsKey(argLength)) {
      Vec2[] ray = new Vec2[argLength];
      for (int i = 0; i < argLength; i++) {
        ray[i] = new Vec2();
      }
      avecs.put(argLength, ray);
    }

    assert (avecs.get(argLength).length == argLength) : "Array not built with correct length";
View Full Code Here

   * World contact point (point of intersection)
   */
  public final Vec2[] points;

  public WorldManifold() {
    normal = new Vec2();
    points = new Vec2[Settings.maxManifoldPoints];
    for (int i = 0; i < Settings.maxManifoldPoints; i++) {
      points[i] = new Vec2();
    }
  }
View Full Code Here

        // }
        //
        // cA.set(normal).mulLocal(radiusA).addLocal(pointA);
        // cB.set(normal).mulLocal(radiusB).subLocal(pointB).negateLocal();
        // points[0].set(cA).addLocal(cB).mulLocal(0.5f);
        final Vec2 pointA = pool3;
        final Vec2 pointB = pool4;

        normal.x = 1;
        normal.y = 0;
        // pointA.x = xfA.p.x + xfA.q.ex.x * manifold.localPoint.x + xfA.q.ey.x *
        // manifold.localPoint.y;
        // pointA.y = xfA.p.y + xfA.q.ex.y * manifold.localPoint.x + xfA.q.ey.y *
        // manifold.localPoint.y;
        // pointB.x = xfB.p.x + xfB.q.ex.x * manifold.points[0].localPoint.x + xfB.q.ey.x *
        // manifold.points[0].localPoint.y;
        // pointB.y = xfB.p.y + xfB.q.ex.y * manifold.points[0].localPoint.x + xfB.q.ey.y *
        // manifold.points[0].localPoint.y;
        Transform.mulToOut(xfA, manifold.localPoint, pointA);
        Transform.mulToOut(xfB, manifold.points[0].localPoint, pointB);

        if (MathUtils.distanceSquared(pointA, pointB) > Settings.EPSILON * Settings.EPSILON) {
          normal.x = pointB.x - pointA.x;
          normal.y = pointB.y - pointA.y;
          normal.normalize();
        }

        final float cAx = normal.x * radiusA + pointA.x;
        final float cAy = normal.y * radiusA + pointA.y;

        final float cBx = -normal.x * radiusB + pointB.x;
        final float cBy = -normal.y * radiusB + pointB.y;

        points[0].x = (cAx + cBx) * .5f;
        points[0].y = (cAy + cBy) * .5f;
      }
        break;
      case FACE_A: {
        final Vec2 planePoint = pool3;

        Rot.mulToOutUnsafe(xfA.q, manifold.localNormal, normal);
        Transform.mulToOut(xfA, manifold.localPoint, planePoint);

        final Vec2 clipPoint = pool4;

        for (int i = 0; i < manifold.pointCount; i++) {
          // b2Vec2 clipPoint = b2Mul(xfB, manifold->points[i].localPoint);
          // b2Vec2 cA = clipPoint + (radiusA - b2Dot(clipPoint - planePoint,
          // normal)) * normal;
          // b2Vec2 cB = clipPoint - radiusB * normal;
          // points[i] = 0.5f * (cA + cB);
          Transform.mulToOut(xfB, manifold.points[i].localPoint, clipPoint);
          // use cA as temporary for now
          // cA.set(clipPoint).subLocal(planePoint);
          // float scalar = radiusA - Vec2.dot(cA, normal);
          // cA.set(normal).mulLocal(scalar).addLocal(clipPoint);
          // cB.set(normal).mulLocal(radiusB).subLocal(clipPoint).negateLocal();
          // points[i].set(cA).addLocal(cB).mulLocal(0.5f);

          final float scalar =
              radiusA
                  - ((clipPoint.x - planePoint.x) * normal.x + (clipPoint.y - planePoint.y)
                      * normal.y);

          final float cAx = normal.x * scalar + clipPoint.x;
          final float cAy = normal.y * scalar + clipPoint.y;

          final float cBx = -normal.x * radiusB + clipPoint.x;
          final float cBy = -normal.y * radiusB + clipPoint.y;

          points[i].x = (cAx + cBx) * .5f;
          points[i].y = (cAy + cBy) * .5f;
        }
      }
        break;
      case FACE_B:
        final Vec2 planePoint = pool3;
        Rot.mulToOutUnsafe(xfB.q, manifold.localNormal, normal);
        Transform.mulToOut(xfB, manifold.localPoint, planePoint);

        // final Mat22 R = xfB.q;
        // normal.x = R.ex.x * manifold.localNormal.x + R.ey.x * manifold.localNormal.y;
        // normal.y = R.ex.y * manifold.localNormal.x + R.ey.y * manifold.localNormal.y;
        // final Vec2 v = manifold.localPoint;
        // planePoint.x = xfB.p.x + xfB.q.ex.x * v.x + xfB.q.ey.x * v.y;
        // planePoint.y = xfB.p.y + xfB.q.ex.y * v.x + xfB.q.ey.y * v.y;

        final Vec2 clipPoint = pool4;

        for (int i = 0; i < manifold.pointCount; i++) {
          // b2Vec2 clipPoint = b2Mul(xfA, manifold->points[i].localPoint);
          // b2Vec2 cB = clipPoint + (radiusB - b2Dot(clipPoint - planePoint,
          // normal)) * normal;
 
View Full Code Here

    super.setViewportTransform(viewportTransform);
  }

  @Override
  public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
    Vec2 vec = getWorldToScreen(argPoint);
    GL2 gl = panel.getGL().getGL2();
    gl.glBegin(GL2.GL_POINT);
    gl.glPointSize(argRadiusOnScreen);
    gl.glVertex2f(vec.x, vec.y);
    gl.glEnd();
View Full Code Here

   */
  public float ratio;

  public PulleyJointDef() {
    type = JointType.PULLEY;
    groundAnchorA = new Vec2(-1.0f, 1.0f);
    groundAnchorB = new Vec2(1.0f, 1.0f);
    localAnchorA = new Vec2(-1.0f, 0.0f);
    localAnchorB = new Vec2(1.0f, 0.0f);
    lengthA = 0.0f;
    lengthB = 0.0f;
    ratio = 1.0f;
    collideConnected = true;
  }
View Full Code Here

    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);
  }
View Full Code Here

   */
  public float dampingRatio;

  public DistanceJointDef() {
    type = JointType.DISTANCE;
    localAnchorA = new Vec2(0.0f, 0.0f);
    localAnchorB = new Vec2(0.0f, 0.0f);
    length = 1.0f;
    frequencyHz = 0.0f;
    dampingRatio = 0.0f;
  }
View Full Code Here

  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();
  }
View Full Code Here

TOP

Related Classes of org.jbox2d.common.Vec2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.