A box collider. More...
#include <BoxCollider.h>
Public Types | |
using | Ptr = std::shared_ptr< BoxCollider > |
shred collider pointer More... | |
using | ConstPtr = std::shared_ptr< const BoxCollider > |
Const shared collider pointer. More... | |
enum | Type { Type::Circle, Type::Box, Type::Polygon, Type::Edge } |
The type of the collider. More... | |
using | BodyPtr = std::shared_ptr< Body > |
Shared Body pointer. More... | |
Public Member Functions | |
BoxCollider (Vector2f size={0.1f, 0.1f}) | |
Default constructor. More... | |
BoxCollider (BoxCollider &&) noexcept | |
Move constructor. More... | |
BoxCollider & | operator= (BoxCollider &&) noexcept |
Move assignment operator. More... | |
BoxCollider::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 | setSize (float width, float height) |
Set the size of the box. More... | |
void | setSize (Vector2f size) |
Set the size of the box. More... | |
Vector2f | getSize () const |
Get the size of the box. More... | |
~BoxCollider () 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 if the collider is a sensor or not. 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... | |
BodyPtr | getBody () |
Get the body the collider is attached to. More... | |
const BodyPtr & | getBody () const |
bool | containsPoint (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... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the alias of the object. More... | |
unsigned int | getObjectId () const |
Get the id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback) |
Add an event listener to a specific property change event. More... | |
void | onPropertyChange (const Callback< Property > &callback) |
Add an event listener to a property change event. More... | |
int | onEvent (const std::string &event, const Callback<> &callback) |
Add an event listener to an event. More... | |
bool | unsubscribe (const std::string &event, int id) |
Remove an event listener from an event. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | removeDestructionListener (int id) |
Remove a destruction listener form the object. More... | |
bool | operator== (const Object &rhs) const |
Check if two objects are the same object or not. More... | |
bool | operator!= (const Object &rhs) const |
Check if two objects are not the same object. More... | |
Static Public Member Functions | |
static BoxCollider::Ptr | create (Vector2f size={0.1f, 0.1f}) |
Create a box collider object. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emit (const std::string &event) |
Dispatch an action event. More... | |
A box collider.
The box is axis-aligned (Its edges are parallel to the X or Y axis of the local space
Definition at line 42 of file BoxCollider.h.
|
inherited |
Shared Body pointer.
Definition at line 121 of file Collider.h.
using ime::BoxCollider::ConstPtr = std::shared_ptr<const BoxCollider> |
Const shared collider pointer.
Definition at line 45 of file BoxCollider.h.
using ime::BoxCollider::Ptr = std::shared_ptr<BoxCollider> |
shred collider pointer
Definition at line 44 of file BoxCollider.h.
|
stronginherited |
The type of the collider.
Enumerator | |
---|---|
Circle | Circle collider. |
Box | Box collider. |
Polygon | Polygon collider. |
Edge | Edge collider. |
Definition at line 126 of file Collider.h.
|
explicit |
Default constructor.
size | The size of the box |
By default the size is 0.1f (width) x 0.1f (height)
|
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 |
BoxCollider::Ptr ime::BoxCollider::copy | ( | ) | const |
|
static |
Create a box collider object.
size | The size of the box |
This function is just a helper function for creating a shared pointer to a box collider. The class does not keep the pointer
By default the size is 0.1f (width) x 0.1f (height)
|
protectedinherited |
Dispatch an action event.
event | The name of the event to be dispatched |
This function will invoke all event listeners of the specified event. The function should be used for events that represent an action, rather than those that represent a property change (Use emitChange for that)
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
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 id of the object.
Each 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::BoxCollider::getSize | ( | ) | const |
Get the size of the box.
|
inherited |
|
inherited |
Get the type of the collider.
|
inherited |
Get the user data extracted from the collider definition.
|
inherited |
Check whether or not the collider is a sensor.
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
Note that an object may have more than one destruction listeners, however, you have to keep the returned id if you may want to remove the callback at a later time
|
inherited |
Add an event listener to an event.
event | The name of the event to add an an event listener to |
callback | The function to be executed when the event takes place |
Unlike onPropertyChange, this function registers event listeners to events that occur when something happens to the object, or when the object does something (action events). Usually the name of the event/action is the name of the function:
Add an event listener to a property change event.
callback | The function to be executed when the property changes |
Note that only one callback function may be registered with this function. This means that adding a new event listener overwrites the previous event listener. To remove the callback, pass a nullptr as an argument. The function may be useful if you want to write the logic for property changes in one function.
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to listen for |
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, for the setTag function, the property that the function modifies is Tag.
Note that when adding a property change event listener, the name of the property must be in lowercase:
Unlike onPropertyChange(const Callback&) you can add multiple event listeners to the same property using this function. However you must store the unique id of the event listener if you wish to remove it at a later time
|
inherited |
Check if two objects are not the same object.
rhs | Object to compare against this object |
Two objects are different from each other if they have different object id's
|
noexcept |
Move assignment operator.
|
inherited |
Check if two objects are the same object or not.
rhs | Object to compare against this object |
Two objects are the same object if they have the same object id. Recall that each object instance has a unique id
|
inherited |
Remove a destruction listener form the object.
The | id of the destruction 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
|
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 if the collider is a sensor or not.
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. Also, sensors only form contacts when at least one body is dynamic, so 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
void ime::BoxCollider::setSize | ( | float | width, |
float | height | ||
) |
Set the size of the box.
width | The width of the box |
height | The height of the box |
The box is centred at the local origin
void ime::BoxCollider::setSize | ( | Vector2f | size | ) |
Set the size of the box.
size | The size of the box |
|
inherited |
Assign the object an alias.
name | The alias of the object |
This function is useful if you want to refer to the object by tag instead of its id. Unlike an object id, multiple objects may have the same tag.
By default, the tag is an empty string
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove event listener from |
id | The unique id of the event listener to be removed |