Examples of Circle


Examples of net.phys2d.raw.shapes.Circle

    for (int y=0;y<5;y++) {
      int xbase = 250 - (y * 21);
      for (int x=0;x<y+1;x++) {
        DynamicShape shape = new Box(40,40);
        if ((x == 1) && (y == 2)) {
          shape = new Circle(19);
        }
        if ((x == 1) && (y == 4)) {
          shape = new Circle(19);
        }
        if ((x == 3) && (y == 4)) {
          shape = new Circle(19);
        }
        Body body2 = new Body("Mover1", shape, 100.0f);
        body2.setPosition(xbase + (x * 42), y*45);
        world.add(body2);
      }
 
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

    world.add(body1);
    body1 = new StaticBody("Ground1", new Box(20.0f, 400.0f));
    body1.setPosition(460.0f, 150);
    world.add(body1);
   
    Body body2 = new Body("Mover1", new Circle(15), 10.0f);
    body2.setPosition(200.0f, 30.0f);
    world.add(body2);
    Body body5 = new Body("Mover1", new Circle(15), 10.0f);
    body5.setPosition(-20.0f, 80.0f);
    world.add(body5);
    Body body3 = new Body("Mover2", new Circle(15), 10.0f);
    body3.setPosition(300.0f, 50.0f);
    world.add(body3);
    Body body4 = new Body("Mover3", new Circle(15), 10.0f);
    body4.setPosition(250.0f, 70.0f);
    world.add(body4);
   
    Joint j = new FixedJoint(body2,body3);
    world.add(j);
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

 
  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body leftAxis = new StaticBody(new Circle(10));
    leftAxis.setPosition(100,250);
    leftAxis.setRestitution(1);
    world.add(leftAxis);
   
    wheel = new Body(new Circle(70),400);
    wheel.setPosition(400, 250);
    wheel.setMoveable(false);
    wheel.setDamping(5f);
    world.add(wheel);
   
    Body socket = new Body(new Circle(10),50);
    socket.setPosition(300, 250);
    socket.setRestitution(1);
    world.add(socket);
   
    FixedAngleJoint angle = new FixedAngleJoint(leftAxis,socket,new Vector2f(),new Vector2f(),0);
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

 
  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body knot = new StaticBody(new Circle(10));
    knot.setPosition(250,100);
    world.add(knot);
   
    int N=5;
    Body bodies[] = new Body[N];
    for(int i=0;i<N;i++){
      Body ball = new Body(new Circle(5),10);
      ball.setDamping(0.01f);
      ball.setPosition(280+i*30,100);
      world.add(ball);
      bodies[i]=ball;
    }
 
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

    world.add(body1);
    Body body3 = new StaticBody("Ground2", new Box(200.0f, 20.0f));
    body3.setPosition(250.0f, 100);
    world.add(body3);
   
    Body swing = new Body("Swing", new Circle(10), 50);
    swing.setPosition(160.0f, 300);
    world.add(swing);
    Body swing2 = new Body("Swing", new Circle(10), 50);
    swing2.setPosition(340.0f, 300);
    world.add(swing2);
    Body swing3 = new Body("Swing", new Box(250.0f, 10.0f), 50);
    swing3.setPosition(250.0f, 285);
    swing3.setFriction(4.0f);
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

   * @param g The graphics context on which to draw
   * @param body The body to be drawn
   * @param fill True if we should draw it filled (indicates a collision)
   */
  protected void drawCircleBody(Graphics2D g, Body body, boolean fill) {
    Circle circle = (Circle) body.getShape();
    drawCircleBody(g,body,circle,fill);
    drawAABody(g,body,body.getShape().getBounds());
  }
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

    for (int i=0;i<9;i++) {
      float size = 6;
      if (i == 0) {
        size = 10;
      }
      DynamicShape shape = new Circle(size);
      Body body = new Body(shape, i == 0 ? 100.0f : 10.0f);
      body.setFriction(0.4f);
      body.setPosition(170.0f + (i*20), 171.0f);
      body.setRotation(0.0f);
      world.add(body);
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

    body2.setPosition(230.0f, 280.0f);
    world.add(body2);
    body2 = new Body("Mover1", new Box(40,40), 10.0f);
    body2.setPosition(280.0f, 280.0f);
    world.add(body2);
    body2 = new Body("Mover1", new Circle(20), 10.0f);
    body2.setPosition(380.0f, 280.0f);
    world.add(body2);
  }
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

  /**
   * @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();
    Circle circle = (Circle) bodyB.getShape();
   
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
    ROVector2f startB = bodyB.getPosition();
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);
//    endB.add(startB);// TODO: inline endB into equations below, this last operation will be useless..
   
    //TODO: reuse mathutil.intersect
//    float d = (endB.y - startB.getY()) * (endA.x - startA.x);
//    d -= (endB.x - startB.getX()) * (endA.y - startA.y);
//   
//    float uA = (endB.x - startB.getX()) * (startA.y - startB.getY());
//    uA -= (endB.y - startB.getY()) * (startA.x - startB.getX());
//    uA /= d;
    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    Vector2f position = null;
   
    if ( uA < 0 ) { // the intersection is somewhere before startA
      position = startA;
    } else if ( uA > 1 ) { // the intersection is somewhere after endA
      position = endA;
    } else {
      position = new Vector2f(
          startA.x + uA * (endA.x - startA.x),
          startA.y + uA * (endA.y - startA.y));
    }
   
    Vector2f normal = endB; // reuse of vector object
    normal.set(startB);
    normal.sub(position);
    float distSquared = normal.lengthSquared();
    float radiusSquared = circle.getRadius() * circle.getRadius();
   
    if ( distSquared < radiusSquared ) {
      contacts[0].setPosition(position);
      contacts[0].setFeature(new FeaturePair());
     
      normal.normalise();
      contacts[0].setNormal(normal);
     
      float separation = (float) Math.sqrt(distSquared) - circle.getRadius();
      contacts[0].setSeparation(separation);
     
      return 1;
    }
   
View Full Code Here

Examples of net.phys2d.raw.shapes.Circle

  private void nextStep() {
    if (step == CREATE) {
      System.out.println("Generating 100");
      for (int i=0;i<100;i++) {
        float size = (float) (10 + (Math.random() * 20));
        Body body = new Body(new Circle(size),1);
        body.setPosition((float) (Math.random() * 500)+50, (float) (Math.random() * 500)+50);
        bodies.add(body);
      }
      step = COLLIDE;
    } else if (step == COLLIDE) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.