GeometryBuffer: add simple Constructor

- add makeCircle util
- return this on clear()
This commit is contained in:
Hannes Janetzek 2014-09-30 02:55:43 +02:00
parent 9642c8c5aa
commit 0814a06d42

View File

@ -70,6 +70,20 @@ public class GeometryBuffer {
private PointF mTmpPoint = new PointF(); private PointF mTmpPoint = new PointF();
private int pointLimit; private int pointLimit;
public GeometryBuffer() {
this(32, 4);
}
/**
* Instantiates a new geometry buffer.
*
* @param numPoints the num of expected points
* @param numIndices the num of expected indices
*/
public GeometryBuffer(int numPoints, int numIndices) {
this(new float[numPoints * 2], new int[numIndices]);
}
/** /**
* Instantiates a new geometry buffer. * Instantiates a new geometry buffer.
* *
@ -122,24 +136,15 @@ public class GeometryBuffer {
return pointPos >> 1; return pointPos >> 1;
} }
/**
* Instantiates a new geometry buffer.
*
* @param numPoints the num points
* @param numIndices the num indices
*/
public GeometryBuffer(int numPoints, int numIndices) {
this(new float[numPoints * 2], new int[numIndices]);
}
/** /**
* Reset buffer. * Reset buffer.
*/ */
public void clear() { public GeometryBuffer clear() {
index[0] = 0; index[0] = 0;
indexPos = 0; indexPos = 0;
pointPos = 0; pointPos = 0;
type = GeometryType.NONE; type = GeometryType.NONE;
return this;
} }
/** /**
@ -423,4 +428,23 @@ public class GeometryBuffer {
return sb.toString(); return sb.toString();
} }
public static GeometryBuffer makeCircle(float x, float y,
float radius, int segments) {
GeometryBuffer g = new GeometryBuffer(segments, 1);
makeCircle(g, x, y, radius, segments);
return g;
}
public static GeometryBuffer makeCircle(GeometryBuffer g,
float x, float y, float radius, int segments) {
g.clear();
g.startPolygon();
for (int i = 0; i < segments; i++) {
double rad = Math.toRadians(i * (360f / segments));
g.addPoint((float) (x + Math.cos(rad) * radius),
(float) (y + Math.sin(rad) * radius));
}
return g;
}
} }