Package physics.collision.shape
Class PrimitiveShape
java.lang.Object
physics.collision.shape.PrimitiveShape
- Direct Known Subclasses:
Circle
,ConvexPolygon
,Line
,Point
,Quadrilateral
,Triangle
The
PrimitiveShape
is implicitly described by all its support vectors.
A support vector is a point on the convex hull of a shape, that is furthest in the direction of a specified vector v.
This class may contain information about explicit points on the edge too.- Since:
- 18.06.2021
- Author:
- Juyas
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.joml.Vector2f
The centroid of the shape - the absolute vector (position is already added to it)protected final org.joml.Vector2f[]
The coordinates of the shape - absolute coordinates (position is already added to it)protected Circle
The boundingSphere of this shape represented by aCircle
.protected final Face[]
All faces of the shapeprotected org.joml.Vector2f
The centroid of the shape - the relative vector to an imaginary origin near the shapeprotected final org.joml.Vector2f[]
The coordinates of the shape - relative to an imaginary origin near the shapeprotected final int
The amount of vertices of the shape -
Constructor Summary
ModifierConstructorDescriptionprotected
PrimitiveShape
(org.joml.Vector2f... relatives) Create a polygon of the given coordinates.protected
PrimitiveShape
(ShapeType type, org.joml.Vector2f... relatives) Create a shape. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjust()
Will be called bysetPosition(Vector2f)
after the new position was set.final Circle
A minimal sphere that contains the original shape.final org.joml.Vector2f
centroid()
The center point or weight point of the shape.final Face[]
faces()
final org.joml.Vector2f[]
protected final void
init()
Requires the relativeCentroid to be set.protected final void
Calculates a relative centroid and the boundingSphere for the shape.final org.joml.Vector2f
position()
final boolean
rotateShape
(float radianAngle, RotationType type, org.joml.Vector2f point) Rotate a shape around a specific point and a given radianAngle.final void
setPosition
(float x, float y) final void
setPosition
(org.joml.Vector2f position) Update the shapes position due to external changes, e.g.org.joml.Vector2f
supportPoint
(org.joml.Vector2f v) According to GJKSM this method is supposed to calculate the point of the shape, that is most in direction of v.final ShapeType
type()
A clean description for this shape.final int
vertices()
-
Field Details
-
relatives
protected final org.joml.Vector2f[] relativesThe coordinates of the shape - relative to an imaginary origin near the shape -
absolutes
protected final org.joml.Vector2f[] absolutesThe coordinates of the shape - absolute coordinates (position is already added to it)- See Also:
-
faces
All faces of the shape- See Also:
-
vertices
protected final int verticesThe amount of vertices of the shape- See Also:
-
relativeCentroid
protected org.joml.Vector2f relativeCentroidThe centroid of the shape - the relative vector to an imaginary origin near the shape -
absoluteCentroid
protected org.joml.Vector2f absoluteCentroidThe centroid of the shape - the absolute vector (position is already added to it)- See Also:
-
boundingSphere
The boundingSphere of this shape represented by aCircle
. This sphere is used as broadphase for collision detection, since circle intersection checks does cost way less- See Also:
-
-
Constructor Details
-
PrimitiveShape
protected PrimitiveShape(org.joml.Vector2f... relatives) Create a polygon of the given coordinates.- Parameters:
relatives
- all relative points on the shape
-
PrimitiveShape
Create a shape. Generally only used as super call from other shape classes.- Parameters:
type
- the type of the target shaperelatives
- the points defining this shape
-
-
Method Details
-
setPosition
public final void setPosition(org.joml.Vector2f position) Update the shapes position due to external changes, e.g. the related object has moved- Parameters:
position
- the new position of the related object
-
setPosition
public final void setPosition(float x, float y) - Parameters:
x
- the x coordy
- the y coord- See Also:
-
position
public final org.joml.Vector2f position() -
getAbsolutePoints
public final org.joml.Vector2f[] getAbsolutePoints() -
faces
-
vertices
public final int vertices() -
initSphere
protected final void initSphere()Calculates a relative centroid and the boundingSphere for the shape. In some special cases this might be done quicker in a different way. -
init
protected final void init()Requires the relativeCentroid to be set. Calculates all relative faces and relative diagonals for a defined shape -
adjust
public void adjust()Will be called bysetPosition(Vector2f)
after the new position was set. Used to recalculate the absolute coordinates. -
rotateShape
Rotate a shape around a specific point and a given radianAngle.- Parameters:
radianAngle
- the radian angle to rotate the shapetype
- the type of rotationpoint
- the optional point to rotate around; if type is notRotationType.AROUND_POINT
, the point can be null- Returns:
- true, if the rotation was successful
- See Also:
-
centroid
public final org.joml.Vector2f centroid()The center point or weight point of the shape.- Returns:
- centroid of the shape
- See Also:
-
boundingSphere
A minimal sphere that contains the original shape. The inner shape is supposed to be fixed inside the sphere and share the same centroid.- Returns:
- the minimal sphere containing this shape
-
supportPoint
public org.joml.Vector2f supportPoint(org.joml.Vector2f v) According to GJKSM this method is supposed to calculate the point of the shape, that is most in direction of v. The general rule is, the more primitive the shape is, the more efficient this method can be. This method may be described as max{v*x,x element of Shape} for any complex shape.- Parameters:
v
- the direction- Returns:
- the point of the shape that is most in the direction of v
-
type
A clean description for this shape.- Returns:
- the
ShapeType
matching thisPrimitiveShape
-