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 body1 = new StaticBody("Ground1", new Box(500.0f, 20.0f));
    body1.setPosition(250.0f, 400);
    world.add(body1);
   
    Body body2 = new Body("Teeter", new Box(250.0f, 10.0f), 5);
    body2.setFriction(0.5f);
    body2.setPosition(250.0f, 370);
    world.add(body2);
   
    Body body3 = new Body("light1", new Box(10.0f, 10.0f), 10);
    body3.setPosition(135, 360);
    world.add(body3);
    Body body4 = new Body("light2", new Box(10.0f, 10.0f), 10);
    body4.setPosition(150, 360);
    world.add(body4);
   
    Body body5 = new Body("weight", new Box(25.0f, 25.0f), 30);
    body5.setPosition(350, 50);
    world.add(body5);
   
    BasicJoint j = new BasicJoint(body1,body2,new Vector2f(250,370));
    world.add(j);
  }
View Full Code Here


    final Vector2f direction = new Vector2f(p2);
    direction.sub(p1);
    direction.normalise();
    direction.scale(20);

    final Body bodies[] = new Body[N];
    final Vector2f pos = new Vector2f(p1);
    for (int i = 0; i < N; i++) {
      final Body body = new Body(new Box(15, 4), 5);
      body.setDamping(0.05f);
      body.setRotation(initRot);
      for (int j = 0; j < i; j++) {
        body.addExcludedBody(bodies[j]);
      }
      pos.add(direction);
      body.setPosition(pos.x,pos.y);
      bodies[i] = body;
      world.add(body);
    }

    for (int i = 1; i < N; i++) {
View Full Code Here

  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    // world.setGravity(0, 0);
    final Body b1 = new Body(new Circle(5), Body.INFINITE_MASS);
    b1.setPosition(100, 50);
    world.add(b1);

    final Body b2 = new Body(new Circle(5), Body.INFINITE_MASS);
    b2.setPosition(300, 250);
    world.add(b2);

    final Body b3 = new Body(new Circle(5), Body.INFINITE_MASS);
    b3.setPosition(450, 400);
    world.add(b3);

    final Body b4 = new Body(new Circle(5), Body.INFINITE_MASS);
    b4.setPosition(150, 380);
    world.add(b4);

    final Body b5 = new Body(new Circle(10), 130);
    b5.setDamping(0.1f);
    b5.setPosition(0, 350);
    world.add(b5);
    chain(b1, b2, new Vector2f(), new Vector2f(0, -5), 14, world, 0.3f);
    chain(b5, b3, new Vector2f(10, 0), new Vector2f(-5, 0), 20, world, 0f);


    final Body b6 = new Body(new Circle(5), Body.INFINITE_MASS);
    b6.setPosition(440, 50);
    world.add(b6);

    final Body b7 = new Body(new Circle(5), Body.INFINITE_MASS);
    b7.setPosition(440, 340);
    world.add(b7);

    chain(b6, b7, new Vector2f(), new Vector2f(), 15, world,
        (float) Math.PI / 2f);
   
    for (int i = 0; i < 30; i++) {
      final Body b = new Body(new Circle(10), 10);
      b.setPosition(110, -i * 30-50);
      world.add(b);
    }
    //world.setGravity(0, 100);
  }
View Full Code Here

  }
 
  @Override
  protected void added(Entity e) {
    Physics collidable = e.getComponent(Physics.class);
    Body body = collidable.getBody();
    body.setUserData(e);
    physicsWorld.add(body);
  }
View Full Code Here

    physicsWorld.remove(collidable.getBody());
  }

  @Override
  public void collisionOccured(CollisionEvent event) {
    Body bodyA = event.getBodyA();
    Body bodyB = event.getBodyB();

    Entity entityA = Entity.class.cast(bodyA.getUserData());
    Entity entityB = Entity.class.cast(bodyB.getUserData());

    ImmutableBag<String> groupsA = world.getManager(GroupManager.class).getGroups(entityA);
    ImmutableBag<String> groupsB = world.getManager(GroupManager.class).getGroups(entityB);
   
    if(groupsA.contains("crates") && groupsB.contains("bullets")) {
View Full Code Here

   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    world.setGravity(0,0);
   
    circle1 = new Body("Circle 1", new Circle(20.0f), 1);
    circle1.setPosition(150,100);
    circle1.setRestitution(1.0f);
    circle1.setFriction(0.0f);
    circle1.adjustVelocity(new Vector2f(100,0));
    world.add(circle1);
    circle2 = new Body("Circle 2", new Circle(20.0f), 1);
    circle2.setPosition(250,100);
    circle2.setRestitution(1.0f);
    circle2.setFriction(0.0f);
    world.add(circle2);
  }
View Full Code Here

   */
  protected void keyHit(char c) {
    super.keyHit(c);
   
    if (c == ' ') {
      Body body2 = new Body("Mover1", new Circle(20), 300.0f);
      body2.setPosition(-50, (float) (((Math.random() * 50) + 150)));
      world.add(body2);
      body2.adjustAngularVelocity(1);
      body2.adjustVelocity(new Vector2f(200,(float) (Math.random() * 200)));
    }
  }
 
View Full Code Here

   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    this.world = world;
   
    Body body1 = new StaticBody("Ground1", new Box(400.0f, 20.0f));
    body1.setPosition(250.0f, 400);
    body1.setFriction(1);
    world.add(body1);
   
    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

  /**
   * @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, 300);
    world.add(body1);
    body1 = new StaticBody("Ground1", new Box(20.0f, 400.0f));
    body1.setPosition(40.0f, 150);
    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);
    j = new FixedJoint(body3,body4);
View Full Code Here

  /**
   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body land = new StaticBody("Line1", new Line(100,50));
    land.setPosition(150,150);
    world.add(land);
    land = new StaticBody("Line2", new Line(150,-75));
    land.setPosition(250,300);
    world.add(land);
    land = new StaticBody("Line2", new Line(150,75));
    land.setPosition(100,350);
    world.add(land);
    land = new StaticBody("Line2", new Line(150,0));
    land.setPosition(300,450);
    world.add(land);
   
    box = new Body("Faller", new Box(50,50), 1);
    box.setPosition(200,50);
    world.add(box);
  }
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.