An edge collider is a line segment. More...
#include <EdgeCollider.h>
Public Types | |
using | Ptr = std::unique_ptr< EdgeCollider > |
Unique collider pointer. 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 | |
EdgeCollider () | |
Default constructor. More... | |
EdgeCollider (EdgeCollider &&) noexcept | |
Move constructor. More... | |
EdgeCollider & | operator= (EdgeCollider &&) noexcept |
Move assignment operator. More... | |
EdgeCollider::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 | setOneSided (const Vector2f &v0, const Vector2f &v1, const Vector2f &v2, const Vector2f &v3) |
Create a one sided collision edge. More... | |
void | setTwoSided (const Vector2f &v1, const Vector2f &v2) |
Create a two sided collision edge. More... | |
std::pair< Vector2f, Vector2f > | getEdgeVertices () const |
Get the vertices that make up the edge. More... | |
Vector2f | getFirstVertex () const |
Get the first vertex of the edge collider. More... | |
Vector2f | getSecondVertex () const |
Get the second vertex of the edge collider. More... | |
std::pair< Vector2f, Vector2f > | getGhostVertices () const |
Get the ghost vertices. More... | |
bool | isOneSided () const |
Check if the edge is collidable on one side or two sides. More... | |
~EdgeCollider () 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 EdgeCollider::Ptr | create () |
Create a new edge 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... | |
An edge collider is a line segment.
Note that edge colliders can collide with circles and polygons but not with themselves because edge shapes have no volume
Definition at line 42 of file EdgeCollider.h.
|
inherited |
RigidBody collision callback.
Definition at line 122 of file Collider.h.
using ime::EdgeCollider::Ptr = std::unique_ptr<EdgeCollider> |
Unique collider pointer.
Definition at line 44 of file EdgeCollider.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::EdgeCollider::EdgeCollider | ( | ) |
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 |
EdgeCollider::Ptr ime::EdgeCollider::copy | ( | ) | const |
Create a copy of the collider.
|
static |
Create a new edge collider.
This function is just a helper function for creating a shared pointer to an edge 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.
Get the vertices that make up the edge.
Vector2f ime::EdgeCollider::getFirstVertex | ( | ) | const |
Get the first vertex of the edge collider.
|
inherited |
Get the coefficient of friction.
Get the ghost vertices.
If the collider is two sided then the ghost vertices are all 0.0f
|
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.
Vector2f ime::EdgeCollider::getSecondVertex | ( | ) | const |
Get the second vertex of the edge 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
bool ime::EdgeCollider::isOneSided | ( | ) | const |
Check if the edge is collidable on one side or two sides.
|
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
|
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
void ime::EdgeCollider::setOneSided | ( | const Vector2f & | v0, |
const Vector2f & | v1, | ||
const Vector2f & | v2, | ||
const Vector2f & | v3 | ||
) |
Create a one sided collision edge.
v0 | A ghost vertex adjacent to the first edge vertex |
v1 | The first edge vertex |
v2 | The second edge vertex |
v3 | A ghost vertex adjacent to the second edge vertex |
In many cases a game environment is constructed by connecting several edge shapes end-to-end. This can give rise to an unexpected artifact when a polygon slides along the chain of edges (ghost collisions). Ghost collisions occur when the polygon collides with an internal vertex generating an internal collision normal. This function provides a mechanism for eliminating ghost collisions by storing the adjacent ghost vertices (v0 and v3) and using them internally to prevent internal collisions that lead to ghost collision.
v1 and v2 are the edge vertices whilst v0 and v3 are the adjacent ghost vertices. The extra ghost vertices are used to provide smooth movement across junctions.
The edge normal points to the right looking from v1 to v2
|
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
Create a two sided collision edge.
v1 | The first edge vertex |
v2 | The second edge vertex |
This function is more suited for edge colliders that are not chained to other edge colliders. If edge colliders are chained, ghost collision may occur when a polygon collider such as the BoxCollider slides across the chain. To counteract this effect, use the setOneSided function to construct the collider. However, if you don't care about ghost collisions, then this function is the preferred function to create an edge collider
The edge normal points to the right looking from v1 to v2.
|
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 |