Package net.phys2d.raw.shapes

Examples of net.phys2d.raw.shapes.Polygon


        float angle = (float) (i* 2 * Math.PI/noVerts);
        circleVerts[i] = new Vector2f(
            (float) (Math.cos(angle) * radius[i%radius.length]),
            (float) (Math.sin(angle) * radius[i%radius.length]));
      }
      Polygon circlePolygon = new Polygon(circleVerts);
      Body circle = new Body("circle", circlePolygon, 2);
      circle.setPosition(250, 150);
      world.add(circle);
     
      BasicJoint joint = new BasicJoint(ground, circle, new Vector2f(circle.getPosition()));
      world.add(joint);
    }
    {
      int outerCircleVerts = 30;
      int noVerts = 120;
      Vector2f[] circleVerts = new Vector2f[outerCircleVerts+1 + noVerts+1];
      for( int i = 0; i <= outerCircleVerts; i++ ) {
        float angle = (float) (i* 2 * Math.PI/outerCircleVerts);
        circleVerts[i] = new Vector2f(
            (float) (Math.cos(angle) * 150),
            (float) (Math.sin(angle) * 150));
      }
      float[] radius = {140, 133, 133, 140};
      for( int i = 0; i <= noVerts; i++ ) {
        float angle = (float) (i* 2 * Math.PI/noVerts);
        circleVerts[outerCircleVerts+1 + noVerts-i] = new Vector2f(
            (float) (Math.cos(angle) * radius[i%radius.length]),
            (float) (Math.sin(angle) * radius[i%radius.length]));
      }
      Polygon circlePolygon = new Polygon(circleVerts);
      Body circle = new Body("circle", circlePolygon, 30);
      circle.setPosition(250, 220);
      world.add(circle);
    }
   
    {
      int noVerts = 20;
      Vector2f[] circleVerts = new Vector2f[noVerts];
      float[] radius = {30,20,20,30};
      for( int i = 0; i < noVerts; i++ ) {
        float angle = (float) (i* 2 * Math.PI/noVerts);
        circleVerts[i] = new Vector2f(
            (float) (Math.cos(angle) * radius[i%radius.length]),
            (float) (Math.sin(angle) * radius[i%radius.length]));
      }
      Polygon circlePolygon = new Polygon(circleVerts);
      Body circle = new Body("circle", circlePolygon, 2);
      circle.setPosition(250, 300);
      world.add(circle);
     
      Vector2f[] nonConvexPoly = {new Vector2f(-20,-10), new Vector2f(20,-10), new Vector2f(10,0), new Vector2f(20,10), new Vector2f(-20,10), new Vector2f(-10,0)};
      Polygon poly = new Polygon(nonConvexPoly);
      Body nonConvexBody = new Body("poly", poly, 25);
      nonConvexBody.setPosition(250, 400);
      world.add(nonConvexBody);
     
      BasicJoint joint = new BasicJoint(circle,nonConvexBody, new Vector2f(circle.getPosition()));
View Full Code Here


public class PolygonPolygonCollider implements Collider {
  /**
   * @see net.phys2d.raw.collide.Collider#collide(net.phys2d.raw.Contact[], net.phys2d.raw.Body, net.phys2d.raw.Body)
   */
  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Polygon polyA = (Polygon) bodyA.getShape();
    Polygon polyB = (Polygon) bodyB.getShape();

    Vector2f[] vertsA = polyA.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = polyB.getVertices(bodyB.getPosition(), bodyB.getRotation());
   
    Vector2f centroidA = new Vector2f(polyA.getCentroid());
    centroidA.add(bodyA.getPosition());
    Vector2f centroidB = new Vector2f(polyB.getCentroid());
    centroidB.add(bodyB.getPosition());
   
    int[][] collEdgeCands = getCollisionCandidates(vertsA, vertsB, centroidA, centroidB);
    Intersection[][] intersections = getIntersectionPairs(vertsA, vertsB, collEdgeCands);   
    return populateContacts(contacts, vertsA, vertsB, intersections);
View Full Code Here

  /**
   * @see net.phys2d.raw.collide.Collider#collide(net.phys2d.raw.Contact[], net.phys2d.raw.Body, net.phys2d.raw.Body)
   */
  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Line line = (Line) bodyA.getShape();
    Polygon poly = (Polygon) bodyB.getShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only one shape
    // specifically the line, because it has only two vertices
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = poly.getVertices(bodyB.getPosition(), bodyB.getRotation());

    Vector2f pos = poly.getCentroid(bodyB.getPosition(), bodyB.getRotation());
   
    // using the z axis of a 3d cross product we determine on what side B is
    boolean isLeftOf = 0 > (pos.x - vertsA[0].x) * (vertsA[1].y - vertsA[0].y) - (vertsA[1].x - vertsA[0].x) * (pos.y - vertsA[0].y);
   
    // to get the proper intersection pairs we make sure
View Full Code Here

  /**
   * @see net.phys2d.raw.collide.Collider#collide(net.phys2d.raw.Contact[], net.phys2d.raw.Body, net.phys2d.raw.Body)
   */
  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Polygon poly = (Polygon) bodyA.getShape();
    Box box = (Box) bodyB.getShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only one shape
    // specifically the box, because it has fewer vertices.
    Vector2f[] vertsA = poly.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = box.getPoints(bodyB.getPosition(), bodyB.getRotation());
   
    // TODO: use a sweepline that has the smallest projection of the box
    // now we use just an arbitrary one
    Vector2f sweepline = new Vector2f(vertsB[1]);
View Full Code Here

 
  /**
   * @see net.phys2d.raw.collide.Collider#collide(net.phys2d.raw.Contact[], net.phys2d.raw.Body, net.phys2d.raw.Body)
   */
  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Polygon polyA = (Polygon) bodyA.getShape();
    Circle circle = (Circle) bodyB.getShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only the circle
    Vector2f[] vertsA = polyA.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    Vector2f centroidA = new Vector2f(polyA.getCentroid());
    centroidA.add(bodyA.getPosition());

   
    int[][] collPairs = getCollisionCandidates(vertsA, centroidA, circle.getRadius(), bodyB.getPosition());

View Full Code Here

public class PolygonPolygonCollider
  implements Collider
{
  public int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Polygon localPolygon1 = (Polygon)paramBody1.getShape();
    Polygon localPolygon2 = (Polygon)paramBody2.getShape();
    Vector2f[] arrayOfVector2f1 = localPolygon1.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f[] arrayOfVector2f2 = localPolygon2.getVertices(paramBody2.getPosition(), paramBody2.getRotation());
    Vector2f localVector2f1 = new Vector2f(localPolygon1.getCentroid());
    localVector2f1.add(paramBody1.getPosition());
    Vector2f localVector2f2 = new Vector2f(localPolygon2.getCentroid());
    localVector2f2.add(paramBody2.getPosition());
    int[][] arrayOfInt = getCollisionCandidates(arrayOfVector2f1, arrayOfVector2f2, localVector2f1, localVector2f2);
    Intersection[][] arrayOfIntersection = getIntersectionPairs(arrayOfVector2f1, arrayOfVector2f2, arrayOfInt);
    return populateContacts(paramArrayOfContact, arrayOfVector2f1, arrayOfVector2f2, arrayOfIntersection);
  }
View Full Code Here

public class LinePolygonCollider extends PolygonPolygonCollider
{
  public int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Line localLine = (Line)paramBody1.getShape();
    Polygon localPolygon = (Polygon)paramBody2.getShape();
    Vector2f[] arrayOfVector2f1 = localLine.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f[] arrayOfVector2f2 = localPolygon.getVertices(paramBody2.getPosition(), paramBody2.getRotation());
    Vector2f localVector2f1 = localPolygon.getCentroid(paramBody2.getPosition(), paramBody2.getRotation());
    int i = 0.0F > (localVector2f1.x - arrayOfVector2f1[0].x) * (arrayOfVector2f1[1].y - arrayOfVector2f1[0].y) - (arrayOfVector2f1[1].x - arrayOfVector2f1[0].x) * (localVector2f1.y - arrayOfVector2f1[0].y) ? 1 : 0;
    if (i != 0)
    {
      localVector2f2 = arrayOfVector2f1[0];
      arrayOfVector2f1[0] = arrayOfVector2f1[1];
View Full Code Here

public class PolygonBoxCollider extends PolygonPolygonCollider
{
  public int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Polygon localPolygon = (Polygon)paramBody1.getShape();
    Box localBox = (Box)paramBody2.getShape();
    Vector2f[] arrayOfVector2f1 = localPolygon.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f[] arrayOfVector2f2 = localBox.getPoints(paramBody2.getPosition(), paramBody2.getRotation());
    Vector2f localVector2f = new Vector2f(arrayOfVector2f2[1]);
    localVector2f.sub(arrayOfVector2f2[2]);
    EdgeSweep localEdgeSweep = new EdgeSweep(localVector2f);
    localEdgeSweep.addVerticesToSweep(true, arrayOfVector2f1);
View Full Code Here

public class PolygonCircleCollider extends PolygonPolygonCollider
{
  public int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Polygon localPolygon = (Polygon)paramBody1.getShape();
    Circle localCircle = (Circle)paramBody2.getShape();
    Vector2f[] arrayOfVector2f = localPolygon.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f localVector2f1 = new Vector2f(localPolygon.getCentroid());
    localVector2f1.add(paramBody1.getPosition());
    int[][] arrayOfInt = getCollisionCandidates(arrayOfVector2f, localVector2f1, localCircle.getRadius(), paramBody2.getPosition());
    int i = 0;
    for (int j = 0; j < arrayOfInt.length; j++)
    {
View Full Code Here

TOP

Related Classes of net.phys2d.raw.shapes.Polygon

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.