Class CapsuleObstacle
A capsule typically is a pill-like shape that fits inside of given rectangle (e.g. it has half circles at the ends of the longest side). If width < height, the capsule will be oriented vertically with the rounded portions at the top and bottom. Otherwise it will be oriented horizontally.
This class allows for the creation of half-capsules, simply by using the
enumeration Capsule. The enumeration specifies which side should be
rounded in case of a half-capsule. Half-capsules are sized so that the
corresponding full capsule would fit in the bounding box.
Unless otherwise specified, the center of mass is the center of the capsule.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.badlogic.gdx.math.RectangleRectangle representation of capsule core for fast computationprotected com.badlogic.gdx.physics.box2d.CircleShapeShape information for the end capprotected com.badlogic.gdx.physics.box2d.CircleShapeShape information for the end capprotected com.badlogic.gdx.physics.box2d.PolygonShapeShape information for this boxFields inherited from class edu.cornell.gdiac.physics2.Obstacle
body, bodyinfo, centroidCache, DEFAULT_UNITS, fixture, massdata, masseffect, outline, positionCache, transform, units, velocityCache -
Constructor Summary
ConstructorsConstructorDescriptionCapsuleObstacle(float width, float height) Creates a new box at the origin.CapsuleObstacle(float x, float y, float width, float height) Creates a new capsule object.CapsuleObstacle(float x, float y, float width, float height, Capsule style) Creates a new capsule object width the given style. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreates new fixtures for this body, defining the shapecom.badlogic.gdx.math.Vector2Returns the dimensions of this capsulefloatReturns the capsule heightfloatReturns the seam offset of the core rectanglegetStyle()Returns the style of this capsulefloatReturns the outline tolerance of this obstacle.floatgetWidth()Returns the capsule widthprotected voidReleases the fixtures for this body, reseting the shapevoidsetDensity(float value) Sets the density of this bodyvoidsetDimension(float width, float height) Sets the dimensions of this capsulevoidsetDimension(com.badlogic.gdx.math.Vector2 value) Sets the dimensions of this capsulevoidsetHeight(float value) Sets the capsule heightvoidsetOrientation(Capsule value) Sets the style of this capsule.voidsetSeamOffset(float value) Sets the seam offset of the core rectanglevoidsetTolerance(float tolerance) Sets the outline tolerance of this obstacle.voidsetWidth(float value) Sets the capsule widthMethods inherited from class edu.cornell.gdiac.physics2.Obstacle
activatePhysics, deactivatePhysics, draw, draw, draw, draw, 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, setFilterData, setFixedRotation, setFriction, setGravityScale, setInertia, setLinearDamping, setLinearVelocity, setMass, setName, setPhysicsUnits, setPosition, setPosition, setRestitution, setSensor, setSleepingAllowed, setUserData, setVX, setVY, setX, setY, update
-
Field Details
-
shape
protected com.badlogic.gdx.physics.box2d.PolygonShape shapeShape information for this box -
end1
protected com.badlogic.gdx.physics.box2d.CircleShape end1Shape information for the end cap -
end2
protected com.badlogic.gdx.physics.box2d.CircleShape end2Shape information for the end cap -
center
protected com.badlogic.gdx.math.Rectangle centerRectangle representation of capsule core for fast computation
-
-
Constructor Details
-
CapsuleObstacle
public CapsuleObstacle(float width, float height) Creates a new box at the origin.The orientation of the capsule will be a full capsule along the major axis. If width == height, it will be a degenerate capsule (e.g a circle).
The size is expressed in physics units NOT pixels. In order for drawing to work properly, you MUST call
Obstacle.setPhysicsUnits(float).- Parameters:
width- The object width in physics unitsheight- The object width in physics units
-
CapsuleObstacle
public CapsuleObstacle(float x, float y, float width, float height) Creates a new capsule object.The orientation of the capsule will be a full capsule along the major axis. If width == height, it will be a degenerate capsule (e.g a circle).
The size is expressed in physics units NOT pixels. In order for drawing to work properly, you MUST call
Obstacle.setPhysicsUnits(float).- Parameters:
x- Initial x position of the box centery- Initial y position of the box centerwidth- The object width in physics unitsheight- The object width in physics units
-
CapsuleObstacle
Creates a new capsule object width the given style.The size is expressed in physics units NOT pixels. In order for drawing to work properly, you MUST call
Obstacle.setPhysicsUnits(float).- Parameters:
x- Initial x position of the box centery- Initial y position of the box centerwidth- The object width in physics unitsheight- The object width in physics unitsstyle- The capsule style
-
-
Method Details
-
getDimension
public com.badlogic.gdx.math.Vector2 getDimension()Returns the dimensions of this capsuleThis method does NOT return a reference to the dimension vector. Changes to this vector will not affect the shape. However, it returns the same vector each time its is called, and so cannot be used as an allocator.
- Returns:
- the dimensions of this capsule
-
setDimension
public void setDimension(com.badlogic.gdx.math.Vector2 value) Sets the dimensions of this capsuleThis method does not keep a reference to the parameter.
- Parameters:
value- the dimensions of this capsule
-
setDimension
public void setDimension(float width, float height) Sets the dimensions of this capsule- Parameters:
width- The width of this capsuleheight- The height of this capsule
-
getWidth
public float getWidth()Returns the capsule width- Returns:
- the capsule width
-
setWidth
public void setWidth(float value) Sets the capsule width- Parameters:
value- the capsule width
-
getHeight
public float getHeight()Returns the capsule height- Returns:
- the capsule height
-
setHeight
public void setHeight(float value) Sets the capsule height- Parameters:
value- the capsule height
-
getStyle
Returns the style of this capsule- Returns:
- the style of this capsule
-
setOrientation
Sets the style of this capsule.Note that style only controls whether the capsule is full, half, or half-reverse . The actual orientation is determined by the longest axis.
- Parameters:
value- the style of this capsule
-
getSeamOffset
public float getSeamOffset()Returns the seam offset of the core rectangleIf the center rectangle is exactly the same size as the circle radius, you may get catching at the seems. To prevent this, you should make the center rectangle epsilon narrower so that everything rolls off the round shape. This parameter is that epsilon value.
- Returns:
- the seam offset of the core rectangle
-
setSeamOffset
public void setSeamOffset(float value) Sets the seam offset of the core rectangleIf the center rectangle is exactly the same size as the circle radius, you may get catching at the seems. To prevent this, you should make the center rectangle epsilon narrower so that everything rolls off the round shape. This parameter is that epsilon value.
- Parameters:
value- the seam offset of the core rectangle
-
getTolerance
public float getTolerance()Returns the outline tolerance of this obstacle. In box2d, the ends of the capsule will be perfect circles. But we cannot draw perfect circles. As a result, the outline drawn in debug mode may not perfectly match the box2d fixtures. This value defines that drawing tolerance. Lower values mean the ends are more likely to be circular (default value is 0.05). This value only affects debugging. It has no affect on box2d.- Returns:
- the outline tolerance of this obstacle.
-
setTolerance
public void setTolerance(float tolerance) Sets the outline tolerance of this obstacle. In box2d, the ends of the capsule will be perfect circles. But we cannot draw perfect circles. As a result, the outline drawn in debug mode may not perfectly match the box2d fixtures. This value defines that drawing tolerance. Lower values mean the ends are more likely to be circular (default value is 0.05). This value only affects debugging. It has no affect on box2d.- Parameters:
tolerance- The outline tolerance of this obstacle.
-
setDensity
public void setDensity(float value) Sets the density of this bodyThe density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.
- Overrides:
setDensityin classObstacle- Parameters:
value- the density of this body
-
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:
createFixturesin 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:
releaseFixturesin classObstacle
-