Solid convex polygon collider. More...
#include <PolygonCollider.h>
Public Types | |
using | Ptr = std::unique_ptr< PolygonCollider > |
Unique polygon collider. More... | |
enum class | Type { Circle , Box , Polygon , Edge } |
The type of the collider. More... | |
using | CollisionCallback = std::function< void(Collider *, Collider *)> |
RigidBody collision callback. More... | |
Public Member Functions | |
PolygonCollider () | |
Default constructor. More... | |
PolygonCollider (PolygonCollider &&) noexcept | |
Move constructor. More... | |
PolygonCollider & | operator= (PolygonCollider &&) noexcept |
Move assignment operator. More... | |
PolygonCollider::Ptr | copy () const |
Create a copy of the collider. More... | |
Collider::Ptr | clone () const override |
Create a copy of the collider. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
void | set (const std::vector< Vector2f > &vertices) |
Create a convex hull from the an array of local points. More... | |
~PolygonCollider () override | |
Destructor. More... | |
std::string | getClassType () const override |
Get the name of this class. More... | |
Type | getType () const |
Get the type of the collider. More... | |
void | setDensity (float density) |
Set the density of the collider. More... | |
float | getDensity () const |
Get the density of the collider. More... | |
void | setFriction (float friction) |
Set the coefficient of friction. More... | |
float | getFriction () const |
Get the coefficient of friction. More... | |
void | setRestitution (float restitution) |
Set the coefficient of restitution. More... | |
float | getRestitution () const |
Get the coefficient of restitution of the collider. More... | |
void | setRestitutionThreshold (float threshold) |
Set the restitution threshold of the collider. More... | |
float | getRestitutionThreshold () const |
Get the restitution velocity threshold of the collider. More... | |
void | setSensor (bool sensor) |
Set whether or not the collider acts as a sensor. More... | |
bool | isSensor () const |
Check whether or not the collider is a sensor. More... | |
void | setCollisionFilter (const CollisionFilterData &filterData) |
Set the collision filter data of the collider. More... | |
const CollisionFilterData & | getCollisionFilterData () const |
Get the collision filter data for the collider. More... | |
void | resetCollisionFilterData () |
Reset the collision filtering data to default. More... | |
void | setEnable (bool enable) |
Enable or disable the collider. More... | |
bool | isAttachedToBody () const |
Check if the collider is attached to a rigid body or not. More... | |
RigidBody * | getBody () |
Get the body the collider is attached to. More... | |
const RigidBody * | getBody () const |
bool | containsPoint (const Vector2f &point) const |
Check if the collider contains a point or not. More... | |
PropertyContainer & | getUserData () |
Get the user data extracted from the collider definition. More... | |
const PropertyContainer & | getUserData () const |
void | onContactBegin (const CollisionCallback &callback) |
Add an event listener to a collision start event. More... | |
void | onContactEnd (const CollisionCallback &callback) |
Add an event listener to a collision end event. More... | |
void | onContactStay (const CollisionCallback &callback) |
Add an event listener to a contact stay event. More... | |
void | emitContact (const std::string &event, Collider *other) |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the tag assigned to the object. More... | |
unsigned int | getObjectId () const |
Get the unique id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a specific property change event. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to any property change event. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeEventListener (int id) |
Remove an event listener. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | isSameObjectAs (const Object &other) const |
Check if another object is the same instance as this object. More... | |
Static Public Member Functions | |
static PolygonCollider::Ptr | create () |
Create a new polygon collider. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emitDestruction () |
Emit a destruction event. More... | |
Protected Attributes | |
EventEmitter | eventEmitter_ |
Event dispatcher. More... | |
Solid convex polygon collider.
A polygon is convex when all line segments connecting two points in t he interior do not cross any edge of the polygon. Polygons are solid and never hollow. A polygon must have 3 or more vertices
Definition at line 44 of file PolygonCollider.h.
|
inherited |
RigidBody collision callback.
Definition at line 122 of file Collider.h.
using ime::PolygonCollider::Ptr = std::unique_ptr<PolygonCollider> |
Unique polygon collider.
Definition at line 46 of file PolygonCollider.h.
|
stronginherited |
The type of the collider.
Enumerator | |
---|---|
Circle | Circle collider. |
Box | Box collider. |
Polygon | Polygon collider. |
Edge | Edge collider. |
Definition at line 127 of file Collider.h.
ime::PolygonCollider::PolygonCollider | ( | ) |
Default constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
|
overridevirtual |
Create a copy of the collider.
You should use this function if you don't care about the type of the collider, otherwise use the colliders copy function
Implements ime::Collider.
|
inherited |
Check if the collider contains a point or not.
point | The point to be checked in world coordinates |
PolygonCollider::Ptr ime::PolygonCollider::copy | ( | ) | const |
Create a copy of the collider.
|
static |
Create a new polygon collider.
This function is just a helper function for creating a shared pointer to a polygon collider. The class does not keep the pointer
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
protectedinherited |
Emit a destruction event.
|
inherited |
Get the body the collider is attached to.
|
overridevirtual |
|
overridevirtualinherited |
Get the name of this class.
Note that this function is only implemented by child classes of Object which also serve as a base class for other classes
Reimplemented from ime::Object.
|
inherited |
Get the collision filter data for the collider.
|
inherited |
Get the density of the collider.
|
inherited |
Get the coefficient of friction.
|
inherited |
Get the unique id of the object.
Note that each instance of ime::Object has a unique id
|
inherited |
Get the coefficient of restitution of the collider.
|
inherited |
Get the restitution velocity threshold of the collider.
|
inherited |
|
inherited |
Get the type of the collider.
|
inherited |
Get the user data extracted from the collider definition.
|
inherited |
Check if the collider is attached to a rigid body or not.
|
inherited |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
|
inherited |
Check if another object is the same instance as this object.
other | The object to compare against this object |
|
inherited |
Check whether or not the collider is a sensor.
|
inherited |
Add an event listener to a collision start event.
callback | The function to be executed when this collider starts overlapping with another collider |
Note that the callback is called when the colliders come into contact and not when they remain in contact. In other words it is called once per interaction. On invocation, the callback is passed this collider and the collider that it started overlapping with respectively. In addition, only one event listener may be registered to this event, subsequent event listeners overwrite the current one. Pass nullptr to remove the current event listener
|
inherited |
Add an event listener to a collision end event.
callback | The function to be executed when the event is fired |
The callback is called when this collider stops overlapping with another collider. The callback is passed this collider and the collider it stopped overlapping with respectively. Note that only only one event listener may be registered to this event, subsequent event listeners overwrite the current one. Pass nullptr to remove the current event listener
|
inherited |
Add an event listener to a contact stay event.
callback | The function to be executed when the event is fired |
The callback is called while this collider remains in contact with another collider. On invocation, the callback is passed this collider and the collider its currently overlapping with respectively.
Note that only one event listener may be registered to this event, subsequent event listeners overwrite the current one. Pass nullptr to remove the current event listener
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it
|
inherited |
Add an event listener to any property change event.
callback | The function to be executed when any property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to add an event listener to |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called
Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.
|
noexcept |
Move assignment operator.
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove an event listener from |
id | The unique id of the event listener to be removed |
|
inherited |
Remove an event listener.
id | The id of the event listener to be removed |
|
inherited |
Reset the collision filtering data to default.
By default, the collider does not belong to any collision group and the rigid body the collider is attached to will collide with any rigid body (that is also collidable) it comes into contact with
void ime::PolygonCollider::set | ( | const std::vector< Vector2f > & | vertices | ) |
Create a convex hull from the an array of local points.
vertices | The vertices to create the convex hull from |
The origin of the polygon is at the local coordinate (0, 0)
|
inherited |
Set the collision filter data of the collider.
filterData | The new collision filter data |
This function will not update contacts until the next time step when either parent body is active or awake
By default, the collider does not belong to any collision group and the rigid body the collider is attached to will collide with any rigid body (that is also collidable) it comes into contact with
|
inherited |
Set the density of the collider.
density | The density to set |
The colliders density is used to compute the mass properties of the rigid body. The density can be zero or positive. You should use similar densities for all of your colliders. This will improve stacking stability
By default, the density is 1.0f
|
inherited |
Enable or disable the collider.
enable | True to enable or false to disable |
This function will only modify the collision bitmask and leave the category bit and group index as is. When enable is set to false, the collision bitmask will be set to 0 causing the collider to not collide with any other collider and when enable is set to true, the collision bitmask will be set to the value it was before it was set to zero.
This function is a just a shortcut for:
By default, the collider is enabled
|
inherited |
Set the coefficient of friction.
friction | The coefficient to set |
Friction is used to make objects slide along each other realistically The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong
By default, the friction is 0.2f
|
inherited |
Set the coefficient of restitution.
restitution | The coefficient to set |
Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision
By default, the restitution is 0.0f
|
inherited |
Set the restitution threshold of the collider.
threshold | The new restitution threshold |
By default, the restitution threshold is 1.0f
|
inherited |
Set whether or not the collider acts as a sensor.
sensor | True to set as sensor, otherwise false |
A sensor detects a collision but does not generate a collision response. This is useful if you only want to know when two colliders overlap. You can flag any collider as being a sensor. Sensors may be attached to static, kinematic, or dynamic bodies. Remember that you may have multiple colliders per body and you can have any mix of sensors and non-sensor colliders. However, sensors only form contacts when at least one body is dynamic, therefore, you will not get a contact for kinematic versus kinematic, kinematic versus static, or static versus static
By default, the collider is not a sensor
|
inherited |
Assign the object an alias.
tag | The alias of the object |
This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag
By default, the tag is an empty string
|
inherited |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
|
protectedinherited |