Package net.phys2d.raw

Examples of net.phys2d.raw.BasicJoint


      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);
     
      wheel = circle;
      circle.setRotDamping(10);
    }
View Full Code Here


   
    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

    Body box = new Body("Resting", new Box(30,30), 1);
    box.setPosition(250.0f, 200);
    box.setRotation(0.15f);
    world.add(box);
   
    BasicJoint j1 = new BasicJoint(body3, swing, new Vector2f(160,110));
    world.add(j1);
    BasicJoint j2 = new BasicJoint(body3, swing2, new Vector2f(340,110));
    world.add(j2);
    BasicJoint j3 = new BasicJoint(swing, swing3, new Vector2f(160,300));
    world.add(j3);
    BasicJoint j4 = new BasicJoint(swing2, swing3, new Vector2f(340,300));
    world.add(j4);
   
    swing.adjustVelocity(new Vector2f(-100,0));
  }
View Full Code Here

      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);
      g.drawLine((int) p1.x, (int) p1.y, (int) p2.getX(), (int) p2.getY());
View Full Code Here

 
      if (i == 0) {
        b2 = body;
      }
     
      BasicJoint j = new BasicJoint(b1, body, new Vector2f(170.0f + (i*20), 111.0f));
      world.add(j);
    }
  }
View Full Code Here

 
      if (i == 0) {
        b2 = body;
      }
     
      BasicJoint j = new BasicJoint(b1, body, new Vector2f(170.0f + (i*20), 111.0f));
      world.add(j);
    }
  }
View Full Code Here

   */
  protected void init(World world) {
    this.world = world;
   
    Body body;
    BasicJoint j;
   
    Body base= new StaticBody("Ground1",new Box(500.0f, 20.0f));
    base.setPosition(250.0f, 400);
    world.add(base);
   
    body = new StaticBody("Ground2",new Box(250.0f, 20.0f));
    body.setPosition(225.0f, 200);
    body.setFriction(3.0f);
    world.add(body);
   
    // pendulum
    body = new StaticBody("Pen1",new Box(20.0f, 20.0f));
    body.setPosition(70.0f, 100);
    world.add(body);
    ball = new Body("Ball",new Box(10.0f, 10.0f), 1000);
    ball.setPosition(70.0f, 170);
    world.add(ball);
   
    j = new BasicJoint(body,ball,new Vector2f(70,110));
    world.add(j);
   
    // dominos
    for (int i=0;i<8;i++) {
      body = new Body("Domino "+i, new Box(10.0f, 40.0f), 10-i);
      body.setPosition(120.0f+(i*30), 170);
      world.add(body);
    }
   
    // ramp
    body = new StaticBody("Ground2",new Box(200.0f, 10.0f));
    body.setPosition(345.0f, 270);
    body.setRotation(-0.6f);
    body.setFriction(0);
    world.add(body);
   
    // teeter
    body = new Body("Teete",new Box(250.0f, 5.0f), 10);
    body.setPosition(250.0f, 360);
    //body.setFriction(3.0f);
    world.add(body);
    j = new BasicJoint(body,base,new Vector2f(250,360));
    world.add(j);
   
    // turner
    body = new Body("Turner", new Box(40.0f, 40.0f), 0.1f);
    body.setPosition(390.0f, 330);
    body.setFriction(0f);
    world.add(body);
    j = new BasicJoint(base,body,new Vector2f(390,335));
    world.add(j);
    Body top = new Body("Top",new Box(40.0f, 5.0f), 0.01f);
    top.setPosition(390.0f, 307.5f);
    top.setFriction(0f);
    world.add(top);
    j = new BasicJoint(top,body,new Vector2f(410,310));
    world.add(j);
  }
View Full Code Here

    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));
      j2.setRelaxation(relax);
      world.add(j2);
      if (i == 4) {
        joint = j2;
      }
     
      body2 = body3;
    }

    BasicJoint j3 = new BasicJoint(body1,body2,new Vector2f(80+(i*45),300));
    j3.setRelaxation(relax);
    world.add(j3);
  }
 
View Full Code Here

TOP

Related Classes of net.phys2d.raw.BasicJoint

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.