curve - Is there any way to draw curved lines or rectangles in Andengine? -
i have draw curved lines or rectangles in andengine. please tell me way if know.
ok, rectangle class draws rectangles, line class draws lines.
rectangle rect = new rectangle(float px, float py, float pwidth, float pheight, vertexbufferobjectmanager pvertexbufferobjectmanager)
you set position, width , height here. put vertex buffer object manager there too, , you're go.
bezier curves harder do, since there no curve class nor beziercurve. use linestrip class:
final vertexbufferobjectmanager vbom = engine.getvertexbufferobjectmanager(); final highperformancelinechainvertexbufferobject pleftcurblinechainvbom = new highperformancelinechainvertexbufferobject(vbom, trianglecount * 3, drawtype.dynamic, true, leftcurb.vertexbufferobjectattributes_default); linestrip leftcurb = new linestrip(0, 0, 2f, 300, pleftcurblinechainvbom){ @override protected void onmanagedupdate(final float psecondselapsed) { super.onmanagedupdate(psecondselapsed); drawbybezier(curveoffset); }; void drawbybezier(float curveoffset){ (int triangleindex = 0; triangleindex < 300; triangleindex++) { this.setx(triangleindex, getbezier(triangleindex, curvexp1, curvexcontrol, curvexp2)); this.sety(triangleindex, getbezier(triangleindex, curveyp1, curveycontrol, curveyp2)); } }
you calculate curve this:
public float getbezier(float triangleindex, float p1x, float pcx, float p2x){ float t = triangleindex / 300; float tt = t * t; float u = 1 - t; float uu = u * u; float bezier = (uu * p1x) + (2 * u * t * pcx) + (tt * p2x); return bezier; }
of course not have in onmanagedupdate - code, since modify curve there. number 300 parameter linestrip , in getbezier method doesnt have 300, may lower or higher, must same in both places. if want have bezier curve (100, 100) (400, 300) control point @ (200, 350) like:
this.setx(triangleindex, getbezier(triangleindex, 100, 200, 400)); this.sety(triangleindex, getbezier(triangleindex, 100, 350, 300));
hope works too.
Comments
Post a Comment