Package net.phys2d.raw

Examples of net.phys2d.raw.Body


  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body land = new StaticBody("Line1", new Line(130,30));
    land.setPosition(-30,200);
    world.add(land);
    Body land2 = new StaticBody("Line2", new Line(50,50));
    land2.setPosition(100,230);
    world.add(land2);
    Body land3 = new StaticBody("Line3", new Line(100,20));
    land3.setPosition(150,280);
    world.add(land3);
    Body land4 = new StaticBody("Line4", new Line(100,80));
    land4.setPosition(250,300);
    world.add(land4);
    Body land5 = new StaticBody("Line5", new Line(100,0));
    land5.setPosition(350,380);
    world.add(land5);
    Body land6 = new StaticBody("Line6", new Line(10,-200));
    land6.setPosition(450,380);
    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);
    other.setRotation(-0.5f);
    world.add(other);
    other = new Body("Faller", new Circle(10), 1);
    other.setPosition(225,50);
    other.setRotation(-0.5f);
    world.add(other);
    other = new Body("Faller", new Circle(10), 1);
    other.setPosition(250,50);
    other.setRotation(-0.5f);
    world.add(other);
    other = new Body("Faller", new Circle(10), 1);
    other.setPosition(275,50);
    other.setRotation(-0.5f);
    world.add(other);
    other = new Body("Faller", new Circle(10), 1);
    other.setPosition(300,50);
    other.setRotation(-0.5f);
    world.add(other);
  }
View Full Code Here


   * @see net.phys2d.raw.test.AbstractDemo#keyHit(char)
   */
  protected void keyHit(char c) {
    super.keyHit(c);
   
    Body newBody = null;
   
    if (c == 's') {   
      Vector2f[] circleVerts = new Vector2f[30];
      float[] radius = {20,10};
      for( int i = 0; i < 30; i++ ) {
        float angle = (float) (3*4 * i * Math.PI/180);
        circleVerts[i] = new Vector2f(
            (float) (Math.cos(angle) * radius[i%2]),
            (float) (Math.sin(angle) * radius[i%2]));
      }
      Polygon circlePolygon = new Polygon(circleVerts);
      newBody = new Body(circlePolygon, 4);
    } else if ( c == 'w' ) {
      newBody = new Body(new Circle(15), 2);
    } else if ( c == 'l' ) {
      newBody = new Body(new Line(0,-50,0,50), 1f);
    } else if ( c == 't' ) {
      Vector2f[] triangleVerts = {new Vector2f(-20, -20), new Vector2f(20,-20), new Vector2f(20,20)};
      ConvexPolygon trianglePolygon = new ConvexPolygon(triangleVerts);
      newBody = new Body(trianglePolygon, 3);
    } else if ( c == 'b' ) {
      newBody = new Body(new Box(20,30), 3);
    } else {
      return;
    }
   
    newBody.setPosition(250, 150);
    newBody.setRotation((float) (random.nextFloat() * 2 * Math.PI));
    world.add(newBody);
   
  }
 
View Full Code Here

////    ground2.setBitmask(0l);

   
   
    Line line1 = new Line(300, 0);
    Body ground1 = new StaticBody("line", line1);
    ground1.setPosition(100, 400);
    world.add(ground1);
   
    Line line2 = new Line(-100, -100);
    Body ground2 = new StaticBody("line", line2);
    ground2.setPosition(140, 420);
    world.add(ground2);
   
    Line line3 = new Line(100, -100);
    Body ground3 = new StaticBody("line", line3);
    ground3.setPosition(360, 420);
    world.add(ground3);
   
   
   
//    Vector2f[] boxVerts = {new Vector2f(-10, -10), new Vector2f(10,-10), new Vector2f(10,10), new Vector2f(-10,10)};
View Full Code Here

 
  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    b1= new Body(new Circle(15),1e3f);
    b1.setMoveable(false);
    b1.setPosition(250,250);
    b1.setRotDamping(10);
    b1.setRotation(0.01f);
   
    world.add(b1);
    final int N=15;
    final Body bodies[] = new Body[N];
    for(int i=0;i<N;i++){
      final Body b2 = new Body(new Circle(8),10);
      b2.setPosition(250+30*(1+i),250);
      world.add(b2);
     
      bodies[i]=b2;
    }
   
 
View Full Code Here

  protected void init(World world) {
    world.setGravity(0,0);
   
    for (int y=0;y<4;y++) {
      for (int x=0;x<y+1;x++) {
        Body body1 = new Body("Ball"+x+","+y, new Circle(20.0f), 1);
        //Body body1 = new Body("Ball"+x+","+y, new Box(40.0f,40.0f), 1);
        body1.setPosition(250.0f+(x*40)-(y*20), 200+(y*35f));
        body1.setRestitution(1.0f);
        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);
    //Body body2 = new Body("Cue", new Box(40.0f,40.0f),1);
    body2.setPosition(250,0);
    body2.adjustVelocity(new Vector2f(0,100));
    body2.setRestitution(1.0f);
    body2.setFriction(0);
    world.add(body2);
  }
View Full Code Here

   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body[] bodies = new Body[5];
    for (int x=0;x<4;x++) {
      bodies[x] = new Body("Ball"+x, new Circle(20.0f), 1);
      bodies[x].setPosition(220.0f+(x*20), 200+(x*40f));
      bodies[x].setRestitution(1.0f);
      world.add(bodies[x]);
    }
    for (int x=0;x<4;x++) {
      for (int i=0;i<4;i++) {
        bodies[x].addExcludedBody(bodies[i]);
      }
    }

    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

 
  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body body1 = new StaticBody("Ground1", new Box(400.0f, 20.0f));
    body1.setPosition(250.0f, 50);
    world.add(body1);
   
    Body body2 = new Body("Mover1", new Box(20.0f, 20.0f), 100.0f);
    body2.setPosition(100.0f, 100f);
    world.add(body2);
   
    Body body3 = new Body("Mover2", new Box(20.0f, 20.0f), 100.0f);
    body3.setPosition(150.0f, 150f);
    world.add(body3);
   
    Body body4 = new Body("Mover3", new Box(20.0f, 20.0f), 50.0f);
    body4.setPosition(200f, 200f);
    world.add(body4);
   
    SpringJoint joint1 = new SpringJoint(body1, body2, new Vector2f(150,60), new Vector2f(100, 90));
    joint1.setBrokenSpringConst(10);
    joint1.setCompressedSpringConst(0);
View Full Code Here

    spaces.clear();
   
    Space space = new Space(0,0,0,0);
   
    for (int i=0;i<bodies.size();i++) {
      Body body = bodies.get(i);
     
      space.addAABox(body.getShape().getBounds(),
               body.getPosition().getX(),
               body.getPosition().getY());
      space.addBody(body);
    }
   
    splitSpace(space, 0, maxInSpace, spaces);
   
View Full Code Here

      spaces[1] = new Space(x1,y1+height,width,height);
      spaces[2] = new Space(x1+width,y1,width,height);
      spaces[3] = new Space(x1+width,y1+height,width,height);
     
      for (int i=0;i<size();i++) {
        Body body = get(i);
        for (int j=0;j<4;j++) {
          if (spaces[j].touches(body.getShape().getBounds(),
                      body.getPosition().getX(),
                      body.getPosition().getY())) {
            spaces[j].add(body);
          }
        }
      }
View Full Code Here

  }
 
  public Body addFigure(float footX, float footY) {
    float oldMass = setMass(Figure.MASS);
    ROVector2f oldPosition = setPosition(new Vector2f(footX + Figure.WIDTH / 2.0f, footY - Figure.HEIGHT / 2.0f));
    Body figure = addAxisAlignedBox(new Figure(), Figure.WIDTH, Figure.HEIGHT);
    setMass(oldMass);
    setPosition(oldPosition);
    return figure;
  }
View Full Code Here

TOP

Related Classes of net.phys2d.raw.Body

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.