Package net.phys2d.raw.shapes

Examples of net.phys2d.raw.shapes.Box


   */
  protected void init(World world) {
    this.world = world;
    float relax = 0.8f;
   
    Body body1 = new StaticBody("Ground1", new Box(500.0f, 20.0f));
    body1.setPosition(250.0f, 400);
    world.add(body1);
   
    Body body2 = new Body("First", new Box(40.0f, 10.0f), 500);
    body2.setFriction(0.2f);
    body2.setPosition(80.0f, 300);
    world.add(body2);
   
    BasicJoint j = new BasicJoint(body1,body2,new Vector2f(40,300));
    j.setRelaxation(relax);
    world.add(j);
   
    int i;
    for (i=1;i<8;i++) {
      Body body3 = new Body("Teeter",new Box(40.0f, 10.0f), 500);
      body3.setFriction(0.2f);
      body3.setPosition(80.0f+(i*45), 300);
      world.add(body3);
     
      BasicJoint j2 = new BasicJoint(body2,body3,new Vector2f(65+(i*45),300));
 
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]);
    sweepline.sub(vertsB[2]);
View Full Code Here

    world.add(land6);
    Body land7 = new StaticBody("Line7", new Line(80,-10));
    land7.setPosition(460,180);
    world.add(land7);
   
    box = new Body("Faller", new Box(50,50), 1);
    box.setPosition(50,50);
    box.setRotation(-0.5f);
    world.add(box);
    Body other = new Body("Faller", new Circle(10), 1);
    other.setPosition(200,50);
View Full Code Here

        body1.setFriction(0);
        world.add(body1);
      }
    }

    Body body5 = new StaticBody("Ground1", new Box(20.0f, 500.0f));
    body5.setPosition(20.0f, 250);
    body5.setRestitution(1.0f);
    world.add(body5);
    Body body6 = new StaticBody("Ground2", new Box(20.0f, 500.0f));
    body6.setPosition(480.0f, 250);
    body6.setRestitution(1.0f);
    world.add(body6);
    Body body1 = new StaticBody("Ground3", new Box(500.0f, 20.0f));
    body1.setPosition(250.0f, 480);
    body1.setRestitution(1.0f);
    world.add(body1);
   
    Body body2 = new Body("Cue", new Circle(20.0f),1);
View Full Code Here

      }
    }

    System.out.println(bodies[3].getExcludedList());
   
    Body body5 = new StaticBody("Ground1", new Box(20.0f, 500.0f));
    body5.setPosition(20.0f, 250);
    body5.setRestitution(1.0f);
    world.add(body5);
    Body body6 = new StaticBody("Ground2", new Box(20.0f, 500.0f));
    body6.setPosition(480.0f, 250);
    body6.setRestitution(1.0f);
    world.add(body6);
    Body body1 = new StaticBody("Ground3", new Box(500.0f, 20.0f));
    body1.setPosition(250.0f, 480);
    body1.setRestitution(1.0f);
    world.add(body1);
  }
View Full Code Here

   */
  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    int numContacts = 0;
   
    Line line = (Line) bodyA.getShape();
    Box box = (Box) bodyB.getShape();
   
    Vector2f lineVec = new Vector2f(line.getDX(), line.getDY());
    lineVec.normalise()
    Vector2f axis = new Vector2f(-line.getDY(), line.getDX());
    axis.normalise();
   
    Vector2f res = new Vector2f();
    line.getStart().projectOntoUnit(axis, res);
    float linePos = getProp(res,axis);
   
    Vector2f c = MathUtil.sub(bodyB.getPosition(),bodyA.getPosition());
    c.projectOntoUnit(axis,res);
    float centre = getProp(res, axis);
   
    Vector2f[] pts = box.getPoints(bodyB.getPosition(), bodyB.getRotation());
    float[] tangent = new float[4];
    float[] proj = new float[4];
   
    int outOfRange = 0;
   
View Full Code Here

    boolean touches = boxBody.getShape().getBounds().touches(x1,y1,circleBody.getShape().getBounds(),x2,y2);
    if (!touches) {
      return 0;
    }
   
    Box box = (Box) boxBody.getShape();
    Circle circle = (Circle) circleBody.getShape();
   
    Vector2f[] pts = box.getPoints(boxBody.getPosition(), boxBody.getRotation());
    Line[] lines = new Line[4];
    lines[0] = new Line(pts[0],pts[1]);
    lines[1] = new Line(pts[1],pts[2]);
    lines[2] = new Line(pts[2],pts[3]);
    lines[3] = new Line(pts[3],pts[0]);
View Full Code Here

  }
 
  public org.newdawn.slick.geom.Shape shapeForBody(Body body) {
    Shape shape = body.getShape();
    if(shape instanceof Box) {
      Box box  = (Box) shape;
      ROVector2f[] points = box.getPoints(new Vector2f(0.0f, 0.0f), 0.0f);
      Polygon poly = new Polygon();
      for(ROVector2f point: points) {
        poly.addPoint(point.getX(), point.getY());
      }
      return poly;
View Full Code Here

    this.mass = mass;
    return oldMass;
  }
 
  public Body addAxisAlignedBox(Entity entity, float width, float height) {
    Body body = new Body(new Box(width, height), this.mass);
    body.setPosition(this.position.getX(), this.position.getY());
    body.setRotatable(false);
    return init(entity, body);
  }
View Full Code Here

    body.setPosition(this.position.getX(), this.position.getY());
    return init(entity, body);
  }
 
  public Body addAxisAlignedWall(Entity entity, float startX, float startY, float x, float y) {
    Body body = new StaticBody(new Box(x, y));
    body.setPosition(startX + x / 2.0f, startY + y / 2.0f);
    return init(entity, body);
  }
View Full Code Here

TOP

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

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.