|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.graphics.glutils.ShapeRenderer
public class ShapeRenderer
Renders points, lines, rectangles, filled rectangles and boxes.
This class works with OpenGL ES 1.x and 2.0. In its base configuration a 2D orthographic projection with the origin in the lower left corner is used. Units are given in screen pixels. To change the projection properties use thesetProjectionMatrix(Matrix4)
method. Usually the Camera.combined
matrix is set via this method. If the screen orientation or resolution changes, the projection matrix might have to be adapted
as well.
Shapes are rendered in batches to increase performance. The standard use-pattern looks as follows:
camera.update();
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.color(1, 1, 0, 1);
shapeRenderer.line(x, y, x2, y2);
shapeRenderer.rect(x, y, width, height);
shapeRenderer.circle(x, y, radius);
shapeRenderer.end();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.color(0, 1, 0, 1);
shapeRenderer.rect(x, y, width, height);
shapeRenderer.circle(x, y, radius);
shapeRenderer.end();
The class has a second matrix called the transformation matrix which is used to rotate, scale and translate shapes in a more
flexible manner. This mechanism works much like matrix operations in OpenGL ES 1.x. The following example shows how to rotate a
rectangle around its center using the z-axis as the rotation axis and placing it's center at (20, 12, 2):
shapeRenderer.begin(ShapeType.Line); shapeRenderer.identity(); shapeRenderer.translate(20, 12, 2); shapeRenderer.rotate(0, 0, 1, 90); shapeRenderer.rect(-width / 2, -height / 2, width, height); shapeRenderer.end();Matrix operations all use postmultiplication and work just like glTranslate, glScale and glRotate. The last transformation specified will be the first that is applied to a shape (rotate then translate in the above example). The projection and transformation matrices are a state of the ShapeRenderer, just like the color and will be applied to all shapes until they are changed.
Nested Class Summary | |
---|---|
static class |
ShapeRenderer.ShapeType
Shape types to be used with begin(ShapeType) . |
Constructor Summary | |
---|---|
ShapeRenderer()
|
|
ShapeRenderer(int maxVertices)
|
Method Summary | |
---|---|
void |
arc(float x,
float y,
float radius,
float start,
float angle)
Calls arc(float, float, float, float, float, int) by estimating the number of segments needed for a smooth arc. |
void |
arc(float x,
float y,
float radius,
float start,
float angle,
int segments)
|
void |
begin(ShapeRenderer.ShapeType type)
Starts a new batch of shapes. |
void |
box(float x,
float y,
float z,
float width,
float height,
float depth)
Draws a box. |
void |
circle(float x,
float y,
float radius)
Calls circle(float, float, float, int) by estimating the number of segments needed for a smooth circle. |
void |
circle(float x,
float y,
float radius,
int segments)
|
void |
cone(float x,
float y,
float z,
float radius,
float height)
Calls cone(float, float, float, float, float, int) by estimating the number of segments needed for a smooth
circular base. |
void |
cone(float x,
float y,
float z,
float radius,
float height,
int segments)
|
void |
curve(float x1,
float y1,
float cx1,
float cy1,
float cx2,
float cy2,
float x2,
float y2,
int segments)
|
void |
dispose()
|
void |
ellipse(float x,
float y,
float width,
float height)
Calls ellipse(float, float, float, float, int) by estimating the number of segments needed for a smooth ellipse. |
void |
ellipse(float x,
float y,
float width,
float height,
int segments)
|
void |
end()
Finishes the batch of shapes and ensures they get rendered. |
void |
flush()
|
Color |
getColor()
|
ShapeRenderer.ShapeType |
getCurrentType()
Returns the current ShapeRenderer.ShapeType used |
Matrix4 |
getProjectionMatrix()
|
ImmediateModeRenderer |
getRenderer()
|
Matrix4 |
getTransformMatrix()
|
void |
identity()
Sets the transformation matrix to identity. |
void |
line(float x,
float y,
float x2,
float y2)
Draws a line in the x/y plane. |
void |
line(float x,
float y,
float x2,
float y2,
Color c1,
Color c2)
Draws a line in the x/y plane. |
void |
line(float x,
float y,
float z,
float x2,
float y2,
float z2)
Draws a line. |
void |
line(float x,
float y,
float z,
float x2,
float y2,
float z2,
Color c1,
Color c2)
Draws a line. |
void |
line(Vector2 v0,
Vector2 v1)
Draws a line. |
void |
line(Vector3 v0,
Vector3 v1)
Draws a line. |
void |
point(float x,
float y,
float z)
Draws a point. |
void |
polygon(float[] vertices)
|
void |
polygon(float[] vertices,
int offset,
int count)
Draws a polygon in the x/y plane. |
void |
polyline(float[] vertices)
|
void |
polyline(float[] vertices,
int offset,
int count)
Draws a polyline in the x/y plane. |
void |
rect(float x,
float y,
float width,
float height)
Draws a rectangle in the x/y plane. |
void |
rect(float x,
float y,
float width,
float height,
Color col1,
Color col2,
Color col3,
Color col4)
Draws a rectangle in the x/y plane. |
void |
rect(float x,
float y,
float width,
float height,
float originX,
float originY,
float rotation)
Draws a rectangle in the x/y plane. |
void |
rect(float x,
float y,
float width,
float height,
float originX,
float originY,
float rotation,
Color col1,
Color col2,
Color col3,
Color col4)
Draws a rectangle in the x/y plane. |
void |
rotate(float axisX,
float axisY,
float axisZ,
float angle)
Multiplies the current transformation matrix by a rotation matrix. |
void |
scale(float scaleX,
float scaleY,
float scaleZ)
Multiplies the current transformation matrix by a scale matrix. |
void |
setColor(Color color)
Sets the Color to be used by shapes. |
void |
setColor(float r,
float g,
float b,
float a)
Sets the Color to be used by shapes. |
void |
setProjectionMatrix(Matrix4 matrix)
Sets the projection matrix to be used for rendering. |
void |
setTransformMatrix(Matrix4 matrix)
|
void |
translate(float x,
float y,
float z)
Multiplies the current transformation matrix by a translation matrix. |
void |
triangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draws a triangle in x/y plane. |
void |
triangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
Color col1,
Color col2,
Color col3)
Draws a triangle in x/y plane with coloured corners. |
void |
x(float x,
float y,
float radius)
Draws two crossed lines. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ShapeRenderer()
public ShapeRenderer(int maxVertices)
Method Detail |
---|
public void setColor(Color color)
Color
to be used by shapes.
public void setColor(float r, float g, float b, float a)
Color
to be used by shapes.
public Color getColor()
public void setProjectionMatrix(Matrix4 matrix)
Camera.combined
.
matrix
- public Matrix4 getProjectionMatrix()
public void setTransformMatrix(Matrix4 matrix)
public Matrix4 getTransformMatrix()
public void identity()
public void translate(float x, float y, float z)
public void rotate(float axisX, float axisY, float axisZ, float angle)
angle
- angle in degreespublic void scale(float scaleX, float scaleY, float scaleZ)
public void begin(ShapeRenderer.ShapeType type)
ShapeRenderer.ShapeType.Point
is specified, only call #point().
The call to this method must be paired with a call to end()
.
In case OpenGL ES 1.x is used, the projection and modelview matrix will be modified.
type
- the ShapeRenderer.ShapeType
.public void point(float x, float y, float z)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Point
.
x
- y
- z
- public final void line(float x, float y, float z, float x2, float y2, float z2)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
.
public final void line(Vector3 v0, Vector3 v1)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
. Lazy method that "just" calls the
"other" method and unpacks the Vector3 for you
public final void line(float x, float y, float x2, float y2)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
.
public final void line(Vector2 v0, Vector2 v1)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
. Lazy method that "just" calls the
"other" method and unpacks the Vector2 for you
public final void line(float x, float y, float x2, float y2, Color c1, Color c2)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
. The line is drawn
with 2 colors interpolated between start & end point.
c1
- Color at start of the linec2
- Color at end of the linepublic void line(float x, float y, float z, float x2, float y2, float z2, Color c1, Color c2)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Line
. The line is drawn with 2 colors
interpolated between start & end point.
c1
- Color at start of the linec2
- Color at end of the linepublic void curve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, int segments)
public void triangle(float x1, float y1, float x2, float y2, float x3, float y3)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
x1
- x of first pointy1
- y of first pointx2
- x of second pointy2
- y of second pointx3
- x of third pointy3
- y of third pointpublic void triangle(float x1, float y1, float x2, float y2, float x3, float y3, Color col1, Color col2, Color col3)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
x1
- x of first pointy1
- y of first pointx2
- x of second pointy2
- y of second pointx3
- x of third pointy3
- y of third pointcol1
- color of the point defined by x1 and y1col2
- color of the point defined by x2 and y2col3
- color of the point defined by x3 and y3public void rect(float x, float y, float width, float height)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
public void rect(float x, float y, float width, float height, Color col1, Color col2, Color col3, Color col4)
ShapeRenderer.ShapeType
passed to begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
col1
- The color at (x, y)col2
- The color at (x + width, y)col3
- The color at (x + width, y + height)col4
- The color at (x, y + height)public void rect(float x, float y, float width, float height, float originX, float originY, float rotation)
ShapeRenderer.ShapeType
passed to
begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
public void rect(float x, float y, float width, float height, float originX, float originY, float rotation, Color col1, Color col2, Color col3, Color col4)
ShapeRenderer.ShapeType
passed to
begin has to be ShapeRenderer.ShapeType.Filled
or ShapeRenderer.ShapeType.Line
.
col1
- The color at (x, y)col2
- The color at (x + width, y)col3
- The color at (x + width, y + height)col4
- The color at (x, y + height)public void box(float x, float y, float z, float width, float height, float depth)
ShapeRenderer.ShapeType
passed
to begin has to be ShapeRenderer.ShapeType.Line
.
public void x(float x, float y, float radius)
public void arc(float x, float y, float radius, float start, float angle)
arc(float, float, float, float, float, int)
by estimating the number of segments needed for a smooth arc.
public void arc(float x, float y, float radius, float start, float angle, int segments)
public void circle(float x, float y, float radius)
circle(float, float, float, int)
by estimating the number of segments needed for a smooth circle.
public void circle(float x, float y, float radius, int segments)
public void ellipse(float x, float y, float width, float height)
ellipse(float, float, float, float, int)
by estimating the number of segments needed for a smooth ellipse.
public void ellipse(float x, float y, float width, float height, int segments)
public void cone(float x, float y, float z, float radius, float height)
cone(float, float, float, float, float, int)
by estimating the number of segments needed for a smooth
circular base.
public void cone(float x, float y, float z, float radius, float height, int segments)
public void polygon(float[] vertices)
polygon(float[], int, int)
public void polygon(float[] vertices, int offset, int count)
ShapeRenderer.ShapeType
passed
to begin has to be ShapeRenderer.ShapeType.Line
.
vertices
- public void polyline(float[] vertices)
polyline(float[], int, int)
public void polyline(float[] vertices, int offset, int count)
ShapeRenderer.ShapeType
passed
to begin has to be ShapeRenderer.ShapeType.Line
.
vertices
- public void end()
public void flush()
public ShapeRenderer.ShapeType getCurrentType()
ShapeRenderer.ShapeType
used
public ImmediateModeRenderer getRenderer()
public void dispose()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |