Package javax.vecmath

Examples of javax.vecmath.Vector2d


    // Compute actions
    for(int index1=0; index1<influenceList.size(); index1++) {
      MotionInfluence inf1 = influenceList.get(index1);
      AgentBody body1 = getAgentBodyFor(inf1.getEmitter());
      if (body1!=null) {
        Vector2d move;
        double rotation;
        if (inf1.getType()==DynamicType.STEEERING) {
          move = computeSteeringTranslation(body1, inf1.getLinearInfluence(), timeManager);
          rotation = computeSteeringRotation(body1, inf1.getAngularInfluence(), timeManager);
        }
        else {
          move = computeKinematicTranslation(body1, inf1.getLinearInfluence(), timeManager);
          rotation = computeKinematicRotation(body1, inf1.getAngularInfluence(), timeManager);
        }
       
        double x1 = body1.getX();
        double y1 = body1.getY();

        // Trivial collision detection
        for(int index2=index1+1; index2<influenceList.size(); index2++) {
          MotionInfluence inf2 = influenceList.get(index2);
          AgentBody body2 = getAgentBodyFor(inf2.getEmitter());
          if (body2!=null) {
            double x2 = body2.getX();
            double y2 = body2.getY();
                       
            double distance = new Vector2d(x2-x1,y2-y1).length();
           
            if (distance<(body1.getSize()+body2.getSize())) {
              move.set(0,0);
              break;
            }
          }
        }
       
View Full Code Here


   * @param v1
   * @param v2
   * @return the signed angle between v1 and v2
   */
  public static double signedAngle(Vector2d v1, Vector2d v2) {
    Vector2d a = new Vector2d(v1);
    if (a.length()==0) return Double.NaN;
    Vector2d b = new Vector2d(v2);
    if (b.length()==0) return Double.NaN;
    a.normalize();
    b.normalize();
   
    double cos = a.x * b.x + a.y * b.y;
    // A x B = |A|.|B|.sin(theta).N = sin(theta) (where N is the unit vector perpendicular to plane AB)
    double sin = a.x*b.y - a.y*b.x;
   
 
View Full Code Here

   * @param angle
   */
  public static void turnVector(Vector2d v, double angle) {
    double length = v.length();
    if (length==0.) return;
    double currentAngle = signedAngle(new Vector2d(1,0), v);
    currentAngle += angle;
    v.set(Math.cos(currentAngle),Math.sin(currentAngle));
    v.scale(length);
  }
View Full Code Here

   *
   * @param angle
   * @return the unit vector for which angle = acos(v.x) and angle = asin(v.y)
   */
  public static Vector2d toOrientationVector(double angle) {
    return new Vector2d(
        Math.cos(angle),
        Math.sin(angle));
  }
View Full Code Here

   *
   * @param orientation
   * @return the angle
   */
  public static double toOrientationAngle(Vector2d orientation) {
    return signedAngle(new Vector2d(1,0), orientation);
  }
View Full Code Here

  }

  @Override
  public Status live() {
    Point2d position = new Point2d(getX(), getY());
    Vector2d orientation = getDirection();
    double linearSpeed = getCurrentLinearSpeed();
    double angularSpeed = getCurrentAngularSpeed();
   
    BehaviourOutput output = null;
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

    // Compute actions
    for(int index1=0; index1<influenceList.size(); index1++) {
      MotionInfluence inf1 = influenceList.get(index1);
      AgentBody body1 = getAgentBodyFor(inf1.getEmitter());
      if (body1!=null) {
        Vector2d move;
        double rotation;
        if (inf1.getType()==DynamicType.STEEERING) {
          move = computeSteeringTranslation(body1, inf1.getLinearInfluence(), timeManager);
          rotation = computeSteeringRotation(body1, inf1.getAngularInfluence(), timeManager);
        }
        else {
          move = computeKinematicTranslation(body1, inf1.getLinearInfluence(), timeManager);
          rotation = computeKinematicRotation(body1, inf1.getAngularInfluence(), timeManager);
        }
       
        double x1 = body1.getX();
        double y1 = body1.getY();

        // Trivial collision detection
        for(int index2=index1+1; index2<influenceList.size(); index2++) {
          MotionInfluence inf2 = influenceList.get(index2);
          AgentBody body2 = getAgentBodyFor(inf2.getEmitter());
          if (body2!=null) {
            double x2 = body2.getX();
            double y2 = body2.getY();
                       
            double distance = new Vector2d(x2-x1,y2-y1).length();
           
            if (distance<(body1.getSize()+body2.getSize())) {
              move.set(0,0);
              break;
            }
           
          }
        }
       
        if(body1 instanceof LemmingBody)
        {

           
          LemmingBody body = (LemmingBody) body1;
          if(body.getIsActing())
          {
            if(body.getCurrentAction() == Action.DigVertically)
            {
              move.set(0,0);
            }
            else if(body.getCurrentAction() == Action.DigHorizontally)
            {
              move.set(1,0);
            }
          }
          actionApplier.doAction(body);
          actions.add(physicsEngine.Gravity(body, new AnimatAction(body, move, rotation)));
        }
View Full Code Here

   * {@inheritDoc}
   */
  public KinematicBehaviourOutput runSeek(Point2d position, double linearSpeed, double maxLinearSpeed, Point2d target) {
    KinematicBehaviourOutput output = new KinematicBehaviourOutput();
   
    Vector2d direction = new Vector2d();
    direction.sub(target,position);
   
    direction.normalize();   
    direction.scale(maxLinearSpeed);
   
    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

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.