Package javax.vecmath

Examples of javax.vecmath.Vector2d


   * {@inheritDoc}
   */
  public SteeringBehaviourOutput runSeek(Point2d position, double linearSpeed, double maxLinearAcc, Point2d target) {
    SteeringBehaviourOutput output = new SteeringBehaviourOutput();
   
    Vector2d direction = new Vector2d();
    direction.sub(target,position);
   
    direction.normalize();   
    direction.scale(maxLinearAcc);
   
    output.setLinear(direction.getX(), direction.getY());
   
    return output;
  }
View Full Code Here


   *
   * @param linearInfluence is the linear influence to apply on the object.
   * @param angularInfluence is the angular influence to apply on the object.
   */
  public void influenceKinematic(Vector2d linearInfluence, double angularInfluence) {
    Vector2d li;
    if (linearInfluence!=null) {
      li = new Vector2d(linearInfluence);
      double nSpeed = li.length();
      if (nSpeed>getMaxLinearSpeed()) {
        li.normalize();
        li.scale(getMaxLinearSpeed());
      }
    }
    else {
      li = new Vector2d();
    }
    double ai = GeometryUtil.clamp(angularInfluence, -getMaxAngularSpeed(), getMaxAngularSpeed());
    this.motionInfluence = new MotionInfluence(DynamicType.KINEMATIC, this, li, ai);
  }
View Full Code Here

   *
   * @param linearInfluence is the linear influence to apply on the object.
   * @param angularInfluence is the angular influence to apply on the object.
   */
  public void influenceSteering(Vector2d linearInfluence, double angularInfluence) {
    Vector2d li;
    if (linearInfluence!=null) {
      li = new Vector2d(linearInfluence);
      double nSpeed = li.length();
      if (nSpeed>getMaxLinearAcceleration()) {
        li.normalize();
        li.scale(getMaxLinearAcceleration());
      }
    }
    else {
      li = new Vector2d();
    }
    double ai = GeometryUtil.clamp(angularInfluence, -getMaxAngularAcceleration(), getMaxAngularAcceleration());
    this.motionInfluence = new MotionInfluence(DynamicType.STEEERING, this, li, ai);
  }
View Full Code Here

  }

  /** {@inheritDoc}
   */
  public Vector2d getCurrentLinearMotion() {
    return new Vector2d(this.linearMove);
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  Vector2d move(double dx, double dy, double simulationDuration, double worldWidth, double worldHeight) {
    Vector2d r = super.move(dx, dy, simulationDuration, worldWidth, worldHeight);
    if (simulationDuration>0) {
      this.linearMove.set(r.x, r.y);
      double distance = this.linearMove.length();
      if (distance>0) {
        this.linearMove.normalize();
View Full Code Here

    super.rotate(rotation, simulationDuration);
    this.currentAngularSpeed = rotation / simulationDuration;
  }

  private Vector2d scaleVector(Vector2d v, double length, SimulationTimeManager clock) {
    Vector2d v2 = new Vector2d(v);
    if (v2.length()>0) v2.normalize();
    v2.scale(clock.perSecond(length));
    return v2;
  }
View Full Code Here

   * @param move is the requested motion.
   * @param clock is the simulation time manager
   * @return the linear instant motion.
   */
  Vector2d computeSteeringTranslation(Vector2d move, SimulationTimeManager clock) {
    Vector2d m = new Vector2d();
    m.add(this.linearMove,move);
    double lSpeed = m.length();
    if (lSpeed<0) lSpeed = 0.;
    if (lSpeed>this.maxLinearSpeed) lSpeed = this.maxLinearSpeed;
   
    return scaleVector(m, lSpeed, clock);
  }
View Full Code Here

   *
   * @param dx
   * @param dy
   */
  protected void setDirection(double dx, double dy) {
    this.angle = GeometryUtil.toOrientationAngle(new Vector2d(dx, dy));
  }
View Full Code Here

   * @param worldWidth is the width of the world.
   * @param worldHeight is the height of the world.
   * @return the real motion.
   */
  Vector2d move(double dx, double dy, double simulationDuration, double worldWidth, double worldHeight) {
    Vector2d r = new Vector2d(dx, dy);
    double tx = this.position.x + dx;
    double ty = this.position.y + dy;

    double size = getSize();
   
    if (tx<size) {
      r.setX(size-this.position.x);
      tx = size;
    }
    else if (tx>(worldWidth-size)) {
      r.setX(worldWidth - size - this.position.x);
      tx = worldWidth - size;
    }
   
    if (ty<size) {
      r.setY(size-this.position.y);
      ty = size;
    }
    else if (ty>(worldHeight-size)) {
      r.setY(worldHeight - size - this.position.y);
      ty = worldHeight - size;
    }
   
    this.position.set(tx, ty);
   
View Full Code Here

     
      for(AgentBody b1 : getAgentBodies()) {
        if (b1!=agent) {
          double x2 = b1.getX();
          double y2 = b1.getY();
          double distance = new Vector2d(x2-x1,y2-y1).length();
          if (distance<bestDistance) {
            bestDistance = distance;
            nearestBody = b1;
          }
        }
View Full Code Here

TOP

Related Classes of javax.vecmath.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.