Skip to content

Commit

Permalink
adds drawRectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandoam committed Sep 9, 2012
1 parent dc288e6 commit 1706c63
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chesterGL/primitivesBlock.js
Expand Up @@ -206,6 +206,27 @@ chesterGL.PrimitiveBlock.prototype.drawPolygon = function (points, color, closeP
this.polygons.unshift([buffer, glbuffer, closePolygon, fillPolygon]);
};

/**
* draws a rectangle
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @param {Array=} color
* @param {boolean=} fill
*/
chesterGL.PrimitiveBlock.prototype.drawRectangle = function (x, y, width, height, color, fill) {
var hw = width / 2,
hh = height / 2;
var pts = [
[x - hw, y - hh, 0],
[x - hw, y + hh, 0],
[x + hw, y + hh, 0],
[x + hw, y - hh, 0]
];
this.drawPolygon(pts, color, true, fill);
};

/**
* recreates the point buffer
* @ignore
Expand Down Expand Up @@ -301,3 +322,4 @@ goog.exportSymbol('chesterGL.PrimitiveBlock', chesterGL.PrimitiveBlock);
goog.exportProperty(chesterGL.PrimitiveBlock.prototype, 'drawPoint', chesterGL.PrimitiveBlock.prototype.drawPoint);
goog.exportProperty(chesterGL.PrimitiveBlock.prototype, 'drawLine', chesterGL.PrimitiveBlock.prototype.drawLine);
goog.exportProperty(chesterGL.PrimitiveBlock.prototype, 'drawPolygon', chesterGL.PrimitiveBlock.prototype.drawPolygon);
goog.exportProperty(chesterGL.PrimitiveBlock.prototype, 'drawRectangle', chesterGL.PrimitiveBlock.prototype.drawRectangle);

0 comments on commit 1706c63

Please sign in to comment.