Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


   */
  public VolcanoWorld(int width,int height){
    super(new Point(0,0),width,height);
    this.background=MEngine.getAssetManager().getSpriteSheet("volcano_background.png");
    this.clouds=MEngine.getAssetManager().getSpriteSheet("clouds.png");
    world=new World(new Vec2(0,-10f),true);
    volcano=new Volcano(this,new Point(250,425));
   
  }
View Full Code Here


    }
    return world;
  }
 
  private World() {
    AABB bounds = new AABB(new Vec2(-10000, -10000), new Vec2(10000, 10000));
    Vec2 gravity = new Vec2(0, 0);
    jbox2dWorld = new org.jbox2d.dynamics.World(bounds, gravity, true);
  }
View Full Code Here

  public void addObject(WorldObject wo, boolean fastObject) {
    BodyDef def = wo.getBodyDef();
    Body body = jbox2dWorld.createDynamicBody(def);
    body.setBullet(fastObject);
    Vector2d vel = wo.getVelocity();
    body.setLinearVelocity(new Vec2((float) vel.getX(), (float) vel.getY()));
    for (ShapeDef sd : wo.getShapeDefs()) {
      body.createShape(sd);
    }
    // TODO Use body.setMassFromShapes() for more realism
    wo.setBody(body);
View Full Code Here

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

    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

    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

    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

  }

  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

  }

  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

  @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

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.