Package org.jbox2d.common

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


      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

    // 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

    return height;
  }

  @Override
  protected void applyOffset(float x, float y, float angle) {
    shape.setAsBox(width/2, height/2, new Vec2(x,y), angle);
  }
View Full Code Here

   */
  public float inertiaScale;
 
  public BodyDef() {
    userData = null;
    position = new Vec2();
    angle = 0f;
    linearVelocity = new Vec2();
    angularVelocity = 0f;
    linearDamping = 0f;
    angularDamping = 0f;
    allowSleep = true;
    awake = true;
View Full Code Here

   * @param x The x axis location of the body
   * @param y The y axis location of the body
   */
  public Body(Shape shape, float x, float y) {
    jboxBodyDef = new BodyDef();
    jboxBodyDef.position = new Vec2(x,y);
    this.shape = shape;
  }
View Full Code Here

   * @param x The amount of force on the X axis
   * @param y The amount of force on the Y axis
   */
  public void applyForce(float x, float y) {
    assertBodyAttached();
    jboxBody.applyForce(new Vec2(x,y), jboxBody.getWorldCenter());
  }
View Full Code Here

   * @param yAt The y-coordinate at which to apply the force
   * @param isLocalPoint if true, assume the *At params are local to the body.  otherwise, they're world coordinates.
   */
  public void applyForce(float xMagnitude, float yMagnitude, float xAt, float yAt, boolean isLocalPoint){
    assertBodyAttached();
    Vec2 position = new Vec2(xAt, yAt);
    if(isLocalPoint)
      position = jboxBody.getWorldPoint(position);
    jboxBody.applyForce(new Vec2(xMagnitude, yMagnitude), position);
  }
View Full Code Here

   * @param x The new x coordinate of the body
   * @param y The new y coordinate of the body
   */
  public void setPosition(float x, float y) {
    assertBodyAttached();
    jboxBody.setTransform(new Vec2(x,y), jboxBody.getAngle());
  }
View Full Code Here

   * @param xVelocity The x component of the velocity
   * @param yVelocity The y component of the velocity
   */
  public void setVelocity(float xVelocity, float yVelocity) {
    assertBodyAttached();
    Vec2 vel = jboxBody.getLinearVelocity();
    vel.x = xVelocity;
    vel.y = yVelocity;
    jboxBody.setLinearVelocity(vel);
  }
View Full Code Here

TOP

Related Classes of org.jbox2d.common.Vec2

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.