Examples of Vector2f


Examples of net.phys2d.math.Vector2f

      velocity += world.getDelta() * 0.005f;
      if(velocity > 1.25f) {
        velocity = 1.25f;
      }
     
      physics.getBody().adjustVelocity(new Vector2f(velocity*ax, velocity*ay));
    } else if(velocity > 0) {
      velocity = 0;
    }
   
    if(reverse) {
      float ax = (TrigLUT.cosDeg(physics.getRotation()) * world.getDelta());
      float ay = (TrigLUT.sinDeg(physics.getRotation()) * world.getDelta());
     
      velocity -= world.getDelta() * 0.0025f;
      if(velocity < -1) {
        velocity = -1;
      }
     
      physics.getBody().adjustVelocity(new Vector2f(velocity*ax, velocity*ay));
    } else if(velocity < 0) {
      velocity += world.getDelta() * 1f;
      if(velocity > 0) {
        velocity = 0;
      }
View Full Code Here

Examples of net.phys2d.math.Vector2f

    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

Examples of net.phys2d.math.Vector2f

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

Examples of net.phys2d.math.Vector2f

      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){
        SpringyAngleJoint saj1 = new SpringyAngleJoint(knot,balls1[i],new Vector2f(),new Vector2f(),1e6f,-(float)Math.PI/2.0f+0.45f);
        SpringyAngleJoint saj2 = new SpringyAngleJoint(balls1[i],knot,new Vector2f(),new Vector2f(),1e6f,(float)Math.PI/2.0f);
        DistanceJoint daj = new DistanceJoint(knot,balls1[i],new Vector2f(),new Vector2f(),50);

        world.add(daj);
        world.add(saj1);
        world.add(saj2);
      }else{
        SpringyAngleJoint saj1 = new SpringyAngleJoint(balls1[i-1],balls1[i],new Vector2f(),new Vector2f(),1e6f,-(float)Math.PI/2.0f);
        SpringyAngleJoint saj2 = new SpringyAngleJoint(balls1[i],balls1[i-1],new Vector2f(),new Vector2f(),1e6f,(float)Math.PI/2.0f);
        DistanceJoint daj = new DistanceJoint(balls1[i-1],balls1[i],new Vector2f(),new Vector2f(),50);

        world.add(daj);
        world.add(saj1);
        world.add(saj2);
      }
View Full Code Here

Examples of net.phys2d.math.Vector2f

   
    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

Examples of net.phys2d.math.Vector2f

  private void chain(Body body1, Body body2, Vector2f anchor1,
      Vector2f anchor2, int chains, World world, float initRot) {

    final int N = chains;

    final Vector2f p1 = new Vector2f(body1.getPosition());
    p1.add(MathUtil.mul(new Matrix2f(body1.getRotation()), anchor1));

    Vector2f p2 = null;
    if (body2 != null) {
      p2 = new Vector2f(body2.getPosition());
      p2.add(MathUtil.mul(new Matrix2f(body2.getRotation()), anchor2));
    } else {
      p2 = new Vector2f(p1);
      p2.add(new Vector2f(chains * 20, 0));
    }

    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++) {
      final DistanceJoint dj = new DistanceJoint(bodies[i - 1],
          bodies[i], new Vector2f(7, 0), new Vector2f(-7, 0), 6);
/*      Vector2f v1,v2;
      v1 = new Vector2f(bodies[i-1].getPosition());v1.x+=7;
      v2 = new Vector2f(bodies[i].getPosition());v2.x-=7;
      SpringJoint dj = new SpringJoint(bodies[i - 1],
          bodies[i], v1, v2);
      dj.setMinSpringSize(4);
      dj.setSpringSize(1);
      dj.setStretchedSpringConst(100);
      dj.setCompressedSpringConst(100);
      dj.setMaxSpringSize(6);*/
      world.add(dj);
    }
    {
      final DistanceJoint dj = new DistanceJoint(body1, bodies[0],
          anchor1, new Vector2f(-7, 0), 10);
      world.add(dj);
    }
    if (body2 != null) {
      final DistanceJoint dj = new DistanceJoint(body2, bodies[N - 1],
          anchor2, new Vector2f(7, 0), 10);
      world.add(dj);
    }
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

    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);
 
View Full Code Here

Examples of net.phys2d.math.Vector2f

  @Override
  public void initialize() {
    physicsMapper = world.getMapper(Physics.class);
    transformMapper = world.getMapper(Transform.class);

    physicsWorld = new World(new Vector2f(0, 0), 10, new QuadSpaceStrategy(8, 6));
    physicsWorld.enableRestingBodyDetection(1f, 1f, 1f);
    physicsWorld.addListener(this);
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

   
    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);
View Full Code Here

Examples of net.phys2d.math.Vector2f

    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
TOP
Copyright © 2018 www.massapi.com. 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.