Package net.sf.fysix.math

Examples of net.sf.fysix.math.Vector2d


 
  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


  public double getFriction(Vector2d pos) {
    return 0;
  }

  public Vector2d getGravity(Vector2d pos) {
    Vector2d dist = new Vector2d(centerPoint.getX(), centerPoint.getY());
    dist.sub(pos);
    if (dist.length() > 0 && dist.length() < 250) {
      dist.scale(100.0/dist.length());
      return dist;
    } else {
      return new Vector2d(0, 0);
    }   
  }
View Full Code Here

  private Vector2d origin;
  private Vector2d direction;
 
  public Force(Vector2d origin, Vector2d direction) {
    this.origin = new Vector2d(origin);
    this.direction = new Vector2d(direction);
  }
View Full Code Here

    this.origin = new Vector2d(origin);
    this.direction = new Vector2d(direction);
  }
 
  public Vector2d getOrigin() {
    return new Vector2d(origin);
  }
View Full Code Here

  public Vector2d getOrigin() {
    return new Vector2d(origin);
  }
 
  public void setOrigin(Vector2d origin) {
    this.origin = new Vector2d(origin);
  }
View Full Code Here

  public void setOrigin(Vector2d origin) {
    this.origin = new Vector2d(origin);
  }
 
  public Vector2d getDirection() {
    return new Vector2d(direction);
  }
View Full Code Here

  public Vector2d getDirection() {
    return new Vector2d(direction);
  }
 
  public void setDirection(Vector2d direction) {
    this.direction = new Vector2d(direction);
  }
View Full Code Here

    //
    // END - TEST CODE AREA FOR COLLISION...
    //   
    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

  private double throttle(double speedW, double strafeW, double rotateW) {
    double targetSpeed = getTargetSpeed();
    double targetStrafe = getTargetStrafe();
    double targetAV = getTargetAngularVelocity();
    Vector2d v = getVelocity();
    v.rotate(-getRotation());    // Make velocity relative to the ships orientation (x=forward, y=starboard)
    double speed = v.getX();
    double strafe = v.getY();
    double tots = v.length();
    double av = getAngularVelocity();
    if (Math.signum(speed * speedW) > 0) {  // Are we moving in the direction of this engines thrust?
      // The formula below makes speed closer to total speed instead of forward/backward speed in a smooth manner.
      // This limits the thrust that otherwise had been applied when moving almost sideways to the wanted direction of movement.
      // If this limitation is not applied the ship could accelerate so that the total speed exceeds the speed limit
View Full Code Here

  }
 
  public Collection<Force> getForces() {
    List<Force> list = new ArrayList<Force>();
   
    Vector2d force = new Vector2d(0.0, -20000.0);
    force.scale(getForeStarboardEngineThrottle());
    list.add(new Force(new Vector2d(13.0, 0.0), force));
   
    force = new Vector2d(0.0, 20000.0);
    force.scale(getForePortEngineThrottle());
    list.add(new Force(new Vector2d(13.0, 0.0), force));
   
    force = new Vector2d(-14000.0, -14000.0);
    force.scale(getAftStarboardEngineThrottle());
    list.add(new Force(new Vector2d(-7.0, 5.0), force));
   
    force = new Vector2d(-14000.0, 14000.0);
    force.scale(getAftPortEngineThrottle());
    list.add(new Force(new Vector2d(-7.0, -5.0), force));
   
    return list;
  }
View Full Code Here

TOP

Related Classes of net.sf.fysix.math.Vector2d

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.