Examples of Vec2


Examples of org.jbox2d.common.Vec2

    //   
    for (WorldObject wo : world.getObjects()) {
      for (Force force : wo.getForces()) {
        Vector2d dir = force.getDirection();
        Vector2d origin = force.getOrigin();
        Vec2 fvect = new Vec2((float) dir.getX(), (float) dir.getY());
        Vec2 point = new Vec2((float) origin.getX(), (float) origin.getY());
        fvect = wo.getBody().getWorldVector(fvect);
        point = wo.getBody().getWorldPoint(point);
        wo.getBody().applyForce(fvect, point);
      }
     
      Vector2d p = wo.getPosition();
      for (Environment env : world.getEnvironments()) {
        Vector2d g = env.getGravity(p);
        double fr = env.getFriction(p);    // TODO Should we get rid of this?
        g.scale(wo.getBody().getMass());
        Vec2 point = wo.getBody().getWorldCenter();
        wo.getBody().applyForce(new Vec2((float) g.getX(), (float) g.getY()), point);
      }
     
      // Time space
      wo.onGameTick();
      if(wo.isAlive() == false){
View Full Code Here

Examples of org.jbox2d.common.Vec2

    getBody().setMass(md);
    */
    if(input.isActive(InputAction.ROTATE_LEFT)){
      //this.setRotation(-0.8);
      //getBody().setAngularVelocity(-2.0f);
      getBody().applyImpulse(new Vec2(0,-1000), new Vec2(10,2));
      getBody().applyImpulse(new Vec2(0,1000), new Vec2(-5,4));
    }
    if(input.isActive(InputAction.ROTATE_RIGHT)){
      //this.setRotation(+0.8);
      //getBody().setAngularVelocity(2.0f);
      getBody().applyImpulse(new Vec2(0,1000), new Vec2(10,-2));
      getBody().applyImpulse(new Vec2(0,-1000), new Vec2(-5,-4));
    }
   
    return list;
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

    return objectType;
  }

  public Vector2d getPosition() {
    if (body != null) {
      Vec2 pos = body.getPosition();
      return new Vector2d(pos.x, pos.y);
    }
    return new Vector2d(position);
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

    return rotation;
  }

  public Vector2d getVelocity() {
    if (body != null) {
      Vec2 vel = body.getLinearVelocity();
      return new Vector2d(vel.x, vel.y);
    }
    return new Vector2d(velocity);
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

  }

  public void setPosition(Vector2d pos) {
    position = new Vector2d(pos);
    if (body != null) {
      body.setXForm(new Vec2((float) pos.getX(), (float) pos.getY()), body.getAngle());
    }
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

  }

  public void setVelocity(Vector2d v) {
    velocity = new Vector2d(v);
    if (body != null) {
      body.setLinearVelocity(new Vec2((float) v.getX(), (float) v.getY()));
    }
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

  @Override
  public void applyImpulse(Vector2d dir) {
    if (body == null) {
      throw new IllegalStateException("Must be added to world first");
    }
    Vec2 impulse = new Vec2((float) dir.getX(), (float) dir.getY());
    body.applyImpulse(impulse, body.getWorldCenter());
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

 
  @Override
  public BodyDef getBodyDef() {
    BodyDef def = new BodyDef();
    def.angle = (float) rotation;
    def.position = new Vec2((float) position.getX(), (float) position.getY());
    def.massData.mass = (float) mass;
    def.massData.I = (float) momentOfInertia;
    def.userData = this;
    return def;
  }
View Full Code Here

Examples of org.jbox2d.common.Vec2

      Polygon poly = (Polygon) shape;
      PolygonDef def = new PolygonDef();
      // TODO Set def.density for realistic mass;
      def.restitution = (float) elasticity;
      for (int i = 0; i < poly.npoints; i++) {
        def.vertices.add(new Vec2(poly.xpoints[i], poly.ypoints[i]));
      }
      return def;
    } else if (shape instanceof Ellipse2D) {
      Ellipse2D ell = (Ellipse2D) shape;
      CircleDef def = new CircleDef();
      def.localPosition = new Vec2((float) ell.getCenterX(), (float) ell.getCenterY());
      def.radius = (float) (ell.getWidth() / 2);
      def.restitution = (float) elasticity;
      return def;
    }
    throw new RuntimeException("Shape type not implemented: " + shape.getClass());
View Full Code Here

Examples of org.jbox2d.common.Vec2

    // JOINT TEST ENGINE AGAINST SHIP!
    //
    // TODO:
    //
    RevoluteJointDef jointDef = new RevoluteJointDef();   
    jointDef.initialize(playerShip.getBody(), mainEngine.getBody(), new Vec2((float)respawnPos.getX(), (float)respawnPos.getY()));
    jointDef.collideConnected = false;
    jointDef.enableMotor = false;
    jointDef.lowerAngle = 0.0f;
    jointDef.upperAngle = 0.0f;
    jointDef.enableLimit = true;
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.