Package net.phys2d.math

Examples of net.phys2d.math.Vector2f


    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);
    world.add(angle);
   
    DistanceJoint dist = new DistanceJoint(socket,wheel,new Vector2f(),new Vector2f(65,0),165);
    world.add(dist);
  }
View Full Code Here


   */
  public void keyHit(char c) {
    super.keyHit(c);
   
    if (c == ' ') {
      b2.addForce(new Vector2f(-100000,0));
    }
  }
View Full Code Here

      world.add(ball);
      bodies[i]=ball;
    }
   
    for(int i=1;i<N;i++){
      SlideJoint sj = new SlideJoint(bodies[i-1],bodies[i],new Vector2f(),new Vector2f(),40,80,1f);
      world.add(sj);
    }
    SlideJoint sj = new SlideJoint(knot,bodies[0],new Vector2f(),new Vector2f(),10,80,1f);
    world.add(sj);
  }
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

   */
  protected void drawBoxBody(Graphics2D g, Body body, boolean fill) {
    Box box = (Box) body.getShape();
    Vector2f[] pts = box.getPoints(body.getPosition(),body.getRotation());
   
    Vector2f v1 = pts[0];
    Vector2f v2 = pts[1];
    Vector2f v3 = pts[2];
    Vector2f v4 = pts[3];
   
    Polygon pol = new Polygon();
    pol.addPoint((int) v1.x,(int) v1.y);
    pol.addPoint((int) v2.x,(int) v2.y);
    pol.addPoint((int) v3.x,(int) v3.y);
View Full Code Here

   * @param box The shape to be drawn
   */
  protected void drawBoxBody(Graphics2D g, Body body, Box box) {
    Vector2f[] pts = box.getPoints(body.getPosition(), body.getRotation());
   
    Vector2f v1 = pts[0];
    Vector2f v2 = pts[1];
    Vector2f v3 = pts[2];
    Vector2f v4 = pts[3];
   
    g.setColor(Color.black);
    g.drawLine((int) v1.x,(int) v1.y,(int) v2.x,(int) v2.y);
    g.drawLine((int) v2.x,(int) v2.y,(int) v3.x,(int) v3.y);
    g.drawLine((int) v3.x,(int) v3.y,(int) v4.x,(int) v4.y);
View Full Code Here

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

   */
  public void keyHit(char c) {
    super.keyHit(c);
   
    if (c == ' ') {
      b2.addForce(new Vector2f(-100000,0));
    }
  }
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

TOP

Related Classes of net.phys2d.math.Vector2f

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.