# Libgdx - How to rotate a single ShapeRenderer object

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.

    //LEFT
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.

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):

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


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();
polygon.setVertices(vertices);


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

polygon.rotate(degrees);


And draw it:

shapeRenderer.begin();
// more code
shapeRenderer.polygon(polygon.getTransformedVertices());
// more code
shapeRenderer.end();


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.

• 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? 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.