Package math

Examples of math.Vector


   * calculate the afterwards direction and rotation.
   */
  public static void rotateObject(Matrix dir, Vector rot, double inertia,
      Vector momentum, double timeDelta) {
    // angular acceleration = M / J (like in F = m*a)
    Vector rotAt = momentum.clone().scale(
        (inertia < 0.0005f) ? 0 : (timeDelta / inertia));
    Vector deltaDir = rotAt.clone().scale(0.5f).add(rot).scale(timeDelta);
    dir.set(Matrix.mult(dir, Matrix.getRotationalMatrix(deltaDir)));
    rot.add(rotAt);
  }
View Full Code Here


    vel.add(Physics.getTranslationalForce(impulse, forceArm).scale(1 / m));
  }
 
  public static void applyRotationalImpulse(Vector rot, Matrix tensor, Vector impulse, Vector forceArm) {
    if (forceArm != null) {
      Vector rotImpulse = Physics.getRotationalMomentum(impulse, forceArm);
      double inertia = Physics.getMomentumOfInertia(tensor, rotImpulse);
      rot.add(rotImpulse.scale((inertia < 0.0005f) ? 0 : 1 / inertia));
    }     
  }
View Full Code Here

  /**
   * Calculates the rotational momentum induced by the given force. If the
   * force arm has length zero, no rotational momentum is induced.
   */
  public static Vector getRotationalMomentum(Vector totalForce, Vector forceArm) {
    return (forceArm.isZero()) ? new Vector(0, 0, 0)
      : Vector.cross(forceArm, totalForce);
  }
View Full Code Here

  public static double getSphereVolume(double r) {
    return SPHERE_VOLUME_FACTOR * r * r * r;
  }

  public static Vector getGForce(double m1, double m2, Vector pos1, Vector pos2) {
    Vector dir = pos1.clone().invert().add(pos2);
    double r = dir.getLength();
    return (r < 0.0005f) ? dir.reset()
      : dir.scale(G * m1 * m2 / (r * r * r));
  }
 
View Full Code Here

   * @param arm2 point of collision relative to the center of mass of object 2
   */
  public static void resolveCollision(double e, Vector n, double m1, double m2, Matrix tensor1,
      Matrix tensor2, Vector arm1, Vector arm2, Vector v1, Vector v2, Vector rot1, Vector rot2) {
    // see http://www.euclideanspace.com/physics/dynamics/collision/threed/index.htm
    Vector dRot1 = Vector.applyMatrix(tensor1.clone().invert(), Vector.cross(n, arm1));
    Vector dRot2 = Vector.applyMatrix(tensor2.clone().invert(), Vector.cross(n, arm2));
    double impulse = (e + 1) * Vector.getDistance(v1, v2) / (1 / m1 + 1 / m2 
        + Vector.cross(dRot1, arm1).dot(n) + Vector.cross(dRot2, arm2).dot(n));
    v1.add(n.clone().scale(- impulse / m1));
    v2.add(n.clone().scale(impulse / m2));
    rot1.add(dRot1.invert());
    rot2.add(dRot2.invert());
  }
View Full Code Here

    }
  }

  private void createSubSectors() {
    subSectors = new Sector[8];
    Vector subSize = size.clone().scale(0.5f);
    double dx = 0.5f * subSize.getX();
    double dy = 0.5f * subSize.getY();
    double dz = 0.5f * subSize.getZ();
    for (int i = 0; i < 8; i++) {
      Vector offset = new Vector(((i / 4) * 2 - 1) * dx,
          (((i % 4) / 2) * 2 - 1) * dy, ((i % 2) * 2 - 1) * dz);
      subSectors[i] = new Sector(this, offset.add(position), subSize);
    }
  }
View Full Code Here

  /* CONSTRUCTORS */
 
  public PhysicalObject(double mass) {
    this.mass = mass;
    tensor = Physics.DEFAULT_TENSOR;
    position = new Vector();
    direction = Matrix.getRotationalIdentity();
    velocity = new Vector();
    rotation = new Vector();
    translationalForce = new Vector();
    rotationalMomentum = new Vector();
  }
View Full Code Here

  Star sun;
  HashMap<Object, Object> solvedCollisions = new HashMap<Object, Object>(4);

  public void init() throws IOException {
    mercury = new Planet(2000, 5000);
    mercury.setPosition(new Vector(-20000, 0, -40000));
    //mercury.setRotation(new Vector(0, 0.02f, 0));
    Texture texMercury = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/mercury.jpg"));
    mercury.setTexture(texMercury);
   
    mercury2 = new Planet(2000, 5000);
    mercury2.setPosition(new Vector(0, -5000, -40000));
    //mercury2.setRotation(new Vector(0, 0.01f, 0));
    mercury2.setTexture(texMercury);
   
    earth = new Planet(3000, 5000);
    earth.setPosition(new Vector(10000, 0, -40000))
    //earth.setRotation(new Vector(0, -0.006f, 0));
    Texture texEarth = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/earth.jpg"))
    earth.setTexture(texEarth);
   
    sun = new Star(7000, 500);
    sun.setPosition(new Vector(-30000, 20000, -40000))
    //sun.setRotation(new Vector(0, -0.006f, 0));
    Texture texSun = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/sun.jpg"))
    sun.setTexture(texSun);

    universe = new Sector(null, new Vector(), new Vector(1e9f, 1e9f, 1e9f));
    universe.addObject(mercury);
    universe.addObject(mercury2);
    universe.addObject(earth);
    universe.addObject(sun);
   
    earth.applyImpulse(new Vector(0, 30e15f, 0), null);
    mercury.applyImpulse(new Vector(0, -30e15f, 0), null);
   
    earth.applyImpulse(new Vector(0, 1e20f, 0), new Vector(1, 0, 0));
   
    //earth.applyImpulse(new Vector(-1e16f, 0, 0), null);
    //mercury.applyImpulse(new Vector(3e16f, 0, 0), null);
  }
View Full Code Here

  public void applyTo(PhysicalObject target) {
    if (source == target || !(target instanceof RenderableObject)) {
      return;
    }
    // line is the vector between the centers, from source to target
    Vector line = position.clone().invert().add(target.getPosition());
    double radsum = source.getBoundingRadius()
        + ((RenderableObject) target).getBoundingRadius();
    if ((line.dot(line) < radsum * radsum)) {
      if (source.equals(solvedCollisions.get(target))) {
        return;
      }
      Vector impulseArm = line.clone().scale(source.getBoundingRadius() / radsum);
      source.collideWith(target, source.getPosition().clone().add(impulseArm),
          impulseArm.clone().normalize(), radsum - line.getLength());
      solvedCollisions.put(source, target);   
    }
  }
View Full Code Here

  public ConstrictedEvent(Vector position, Vector size) {
    super(position, size);
  }
 
  public ConstrictedEvent(Vector position, double size) {
    super(position, new Vector(size, size, size));
  }
View Full Code Here

TOP

Related Classes of math.Vector

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.