So, looked at a couple of questions similar to this, led me straight into dead ends. I have an object drawn out in ShapeRenderer, and I wish to rotate only that one object. I have tried shapeRenderer.rotate(x, y, 1, 1), however all of my ShapeRenderer objects rotate. Anyone know how one would go about rotating a single ShapeRenderer object that is defined by an array of vertices? I've posted how I have drawn my object below.

    shapex[0] = x - 59/2;
    shapey[0] = y + 53/2;

    shapex[1] = x - 18/2;
    shapey[1] = y + 30/2 ;

    shapex[2] = x - 6/2;
    shapey[2] = y + 53/2;

    shapex[3] = x - 16/2;
    shapey[3] = y -51/2;

    shapex[4] = x - 21/2;
    shapey[4] = y + 1/2;

EDIT: I have tried to use polygon, however I see no good tutorials showing how to use it.


2 Answers 2


As @drumbumLOLcatz says, there are a bunch of overloaded methods when you create your shapes, what you are looking are for those methods that involve a degreeparameter. Something like this:

public void rect(float x, float y, float originX, float originY, float width, 
                 float height, float scaleX, float scaleY, float degrees)

So everytime you call the shapeRenderer object, you must specify this parameters for each shape that you want to transform (in this case, rotate):

// more code
shapeRenderer.rect(x, y, oX, oY, w, h, sX, sY, degrees);
// more code

As you don't say if you are using complex shapes, I don't know if this will satisfy your question (since I don't know if you are drawing simple lines, quadrilaterals, circles, arcs, etc.). If you are using the Polygon class, this should be easier, since this class can manage the rotation individually.

To draw a polygon, first, you construct your shape with your vertices, something like this:

// this are the vertices for a simple quadrilateral
float[] vertices = new float[] {
    0,   0,
    100, 0,
    100, 100,
    0,   100
// Create the polygon
Polygon polygon = new Polygon();

Then, if you want, you could rotate this polygon:


And draw it:

// more code
// more code

But, take in count that this will only draw the outline, in order to fill your shape you must consider another option like the Mesh class, triangulating your complex shape.

  • 1
    \$\begingroup\$ Nice, this works perfectly how I needed it to. Yes, I'm using complex polygons, so I added a radian factor to it. My shapes can go beyond 132 individual points, where I spend at least 2 minutes per point, so that time adds up. Would making a new class that took in point inputs and converted them from polar to cartesian coordinates work best to save a lot of time? \$\endgroup\$ Jul 4, 2015 at 19:22

When you draw a shape, there is sometimes a degree parameter (at least when you draw a rect) http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html#rect-float-float-float-float-float-float-float-float-float-

EDIT: also, any libgdx Shape Class will have a rotate function. Maybe instead of keeping your shapes in arrays of x and y, make an array of Polygons.

Docs: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Polygon.html#rotate-float-

  • 2
    \$\begingroup\$ Please give more details in your answer. \$\endgroup\$
    – Vaillancourt
    Jun 22, 2015 at 21:41
  • \$\begingroup\$ Yea, looks like it's only for rectangles. I wanted my shape to point towards the mouse, so I added a MathUtils.cos(radians) and MathUtils.sin(radians) factor to shapex and shapey, however that didn't work. The shape seemed to rotate across the x and y axis instead of the z axis. \$\endgroup\$ Jun 22, 2015 at 21:48
  • \$\begingroup\$ Edited my answer to link to the rotate function. Hope this helps \$\endgroup\$ Jun 22, 2015 at 21:58
  • \$\begingroup\$ Thanks for the refs, now I just need to figure out how to use these. \$\endgroup\$ Jun 22, 2015 at 23:40
  • \$\begingroup\$ Nope, still have no clue how to do it. I don't know how to properly draw the polygon. \$\endgroup\$ Jun 23, 2015 at 3:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .