// Bndry

class Boundary extends PhysicsObject {
  Boundary(float X,float Y, float w_, float h_, float Angle) {
    x = X;
    y = Y;
    w = w_;
    h = h_;
    angle = Angle;
    makeBody();
    updatePos();
  }
  void makeBody() {
    killBody();

    // Figure out the box2d coordinates
    float box2dW = box2d.scalarPixelsToWorld(w/2)/WS;
    float box2dH = box2d.scalarPixelsToWorld(h/2)/WS;
    Vec2 center = new Vec2(x/WS, y/WS);
    // Define the polygon
    PolygonDef sd = new PolygonDef();
    sd.setAsBox(box2dW, box2dH);
    sd.density = 0;    // No density means it won't move!
    sd.friction = 2f;
    
    //Filter! (No interacting with aesthetic particles!)
    //if (isDisabled) sd.filter.categoryBits = 0x0004;
    //else
    sd.filter.categoryBits = 0x0002;
    // Create the body
    BodyDef bd = new BodyDef();
    bd.userData = "boundary";//this;
    bd.position.set(box2d.coordPixelsToWorld(center));
    body = box2d.createBody(bd);
    body.createShape(sd);
  }
  
  void updatePos() {
    x = box2d.getBodyPixelCoord(body).x * WS;
    y = box2d.getBodyPixelCoord(body).y * WS;
  }

  void draw() {
    // Draw.
    pushMatrix();
    translate(x, y);
    rotate(-angle);
    drawBody();
    popMatrix();
  }
  void drawBody() {
    fill(0, 200);
    noStroke();
    rect(0,0, w,h);
  }
  
  
  void killBody() {
    if(body!=null) box2d.destroyBody(body);
  }
}

