Package processing.core

Examples of processing.core.PVector


   * @param start
   * @param end
   * @param preStart - the extra point used to correctly orient axis
   */
  private void addAxis(PVector start, PVector end, PVector preStart) {
    PVector axis = PVector.sub(start, end);
    axis.normalize();
    axis = HermesMath.rotate(axis,Math.PI/2);
    float project1 = axis.dot(start);
    float projectpre = axis.dot(preStart);
    assert project1 != projectpre : "HPolygon must be convex!";
    if(project1 < projectpre) {
      reverse(axis);
    }
    _axes.add(axis);
View Full Code Here


   * @return Copy of list of vertex points.
   */
  public ArrayList<PVector> getPointsCopy() {
    ArrayList<PVector> copy = new ArrayList<PVector>();
    for(PVector p : _points) {
      copy.add(new PVector(p.x, p.y));
    }
    return copy;
  }
View Full Code Here

   */
  public void addPoint(PVector point) {
    //Remove the axis for the edge between the current first and last points
    _axes.remove(_axes.size());
   
    PVector first = _points.get(0);
    PVector last = _points.get(_points.size()-1);
   
    addAxis(first, point, last);
    addAxis(point, last, first);
    _points.add(point);
  }
View Full Code Here

   * @return Copy of axes list.
   */
  public ArrayList<PVector> getAxesCopy() {
    ArrayList<PVector> copy = new ArrayList<PVector>();
    for(PVector p : _axes) {
      copy.add(new PVector(p.x, p.y));
    }
    return copy;
  }
View Full Code Here

   * @param theta    Angle to rotate by
   */
  public void rotate(PVector pivotLoc, double theta) {
    for(PVector p : _points) {
      //translate points into coordinates where given position is now (0,0)
      PVector translatedP = PVector.sub(p, pivotLoc);
      HermesMath.rotate(translatedP, theta);
      //translate back
      p.add(pivotLoc);
    }
    for(PVector p : _axes) {
View Full Code Here

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

    }
   
    return resolution;*/
   
    //Turn HRectangle into a HPolygon
    PVector otherPos = other.getPosition();
    PVector min = other.getMin();
    PVector max = other.getMax();
    PVector v2 = new PVector(min.x, max.y);
    PVector v4 = new PVector(max.x, min.y);
    ArrayList<PVector> points = new ArrayList<PVector>();
    points.add(min);
    points.add(v2);
    points.add(max);
    points.add(v4)
View Full Code Here

  }
 
  @Override
  public PVector projectionVector(HCircle other) {
    //Get distance between shapes
    PVector dist = PVector.sub(_position, other.getPosition());
    //Set up variables for keeping track of smallest resolution
        PVector resolution = null;
        float resolutionSize = Float.MAX_VALUE;
   
    PVector center = other.getCenter();
    float radius = other.getRadius();
   
    //Check for collision along all axes in this polygon
    for(PVector axis : _axes) {
      PVector result = checkSepAxis(axis, dist, center, radius);
      if(result == null) {
          return null;
      } else { //Determine if result is smaller than current min resolution
          float temp = mag2(result);
          if(temp < resolutionSize) {
                resolution = result;
                resolutionSize = temp;
                }
      }
    }
   
    //Check for collisions along axes between circle center and vertices
    for(PVector p : _points) {
      PVector axis = PVector.sub(center, PVector.add(p, dist));
      axis.normalize();
      PVector result = checkSepAxis(axis, dist, center, radius);
      if(result == null) {
          return null;
      } else { //Determine if result is smaller than current min resolution
          float temp = mag2(result);
          if(temp < resolutionSize) {
View Full Code Here

  }
 
  @Override
  public PVector projectionVector(HPolygon other) {
    //Get distance between polygons
    PVector dist = PVector.sub(_position, other.getPosition());
    //Set up variables for keeping track of smallest resolution
        PVector resolution = null;
        float resolutionSize = Float.MAX_VALUE;
   
    //Check for collision along all axes in this polygon
    for(PVector axis : _axes) {
      PVector result = checkSepAxis(axis, dist, other);
      if(result == null) {
          return null;
      } else { //Determine if result is smaller than current min resolution
          float temp = mag2(result);
          if(temp < resolutionSize) {
                resolution = result;
                resolutionSize = temp;
                }
      }
    }
   
    //Check for collision along all axes in other polygon
    ArrayList<PVector> axes = other.getAxes();
    for(PVector axis : axes) {
      PVector result = checkSepAxis(axis, dist, other);
      if(result == null) {
          return null;
      } else { //Determine if result is smaller than current min resolution
          float temp = mag2(result);
          if(temp < resolutionSize) {
View Full Code Here

   * @param center - center of circle
   * @param radius - radius of circle
   * @return
   */
  private PVector checkSepAxis(PVector axis, PVector dist, PVector center, float radius) {
    PVector project1 = getProjection(axis, this);
    PVector project2 = getProjection(axis, center, radius);
   
    //Offset projection of this away from other
    float offset = PVector.dot(dist,axis);
    project1.add(offset, offset, 0);
   
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.