DonutBlobContainer.java :  » Game » JBox2D-2.0.1 » org » jbox2d » util » blob » Java Open Source

Java Open Source » Game » JBox2D 2.0.1 
JBox2D 2.0.1 » org » jbox2d » util » blob » DonutBlobContainer.java
package org.jbox2d.util.blob;

import org.jbox2d.collision.AABB;
import org.jbox2d.common.Vec2;

/**
 * A donut blob container specified by two radii and a center.
 */
public class DonutBlobContainer implements BlobContainer {
  private float centerX, centerY;
  private float radiusSmall, radiusLarge;
  private float radiusSmallSqr, radiusLargeSqr;
  
  public DonutBlobContainer(Vec2 _center, float _radiusSmall, float _radiusLarge) {
    centerX = _center.x;
    centerY = _center.y;
    radiusSmall = _radiusSmall;
    radiusLarge = _radiusLarge;
    radiusSmallSqr = _radiusSmall*_radiusSmall;
    radiusLargeSqr = _radiusLarge*_radiusLarge;
  }

  
  public boolean containsPoint(Vec2 p) {
    float distSqr = (p.x-centerX)*(p.x-centerX)+(p.y-centerY)*(p.y-centerY);
    if (distSqr > radiusLargeSqr) return false;
    if (distSqr < radiusSmallSqr) return false;
    return true;
  }

  public AABB getAABB() {
    Vec2 min = new Vec2(centerX-1.2f*radiusLarge,centerY-1.2f*radiusLarge);
    Vec2 max = new Vec2(centerX+1.2f*radiusLarge,centerY+1.2f*radiusLarge);
    return new AABB(min,max);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.