Package org.matheusdev.util.vecmath

Examples of org.matheusdev.util.vecmath.Vec2


      throw new IllegalArgumentException("elements < 3: This is not a Polygon.");
    }
    this.vertices = vertices;
    this.verticesCached = new Vec2[elements];
    this.center = calculateCenter();
    this.centerCached = new Vec2();

    this.normals = new Vec2[elements];
    for (int i = 0; i < normals.length; i++) normals[i] = new Vec2();
    this.mat = new Mat4();
    this.aabb = new Rect();
    this.circBounds = createCircularBounds(circBounds);
    updateFromMatrix();
  }
View Full Code Here


    for (int i = 0; i < vertices.length; i++) {
      vertX[i] = vertices[i].x;
      vertY[i] = vertices[i].y;
    }

    return new Vec2(Average.get(vertX), Average.get(vertY));
  }
View Full Code Here

    }
    return this;
  }

  protected Vec2 calculateNormal(int side) {
    Vec2 v0 = getTransformedVertex(side);
    Vec2 v1 = getTransformedVertex(side + 1);
    return normals[side].set(v1.x - v0.x, v1.y - v0.y).perpLeft().normalize();
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.matheusdev.util.collision.SATObject#project(org.matheusdev.util.vecmath.Vec2)
   */
  @Override
  public Vec2 project(Vec2 axis, Vec2 dest) {
    if (dest == null) dest = new Vec2();

    float min = Vec2.dot(axis, verticesCached[0]);
    float max = min;

    for (int i = 1; i < verticesCached.length; i++) {
View Full Code Here

  @Deprecated
  public static Vec2 polyVsPolyMTV(SATObject obj0, SATObject obj1) {
    if (circleVsCircle(obj0.getBounds(), obj1.getBounds())) {
      objectsTested++;
      float overlap = Float.MAX_VALUE;
      Vec2 smallest = null;

      Vec2[] axes0 = obj0.getAxes();
      Vec2[] axes1 = obj1.getAxes();

      for (Vec2 axis : axes0) {
        axesTested++;
        obj0.project(axis, proj0);
        obj1.project(axis, proj1);

        if (noProjOverlap(proj0, proj1)) {
          return null;
        } else {
          float o = projOverlap(proj0, proj1);

          if (o < overlap) {
            overlap = o;
            smallest = axis;
          }
        }
      }

      for (Vec2 axis : axes1) {
        axesTested++;
        obj0.project(axis, proj0);
        obj1.project(axis, proj1);

        if (noProjOverlap(proj0, proj1)) {
          return null;
        } else {
          float o = projOverlap(proj0, proj1);

          if (o < overlap) {
            overlap = o;
            smallest = axis;
          }
        }
      }
      Vec2 mtv = new Vec2(smallest.x * overlap, smallest.y * overlap);
      return mtv;
    } else {
      return null;
    }
  }
View Full Code Here

    if (circleVsCircle(obj.getBounds(), circ)) {
      objectsTested++;
      Vec2[] vertices = obj.getTransformedVertices();

      for (int i = 0; i < vertices.length; i++) {
        if (axes[i] == null) axes[i] = new Vec2();

        axes[i].set(circ.getCenter().x - vertices[i].x, circ.getCenter().y - vertices[i].y).normalize();
      }
      return seperatingAxesTest(axes, obj, circ);
    } else {
View Full Code Here

    return true;
  }

  public static boolean seperatingAxesTest(Vec2[] axes, Projectable p0, Projectable p1) {
    for (int i = 0; i < axes.length && axes[i] != null; i++) {
      Vec2 axis = axes[i];
      axesTested++;
      p0.project(axis, proj0);
      p1.project(axis, proj1);

      if (noProjOverlap(proj0, proj1)) {
View Full Code Here

  protected Circle circBounds;

  protected Mat4 mat;

  public Quad(float centerX, float centerY, float w, float h) {
    this(new Vec2(centerX, centerY), w, h);
  }
View Full Code Here

    this.center = center;

    float hw = w / 2;
    float hh = h / 2;

    this.topLeft = new Vec2(center.x - hw, center.y - hh);
    this.topRight = new Vec2(center.x + hw, center.y - hh);
    this.botRight = new Vec2(center.x + hw, center.y + hh);
    this.botLeft = new Vec2(center.x - hw, center.y + hh);

    this.verticesCached = new Vec2[4];
    this.normalsCached = new Vec2[4];
    this.satNormalCache = new Vec2[2];
    this.mat = new Mat4();
View Full Code Here

    return this;
  }

  protected Vec2 calculateNormal(Vec2 v0, Vec2 v1, Vec2 dest) {
    if (dest == null) dest = new Vec2();

    return dest.set(v1.x - v0.x, v1.y - v0.y).perpLeft().normalize();
  }
View Full Code Here

TOP

Related Classes of org.matheusdev.util.vecmath.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.