Package net.phys2d.raw

Examples of net.phys2d.raw.Body


      g.drawLine((int) x1,(int) y1,(int) x2,(int) y2);
    }
    if(j instanceof SlideJoint){
      SlideJoint joint = (SlideJoint) j;
     
      Body b1 = joint.getBody1();
      Body b2 = joint.getBody2();
 
      Matrix2f R1 = new Matrix2f(b1.getRotation());
      Matrix2f R2 = new Matrix2f(b2.getRotation());
 
      ROVector2f x1 = b1.getPosition();
      Vector2f p1 = MathUtil.mul(R1,joint.getAnchor1());
      p1.add(x1);
 
      ROVector2f x2 = b2.getPosition();
      Vector2f p2 = MathUtil.mul(R2,joint.getAnchor2());
      p2.add(x2);
     
      Vector2f im = new Vector2f(p2);
      im.sub(p1);
      im.normalise();
     
     
     
      g.setColor(Color.red);
      g.drawLine((int)p1.x,(int)p1.y,(int)(p1.x+im.x*joint.getMinDistance()),(int)(p1.y+im.y*joint.getMinDistance()));
      g.setColor(Color.blue);
      g.drawLine((int)(p1.x+im.x*joint.getMinDistance()),(int)(p1.y+im.y*joint.getMinDistance()),(int)(p1.x+im.x*joint.getMaxDistance()),(int)(p1.y+im.y*joint.getMaxDistance()));
    }
    if(j instanceof AngleJoint){
      AngleJoint angleJoint = (AngleJoint)j;
      Body b1 = angleJoint.getBody1();
      Body b2 = angleJoint.getBody2();
      float RA = j.getBody1().getRotation() + angleJoint.getRotateA();
      float RB = j.getBody1().getRotation() + angleJoint.getRotateB();
     
      Vector2f VA = new Vector2f((float) Math.cos(RA), (float) Math.sin(RA));
      Vector2f VB = new Vector2f((float) Math.cos(RB), (float) Math.sin(RB));
     
      Matrix2f R1 = new Matrix2f(b1.getRotation());
      Matrix2f R2 = new Matrix2f(b2.getRotation());
     
      ROVector2f x1 = b1.getPosition();
      Vector2f p1 = MathUtil.mul(R1,angleJoint.getAnchor1());
      p1.add(x1);
 
      ROVector2f x2 = b2.getPosition();
      Vector2f p2 = MathUtil.mul(R2,angleJoint.getAnchor2());
      p2.add(x2);
     
      g.setColor(Color.red);
      g.drawLine((int)p1.x,(int)p1.y,(int)(p1.x+VA.x*20),(int)(p1.y+VA.y*20));
      g.drawLine((int)p1.x,(int)p1.y,(int)(p1.x+VB.x*20),(int)(p1.y+VB.y*20));
    }
    if (j instanceof BasicJoint) {
      BasicJoint joint = (BasicJoint) j;
     
      Body b1 = joint.getBody1();
      Body b2 = joint.getBody2();
 
      Matrix2f R1 = new Matrix2f(b1.getRotation());
      Matrix2f R2 = new Matrix2f(b2.getRotation());
 
      ROVector2f x1 = b1.getPosition();
      Vector2f p1 = MathUtil.mul(R1,joint.getLocalAnchor1());
      p1.add(x1);
 
      ROVector2f x2 = b2.getPosition();
      Vector2f p2 = MathUtil.mul(R2,joint.getLocalAnchor2());
      p2.add(x2);
 
      g.setColor(Color.red);
      g.drawLine((int) x1.getX(), (int) x1.getY(), (int) p1.x, (int) p1.y);
      g.drawLine((int) p1.x, (int) p1.y, (int) x2.getX(), (int) x2.getY());
      g.drawLine((int) x2.getX(), (int) x2.getY(), (int) p2.x, (int) p2.y);
      g.drawLine((int) p2.x, (int) p2.y, (int) x1.getX(), (int) x1.getY());
    }
    if(j instanceof DistanceJoint){
      DistanceJoint joint = (DistanceJoint) j;
     
      Body b1 = joint.getBody1();
      Body b2 = joint.getBody2();
 
      Matrix2f R1 = new Matrix2f(b1.getRotation());
      Matrix2f R2 = new Matrix2f(b2.getRotation());
 
      ROVector2f x1 = b1.getPosition();
      Vector2f p1 = MathUtil.mul(R1,joint.getAnchor1());
      p1.add(x1);
 
      ROVector2f x2 = b2.getPosition();
      Vector2f p2 = MathUtil.mul(R2,joint.getAnchor2());
      p2.add(x2);
     
      g.setColor(Color.red);
      g.drawLine((int) p1.getX(), (int) p1.getY(), (int) p2.x, (int) p2.y);
    }
    if (j instanceof SpringJoint) {
      SpringJoint joint = (SpringJoint) j;
     
      Body b1 = joint.getBody1();
      Body b2 = joint.getBody2();
 
      Matrix2f R1 = new Matrix2f(b1.getRotation());
      Matrix2f R2 = new Matrix2f(b2.getRotation());
 
      ROVector2f x1 = b1.getPosition();
      Vector2f p1 = MathUtil.mul(R1,joint.getLocalAnchor1());
      p1.add(x1);
 
      ROVector2f x2 = b2.getPosition();
      Vector2f p2 = MathUtil.mul(R2,joint.getLocalAnchor2());
      p2.add(x2);
     
      g.setColor(Color.red);
      g.drawLine((int) x1.getX(), (int) x1.getY(), (int) p1.x, (int) p1.y);
View Full Code Here


   */
  protected void draw(Graphics2D g) {
    BodyList bodies = world.getBodies();
   
    for (int i=0;i<bodies.size();i++) {
      Body body = bodies.get(i);
     
      drawBody(g, body);
    }
   
    JointList joints = world.getJoints();
View Full Code Here

   */
  protected void keyHit(char c) {
    super.keyHit(c);
   
    if (c == ' ') {
      Body body2 = new Body("Mover1", new Box(40.0f, 40.0f), 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<7;y++) {
      int xbase = 250 - (y * 21);
      for (int x=0;x<y+1;x++) {
        Body body2 = new Body("Mover1", new Box(40.0f, 40.0f), 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 land = new StaticBody("Line1", new Line(190,0));
    land.setPosition(50,400);
    world.add(land);
    Body land2 = new StaticBody("Box1", new Box(190,10));
    land2.setPosition(350,405);
    world.add(land2);
   
    Body box = new Body("Faller", new Box(50,50), 1);
    box.setPosition(150,100);
    box.setRotation(0.5f);
    world.add(box);
    Body box2 = new Body("Faller", new Box(50,50), 1);
    box2.setPosition(350,100);
    box2.setRotation(0.5f);
    world.add(box2);
  }
View Full Code Here

   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Vector2f[] groundVerts = {new Vector2f(-200, -10), new Vector2f(200,-10), new Vector2f(200,10), new Vector2f(-200,10)};
    ConvexPolygon groundBox = new ConvexPolygon(groundVerts);
    Body ground = new StaticBody("ground", groundBox);
    ground.setPosition(250, 50);
    world.add(ground);
   
    {
      int noVerts = 40;
      Vector2f[] circleVerts = new Vector2f[noVerts];
      float[] radius = {50,42,42,50};
      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, 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()));
      world.add(joint);
     
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, 400);
    world.add(body1);
    Body body1a = new StaticBody("Ground2", new Box(200.0f, 20.0f));
    body1a.setPosition(350.0f, 280);
    body1a.setRotation(-0.7f);
    world.add(body1a);
    Body body1b = new StaticBody("Ground1", new Box(20.0f, 400.0f));
    body1b.setPosition(20.0f, 200);
    world.add(body1b);
   
    Body body2 = new Body("Mover1", new Circle(25), 100.0f);
    body2.setPosition(300.0f, 4.0f);
    world.add(body2);
    //Body body3 = new Body("Mover2", new Box(25,25), 10.0f);
    Body body3 = new Body("Mover2", new Circle(25), 10.0f);
    body3.setRotation(0.3f);
    body3.setPosition(380.0f, 100.0f);
    world.add(body3);
  }
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(600.0f, 20.0f));
    body1.setPosition(250.0f, 400);
    world.add(body1);
    Body body3 = new StaticBody("Ground2", new Box(200.0f, 20.0f));
    body3.setPosition(360.0f, 340);
    body3.setRotation(0.4f);
    world.add(body3);
    Body body9 = new StaticBody("Ground3", new Box(200.0f, 20.0f));
    body9.setPosition(140.0f, 340);
    body9.setRotation(-0.4f);
    world.add(body9);
    Body bodya = new StaticBody("Wall1", new Box(20.0f, 400.0f));
    bodya.setPosition(20.0f, 190);
    world.add(bodya);
    Body bodyb = new StaticBody("Wall2", new Box(20.0f, 400.0f));
    bodyb.setPosition(480.0f, 190);
    world.add(bodyb);
   
    Body body2 = new Body("Mover1", new Box(50.0f, 50.0f), 100.0f);
    body2.setPosition(250.0f, 4.0f);
    body2.setRotation(0.2f);
    world.add(body2);
    Body body4 = new Body("Mover2", new Box(50.0f, 50.0f), 100.0f);
    body4.setPosition(230.0f, -60.0f);
    world.add(body4);
    Body body8 = new Body("Mover3", new Box(50.0f, 50.0f), 100.0f);
    body8.setPosition(280.0f, -120.0f);
    world.add(body8);
  }
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, 400);
    world.add(body1);
    Body body1b = new StaticBody("Ground1", new Box(20.0f, 400.0f));
    body1b.setPosition(20.0f, 200);
    world.add(body1b);

    Body body3 = new Body("Mover2", new Circle(25), 50.0f);
    body3.setPosition(225.0f, 365);
    world.add(body3);
    Body body2 = new Body("Mover1", new Circle(25), 50.0f);
    body2.setPosition(275.0f, 365);
    world.add(body2);
    Body body3a = new Body("Mover2", new Circle(25), 50.0f);
    body3a.setPosition(175.0f, 365);
    world.add(body3a);
    Body body2a = new Body("Mover1", new Circle(25), 50.0f);
    body2a.setPosition(325.0f, 365);
    world.add(body2a);
   
    Body faller = new Body("Faller", new Circle(25), 200.0f);
    faller.setPosition(250.0f, -20f);
    world.add(faller);
  }
View Full Code Here

 
  /**
   * @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(100,400);
    knot.setRotation(0.5f);
    world.add(knot);
    int N=8;
    Body balls[] = new Body[N];
    for(int i=0;i<N;i++){
      Body ball = new Body(new Circle(5),10);
      ball.setPosition(100,400-(i+1)*50);
      ball.setDamping(0.01f);
      world.add(ball);
      balls[i]=ball;
    }
   
    for(int i=0;i<N;i++){
      if(i==0){
        SpringyAngleJoint saj1 = new SpringyAngleJoint(knot,balls[i],new Vector2f(),new Vector2f(),1e6f,-(float)Math.PI/2.0f-0.15f);
        SpringyAngleJoint saj2 = new SpringyAngleJoint(balls[i],knot,new Vector2f(),new Vector2f(),1e6f,(float)Math.PI/2.0f);
        //DistantConstraint daj = new DistantConstraint(knot,balls[i],new Vector2f(),new Vector2f(),50);
        SpringJoint daj = new SpringJoint(knot,balls[i],new Vector2f(100,400),new Vector2f(balls[i].getPosition()));
        daj.setCompressedSpringConst(100);
        daj.setStretchedSpringConst(100);
        daj.setSpringSize(30);
        world.add(daj);
        world.add(saj1);
        world.add(saj2);
      }else{
        SpringyAngleJoint saj1 = new SpringyAngleJoint(balls[i-1],balls[i],new Vector2f(),new Vector2f(),1e6f,-(float)Math.PI/2.0f);
        SpringyAngleJoint saj2 = new SpringyAngleJoint(balls[i],balls[i-1],new Vector2f(),new Vector2f(),1e6f,(float)Math.PI/2.0f);
        //DistantConstraint daj = new DistantConstraint(balls[i-1],balls[i],new Vector2f(),new Vector2f(),50);
        SpringJoint daj = new SpringJoint(balls[i-1],balls[i],new Vector2f(balls[i-1].getPosition()),new Vector2f(balls[i].getPosition()));
        daj.setCompressedSpringConst(100);
        daj.setStretchedSpringConst(100);
        daj.setSpringSize(50);
        world.add(daj);
        world.add(saj1);
        world.add(saj2);
      }
    }
    Body balls1[] = new Body[N];
    for(int i=0;i<N;i++){
      Body ball = new Body(new Circle(5),10);
      ball.setPosition(100,400-(i+1)*50);
      ball.setDamping(0.01f);
      world.add(ball);
      balls1[i]=ball;
    }
    for(int i=0;i<N;i++){
      if(i==0){
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.