Package processing.core

Examples of processing.core.PVector


  }

  @Override
  public PVector projectionVector(HShape other) {
    assert other != null : "Rectangle.projectionVector: other must be a valid rectangle";
    PVector opposite = other.projectionVector(this);
    return opposite == null ? null : reverse(opposite);
  }
View Full Code Here


    return opposite == null ? null : reverse(opposite);
  }

  @Override
  public PVector projectionVector(HCircle other) {
    PVector opposite = other.projectionVector(this);
    return opposite == null ? null : reverse(opposite);
  }
View Full Code Here

    return opposite == null ? null : reverse(opposite);
  }

  @Override
  public PVector projectionVector(HPolygon other) {
    PVector opposite = other.projectionVector(this);
    return opposite == null ? null : reverse(opposite);
  }
View Full Code Here

  @Override
  public PVector projectionVector(HRectangle other) {
    if(other == this// no self-projection
      return null;
    // calculate the distance between rect centers
    PVector center1 = getCenter();
    PVector center2 = other.getCenter();
    float xDist = center1.x - center2.x;
    float yDist = center1.y - center2.y;
    // the projection is distance minus combined side length
    float xProject = Math.abs(xDist) - (_max.x - _min.x + other._max.x - other._min.x)/2;
    float yProject = Math.abs(yDist) - (_max.y - _min.y + other._max.y - other._min.y)/2;
    // they collide if they overlap on both axes
    if( xProject > 0 || yProject > 0)
      return null;
    // the projection vector is the smallest projection, in direction opposite the distance vector
    return (xProject > yProject ?
        new PVector(xProject * sign(xDist), 0.0f) :
          new PVector(0.0f, yProject * sign(yDist)));
 
View Full Code Here

  public HCircle(PVector position, float radius) {
    super(position);
   
    assert radius >= 0 : "In HCircle constructor, radius must be positive"; //TODO can radius be 0?
   
    _center = new PVector(0,0);
    _radius = radius;
  }
View Full Code Here

  }
 
  @Override
  public PVector projectionVector(HShape other) {
    assert other != null : "HCircle.collide: other must be a validHShape";
    PVector opposite = other.projectionVector(this);
    return opposite == null ? null : reverse(opposite);
  }
View Full Code Here

    return opposite == null ? null : reverse(opposite);
  }

  @Override
  public PVector projectionVector(HPolygon other) {
    PVector opposite = other.projectionVector(this);
    return opposite == null ? null : reverse(opposite);
  }
View Full Code Here

  }
 
  @Override
  public PVector projectionVector(HCircle other) {
    //Get the center of this circle
    PVector worldCenterThis = PVector.add(_position, _center);
    //Get the center of the other circle
    PVector worldCenterOther = PVector.add(other.getPosition(), other.getCenter());
   
    //HCircles are colliding if distance between them is less than sum of radii
    PVector dir = PVector.sub(worldCenterOther, worldCenterThis);
    float distance = dir.mag();
    float sumRadii = _radius + other._radius;
    boolean collides = distance <= sumRadii;
   
    //Projection vector is the unit vector pointing from this circle to other scaled by overlap
    if(collides) {
      float magnitude = sumRadii - distance;
      dir.normalize();
      dir.mult(magnitude);
      return dir;
    }
    else return null;
  }
View Full Code Here

  }
 
  @Override
  public PVector projectionVector(HRectangle other) {
    //Get the center of this circle
    PVector worldCenter = PVector.add(_center, _position);
    //Figure out what voronoi region of the rectangle the circle is in
    PVector min = PVector.add(other._position, other.getMin());
    PVector max = PVector.add(other._position, other.getMax());
    if(min.x <= worldCenter.x) {
      if(worldCenter.x <= max.x) {
        //In regions above or below rectangle,
        //compare y projections
        float minProject = worldCenter.y - _radius;
        float maxProject = worldCenter.y + _radius;
        if(min.y <= maxProject && minProject <= max.y) {
          float topCollide = max.y - minProject;
          float bottomCollide = maxProject - min.y;
          return (topCollide >= bottomCollide ?
              new PVector(0,bottomCollide):
              new PVector(0,-topCollide));
         
        }
      }
      else if(min.y <= worldCenter.y) {
        if(worldCenter.y <= max.y) {
          //In region directly to right of rectangle
          //Compare x projections
          float minProject = worldCenter.x - _radius;
          if(minProject <= max.x) {
            return new PVector(minProject - max.x,0);
          }
        }
        else {
          //In region to the right&up of rectangle
          //Get projection of both along up-right vertex (max)
          return getOverlap(worldCenter,max);
        }
      }
      else {
        //In region to the right&down of rectangle
        //Get projection of both along bottom-right vertex
        PVector brVertex = new PVector(max.x, min.y);
        return getOverlap(worldCenter, brVertex);
      }
    }
    else if(min.y <= worldCenter.y) {
      if(worldCenter.y <= max.y) {
        //In region directly to the left of rectangle
        //Compare x projections
        float maxProject = worldCenter.x + _radius;
        if(min.x <= maxProject) {
          return new PVector(maxProject - min.x,0);
        }
      }
      else {
        //In region to the left&up of rectangle
        //Get projection of both along top-left vertex
        PVector tlVertex = new PVector(min.x, max.y);
        return getOverlap(worldCenter, tlVertex);
      }
    }
    else {
      //In region to the left&down of rectangle
View Full Code Here

   * @param vertex
   * @return projection vector when colliding, null when not
   */
  private PVector getOverlap(PVector worldCenter, PVector vertex) {
    //Get vector from circle to vertex and overlap of shapes
    PVector axis = PVector.sub(vertex, worldCenter);
    float overlap = _radius - axis.mag();
    if(overlap >= 0) {
      //Get projection vector
      axis.normalize();
      axis.mult(overlap);
      return axis;
    }
    else return null;
  }
View Full Code Here

TOP

Related Classes of processing.core.PVector

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.