Class PolygonObstacle
The polygon will be triangulated, so that the fixtures are guaranteed to be convex. The polyon coordinates are all in local space, relative to the object center.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Poly2
The Poly2 representation of this obstacleprotected com.badlogic.gdx.physics.box2d.PolygonShape[]
Shape information for this physics objectFields inherited from class edu.cornell.gdiac.physics2.Obstacle
body, bodyinfo, centroidCache, DEFAULT_UNITS, fixture, massdata, masseffect, outline, positionCache, transform, units, velocityCache
-
Constructor Summary
ConstructorsConstructorDescriptionPolygonObstacle
(float[] points) Creates a (not necessarily convex) polygon at the origin.PolygonObstacle
(float[] points, float x, float y) Creates a (not necessarily convex) polygonPolygonObstacle
(com.badlogic.gdx.utils.FloatArray points) Creates a (not necessarily convex) polygon at the origin.PolygonObstacle
(com.badlogic.gdx.utils.FloatArray points, float x, float y) Creates a (not necessarily convex) polygonPolygonObstacle
(Poly2 poly) Creates a (not necessarily convex) polygon at the origin.PolygonObstacle
(Poly2 poly, float x, float y) Creates a (not necessarily convex) polygon -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Creates new fixtures for this body, defining the shapevoid
draw
(SpriteBatch batch) Draws a wireframe of this physics object.void
draw
(SpriteBatch batch, com.badlogic.gdx.graphics.Color color) Draws a wireframe of this physics object.void
draw
(SpriteBatch batch, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Affine2 affine) Draws a wireframe of this physics object.void
draw
(SpriteBatch batch, com.badlogic.gdx.math.Affine2 affine) Draws a wireframe of this physics object.com.badlogic.gdx.math.Rectangle
Returns the bounds of this polygoncom.badlogic.gdx.math.Rectangle
getBounds
(com.badlogic.gdx.math.Rectangle rect) Sets the given rectangle to the bounds of this polygonprotected void
Releases the fixtures for this body, reseting the shapevoid
setPoints
(float[] points) Sets this polygon obstacle to contain the given points.void
setPoints
(float[] points, int offset, int length) Sets this polygon obstacle to contain the given points.void
setPoints
(com.badlogic.gdx.utils.FloatArray points) Sets this polygon obstacle to contain the given points.void
setPolygon
(Poly2 poly) Sets this obstacle to be the given polygon.Methods inherited from class edu.cornell.gdiac.physics2.Obstacle
activatePhysics, deactivatePhysics, getAngle, getAngularDamping, getAngularVelocity, getBody, getBodyType, getCentroid, getDensity, getFilterData, getFriction, getGravityScale, getInertia, getLinearDamping, getLinearVelocity, getMass, getName, getOutline, getPhysicsUnits, getPosition, getRestitution, getUserData, getVX, getVY, getX, getY, isActive, isAwake, isBullet, isDirty, isFixedRotation, isRemoved, isSensor, isSleepingAllowed, markDirty, markRemoved, resetMass, setActive, setAngle, setAngularDamping, setAngularVelocity, setAwake, setBodyState, setBodyType, setBullet, setCentroid, setDensity, setFilterData, setFixedRotation, setFriction, setGravityScale, setInertia, setLinearDamping, setLinearVelocity, setMass, setName, setPhysicsUnits, setPosition, setPosition, setRestitution, setSensor, setSleepingAllowed, setUserData, setVX, setVY, setX, setY, update
-
Field Details
-
shapes
protected com.badlogic.gdx.physics.box2d.PolygonShape[] shapesShape information for this physics object -
poly
The Poly2 representation of this obstacle
-
-
Constructor Details
-
PolygonObstacle
public PolygonObstacle(float[] points) Creates a (not necessarily convex) polygon at the origin.The points given are relative to the origin. They are measured in Box2d units.
- Parameters:
points
- The polygon vertices
-
PolygonObstacle
public PolygonObstacle(float[] points, float x, float y) Creates a (not necessarily convex) polygonThe points given are relative to the obstacle's origin. They are measured in Box2d units.
- Parameters:
points
- The polygon verticesx
- The x position of the polygon originy
- The y position of the polygon origin
-
PolygonObstacle
public PolygonObstacle(com.badlogic.gdx.utils.FloatArray points) Creates a (not necessarily convex) polygon at the origin.The points given are relative to the origin. They are measured in Box2d units.
- Parameters:
points
- The polygon vertices
-
PolygonObstacle
public PolygonObstacle(com.badlogic.gdx.utils.FloatArray points, float x, float y) Creates a (not necessarily convex) polygonThe points given are relative to the obstacle's origin. They are measured in Box2d units.
- Parameters:
points
- The polygon verticesx
- The x position of the polygon originy
- The y position of the polygon origin
-
PolygonObstacle
Creates a (not necessarily convex) polygon at the origin.The points in the Poly2 object are specified relative to the origin. They are measured in Box2d units.
- Parameters:
poly
- The polygon shape
-
PolygonObstacle
Creates a (not necessarily convex) polygonThe points in the Poly2 object are specified relative to the obstacle's origin. They are measured in Box2d units.
- Parameters:
poly
- The polygon shapex
- The x position of the polygon originy
- The y position of the polygon origin
-
-
Method Details
-
getBounds
public com.badlogic.gdx.math.Rectangle getBounds()Returns the bounds of this polygonThe bounds of a polygon is the axis-aligned bounding box containing all of the vertices. This value is not scaled by the physics units, so it is expressed in Box2d units.
- Returns:
- the bounds of this polygon
-
getBounds
public com.badlogic.gdx.math.Rectangle getBounds(com.badlogic.gdx.math.Rectangle rect) Sets the given rectangle to the bounds of this polygonThe bounds of a polygon is the axis-aligned bounding box containing all of the vertices. This value is not scaled by the physics units, so it is expressed in Box2d units.
- Parameters:
rect
- the rectangle to store the result- Returns:
- the rectangle storing the result
-
setPoints
public void setPoints(float[] points) Sets this polygon obstacle to contain the given points.This is an expensive method as it will retriangulate all of the fixtures. If you need to change the shape of an obstacle, we recommend that you create a
Poly2
object first and usesetPolygon(edu.cornell.gdiac.math.Poly2)
.The points given are relative to the polygon's origin. They are measured in Box2d units.
- Parameters:
points
- The points to triangulate
-
setPoints
public void setPoints(float[] points, int offset, int length) Sets this polygon obstacle to contain the given points.This is an expensive method as it will retriangulate all of the fixtures. If you need to change the shape of an obstacle, we recommend that you create a
Poly2
object first and usesetPolygon(edu.cornell.gdiac.math.Poly2)
.The points given are relative to the polygon's origin. They are measured in Box2d units.
- Parameters:
points
- The points to triangulateoffset
- The offset into the arraylength
- The length of the array
-
setPoints
public void setPoints(com.badlogic.gdx.utils.FloatArray points) Sets this polygon obstacle to contain the given points.This is an expensive method as it will retriangulate all of the fixtures. If you need to change the shape of an obstacle, we recommend that you create a
Poly2
object first and usesetPolygon(edu.cornell.gdiac.math.Poly2)
.The points given are relative to the obstacle origin. They are measured in Box2d units.
- Parameters:
points
- The points to triangulate
-
setPolygon
Sets this obstacle to be the given polygon.The polygon given are relative to the obstacle origin. They are measured in Box2d units. This method does not keep a reference to the provided Poly2 object.
- Parameters:
poly
- The polygon for this obstacle
-
createFixtures
protected void createFixtures()Creates new fixtures for this body, defining the shapeThis is the primary method to override for custom physics objects
- Specified by:
createFixtures
in classObstacle
-
releaseFixtures
protected void releaseFixtures()Releases the fixtures for this body, reseting the shapeThis is the primary method to override for custom physics objects
- Specified by:
releaseFixtures
in classObstacle
-
draw
Draws a wireframe of this physics object.The physics object will be drawn to the given sprite batch as a white wireframe, using the
Obstacle.getPhysicsUnits()
to properly scale the shape. -
draw
Draws a wireframe of this physics object.The physics object will be drawn to the given sprite batch as a wireframe of the given color, using the
Obstacle.getPhysicsUnits()
to properly scale the shape. -
draw
Draws a wireframe of this physics object.The physics object will be drawn to the given sprite batch as a white wireframe, using the
Obstacle.getPhysicsUnits()
to properly scale the shape. The affine transform will be applied to this scaled coordinate system. -
draw
public void draw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Affine2 affine) Draws a wireframe of this physics object.The physics object will be drawn to the given sprite batch as a wireframe of the given color, using the
Obstacle.getPhysicsUnits()
to properly scale the shape. The affine transform will be applied to this scaled coordinate system.
-