CORGI
An open source project by
FPL.
|
The Component that manages the physics for every Entity that registers with it. More...
#include <physics.h>
Inherits corgi::Component< PhysicsData >.
The Component that manages the physics for every Entity that registers with it.
Public Member Functions | |
PhysicsComponent () | |
Constructor for the PhysicsComponent. | |
virtual | ~PhysicsComponent () |
Destructor for the PhysicsComponent. | |
virtual void | AddFromRawData (corgi::EntityRef &entity, const void *raw_data) |
Deserialize a flat binary buffer to create and populate an Entity from raw data. More... | |
virtual RawDataUniquePtr | ExportRawData (const corgi::EntityRef &entity) const |
Serializes a PhysicsComponent's data for a given Entity. More... | |
virtual void | Init () |
Initializes the internal state of the variables for the PhysicsComponent. | |
virtual void | InitEntity (corgi::EntityRef &) |
Adds an Entity to the TransformComponent. More... | |
virtual void | CleanupEntity (corgi::EntityRef &entity) |
Disables physics for the given Entity. More... | |
virtual void | UpdateAllEntities (corgi::WorldTime delta_time) |
Update the physics data for all Entities registered with this Component. More... | |
void | ProcessBulletTickCallback () |
Called after every Bullet frame update to handle all the collisions. | |
void | UpdatePhysicsFromTransform (const corgi::EntityRef &entity) |
Update the physics world to match the transform for a given Entity. More... | |
void | UpdatePhysicsScale (const corgi::EntityRef &entity) |
Update the physics scale to match the transform for a given Entity. More... | |
void | EnablePhysics (const corgi::EntityRef &entity) |
Enables physics for a given Entity. More... | |
void | DisablePhysics (const corgi::EntityRef &entity) |
Disables physics for a given Entity. More... | |
void | AwakenEntity (const corgi::EntityRef &entity) |
Activate the rigid bodies for a given Entity to force reevaluation within the scene. More... | |
void | AwakenAllEntities () |
Activates the rigid bodies in every Entity to force reevaluation within the scene. | |
void | InitStaticMesh (corgi::EntityRef &entity) |
Initialize the data needed to generate a static mesh. More... | |
void | AddStaticMeshTriangle (const corgi::EntityRef &entity, const mathfu::vec3 &pt0, const mathfu::vec3 &pt1, const mathfu::vec3 &pt2) |
Add a triangle to the static mesh for the given entity. More... | |
void | FinalizeStaticMesh (const corgi::EntityRef &entity, short collision_type, short collides_with, float mass, float restitution, const std::string &user_tag) |
Generates a static mesh shape and adds it to the world, based on the previously added static mesh triangles. More... | |
void | GenerateRaycastShape (corgi::EntityRef &entity, bool result_exportable) |
Generate an AABB based on the rendermesh that collides with the raycast layer. More... | |
corgi::EntityRef | RaycastSingle (mathfu::vec3 &start, mathfu::vec3 &end) |
Performs a raycast into the world, returning the first Entity hit. More... | |
corgi::EntityRef | RaycastSingle (mathfu::vec3 &start, mathfu::vec3 &end, short layer_mask) |
Performs a raycast into the world, returning the first Entity hit. More... | |
corgi::EntityRef | RaycastSingle (mathfu::vec3 &start, mathfu::vec3 &end, mathfu::vec3 *hit_point) |
Performs a raycast into the world, returning the first Entity hit. More... | |
corgi::EntityRef | RaycastSingle (mathfu::vec3 &start, mathfu::vec3 &end, short layer_mask, mathfu::vec3 *hit_point) |
Performs a raycast into the world, returning the first Entity hit. More... | |
float | GravityForEntity (const corgi::EntityRef &entity) const |
Get the gravity value of the given Entity. More... | |
void | DebugDrawWorld (fplbase::Renderer *renderer, const mathfu::mat4 &camera_transform) |
Render the entire physics worlds using Bullet's default debugging tools. More... | |
void | DebugDrawObject (fplbase::Renderer *renderer, const mathfu::mat4 &camera_transform, const corgi::EntityRef &entity, const mathfu::vec3 &color) |
Render a given Entity's physics using Bullet's default debugging tools. More... | |
btDiscreteDynamicsWorld * | bullet_world () |
Get the bullet world. More... | |
void | set_gravity (float gravity) |
Set the gravity value. More... | |
float | gravity () const |
Get the gravity value. More... | |
void | set_max_steps (int max_steps) |
Set the max steps. More... | |
int | max_steps () const |
Get the max steps. More... | |
CollisionData & | collision_data () |
Get the collision data. More... | |
void | set_collision_callback (CollisionCallback callback, void *user_data) |
Sets the callback function for collisions. More... | |
Public Member Functions inherited from corgi::Component< PhysicsData > | |
Component () | |
Construct a Component without an EntityManager. | |
virtual | ~Component () |
Destructor for a Component. | |
virtual void | AddEntityGenerically (EntityRef &entity) |
Provides an alternate way to add Entities if you do not care about the returned data structure, and if you do not feel like casting the BaseComponent into something more specific. More... | |
PhysicsData * | AddEntity (EntityRef &entity, AllocationLocation alloc_location) |
Adds an Entity to the list that this Component is tracking. More... | |
PhysicsData * | AddEntity (EntityRef &entity) |
Adds an Entity to the list that this Component is tracking. More... | |
virtual void | RemoveEntity (EntityRef &entity) |
Removes an Entity from the list of Entities. More... | |
virtual EntityIterator | RemoveEntity (EntityIterator iter) |
Removes an Entity from the list of Entities. More... | |
virtual EntityIterator | begin () |
Gets an iterator that will iterate over every Entity associated with the Component, starting from the beginning. More... | |
virtual EntityIterator | end () |
Gets an iterator that points to the end of the list of all entites in the Component. More... | |
virtual bool | HasDataForEntity (const EntityRef &entity) |
Checks if this component contains any data associated with the supplied entity. | |
virtual void * | GetComponentDataAsVoid (const EntityRef &entity) |
Gets the data for a given Entity as a void pointer. More... | |
virtual const void * | GetComponentDataAsVoid (const EntityRef &entity) const |
Gets the data for a given Entity as a const void pointer. More... | |
PhysicsData * | GetComponentData (size_t data_index) |
Gets the Component data stored at a given index. More... | |
PhysicsData * | GetComponentData (const EntityRef &entity) |
Gets the data for a given Entity. More... | |
const PhysicsData * | GetComponentData (size_t data_index) const |
Gets the Component data stored at a given index. More... | |
const PhysicsData * | GetComponentData (const EntityRef &entity) const |
Gets the data for a given Entity. More... | |
virtual void | ClearComponentData () |
Clears all tracked Component data. | |
ComponentDataType * | Data (const EntityRef &entity) |
A utility function for retrieving the Component data for an Entity from a specific Component. More... | |
ComponentDataType * | Data (const EntityRef &entity) const |
A utility function for retrieving the Component data for an Entity from a specific Component. More... | |
bool | IsRegisteredWithComponent (const EntityRef &entity) |
A utility function for checking if an entity is registered with a particular component. More... | |
ComponentDataType * | GetComponent () |
A utility function for retrieving a reference to a specific Component object, by type. More... | |
virtual void | Cleanup () |
Override this function with any code that executes when this Component is removed from the EntityManager. (i.e. Usually when the game/state is over and everything is shutting down.) | |
virtual void | SetEntityManager (EntityManager *entity_manager) |
Set the EntityManager for this Component. More... | |
virtual void | SetComponentIdOnDataType (ComponentId id) |
Sets the Component ID on the data type. More... | |
Public Member Functions inherited from corgi::ComponentInterface | |
virtual | ~ComponentInterface () |
A destructor for the Component interface. | |
Additional Inherited Members | |
Public Types inherited from corgi::Component< PhysicsData > | |
typedef VectorPool < ComponentData >::Iterator | EntityIterator |
An iterator to iterate through all of the Entities in the Component. | |
typedef PhysicsData | value_type |
The templated data type stored by this Component. | |
Public Types inherited from corgi::ComponentInterface | |
typedef std::unique_ptr < uint8_t, std::function< void(uint8_t *)> > | RawDataUniquePtr |
A pointer type for exported raw data. | |
Static Public Member Functions inherited from corgi::Component< PhysicsData > | |
static ComponentId | GetComponentId () |
Get the ID for this Component. More... | |
Protected Member Functions inherited from corgi::Component< PhysicsData > | |
size_t | GetComponentDataIndex (const EntityRef &entity) const |
Get the index of the Component data for a given Entity. More... | |
Protected Attributes inherited from corgi::Component< PhysicsData > | |
VectorPool< ComponentData > | component_data_ |
Storage for all of the data for the Component. | |
EntityManager * | entity_manager_ |
A pointer to the EntityManager for this Component. This is the main point of contact for Components that need to talk to other things. | |
std::unordered_map < EntityIdType, ComponentIndex > | component_index_lookup_ |
A map, for translating unique entity IDs into vectorpool indexes. | |
|
virtual |
Deserialize a flat binary buffer to create and populate an Entity from raw data.
[in,out] | entity | An EntityRef reference that points to an Entity that is being added from the raw data. |
[in] | raw_data | A void pointer to the raw FlatBuffer data. |
Implements corgi::ComponentInterface.
void PhysicsComponent::AddStaticMeshTriangle | ( | const corgi::EntityRef & | entity, |
const mathfu::vec3 & | pt0, | ||
const mathfu::vec3 & | pt1, | ||
const mathfu::vec3 & | pt2 | ||
) |
Add a triangle to the static mesh for the given entity.
InitStaticMesh()
needs to be called beforehand.[in] | entity | An EntityRef to the Entity whose PhysicsData should add the new static mesh. |
[in] | pt0 | The first vertex for the triangle. |
[in] | pt1 | The second vertex for the triangle. |
[in] | pt2 | The third vertex for the triangle. |
void PhysicsComponent::AwakenEntity | ( | const corgi::EntityRef & | entity | ) |
Activate the rigid bodies for a given Entity to force reevaluation within the scene.
[in] | entity | An EntityRef reference to the Entity whose rigid bodies should be activated. |
|
inline |
Get the bullet world.
btDiscreteDynamicsWorld
.
|
virtual |
Disables physics for the given Entity.
[in] | entity | An EntityRef reference to the Entity that should be cleaned up by having its physics disabled. |
Reimplemented from corgi::Component< PhysicsData >.
|
inline |
Get the collision data.
void PhysicsComponent::DebugDrawObject | ( | fplbase::Renderer * | renderer, |
const mathfu::mat4 & | camera_transform, | ||
const corgi::EntityRef & | entity, | ||
const mathfu::vec3 & | color | ||
) |
Render a given Entity's physics using Bullet's default debugging tools.
[in] | renderer | A pointer to the fplbase::Renderer to handle the rendering. |
[in] | camera_transform | The camera transform for the view projection. |
[in] | entity | The Entity whose physics should be rendered. |
[in] | color | The color to draw the object in RGB. |
void PhysicsComponent::DebugDrawWorld | ( | fplbase::Renderer * | renderer, |
const mathfu::mat4 & | camera_transform | ||
) |
Render the entire physics worlds using Bullet's default debugging tools.
[in] | renderer | A pointer to the fplbase::Renderer to handle the rendering. |
[in] | camera_transform | The camera transform for the view projection. |
void PhysicsComponent::DisablePhysics | ( | const corgi::EntityRef & | entity | ) |
Disables physics for a given Entity.
[in] | entity | An EntityRef reference to the Entity whose physics should be disabled. |
void PhysicsComponent::EnablePhysics | ( | const corgi::EntityRef & | entity | ) |
Enables physics for a given Entity.
[in] | entity | An EntityRef reference to the Entity whose physics should be enabled. |
|
virtual |
Serializes a PhysicsComponent's data for a given Entity.
[in] | entity | An EntityRef reference to an Entity whose corresponding PhysicsData will be serialized. |
Reimplemented from corgi::Component< PhysicsData >.
void PhysicsComponent::FinalizeStaticMesh | ( | const corgi::EntityRef & | entity, |
short | collision_type, | ||
short | collides_with, | ||
float | mass, | ||
float | restitution, | ||
const std::string & | user_tag | ||
) |
Generates a static mesh shape and adds it to the world, based on the previously added static mesh triangles.
[in] | entity | An EntityRef to the Entity whose PhysicsData contains the static mesh. |
[in] | collision_type | A bit field determining the type of collision for the rigid body. |
[in] | collides_with | A bit field determining what type of objects the rigid body can collide into. |
[in] | mass | The mass of the rigid body. |
[in] | restitution | The restitution for the rigid body. |
[in] | user_tag | A C-string provided by the user to identify the rigid body. |
void PhysicsComponent::GenerateRaycastShape | ( | corgi::EntityRef & | entity, |
bool | result_exportable | ||
) |
Generate an AABB based on the rendermesh that collides with the raycast layer.
[in] | entity | An EntityRef to the Entity whose AABB should be generated for raycasting. |
[in] | result_exportable | A bool flag determining if the resulting shape should be exported. |
|
inline |
Get the gravity value.
float PhysicsComponent::GravityForEntity | ( | const corgi::EntityRef & | entity | ) | const |
Get the gravity value of the given Entity.
[in] | entity | The Entity to get the custom gravity for. |
|
virtual |
Adds an Entity to the TransformComponent.
Reimplemented from corgi::Component< PhysicsData >.
void PhysicsComponent::InitStaticMesh | ( | corgi::EntityRef & | entity | ) |
Initialize the data needed to generate a static mesh.
Adds the entity to the PhysicsComponent, if necessary.
[in] | entity | An EntityRef to the entity that should be added to the PhysicsComponent, if necessary. |
|
inline |
Get the max steps.
corgi::EntityRef PhysicsComponent::RaycastSingle | ( | mathfu::vec3 & | start, |
mathfu::vec3 & | end | ||
) |
Performs a raycast into the world, returning the first Entity hit.
[in] | start | The start point (origin) of the ray. |
[in] | end | The end point of the ray. |
corgi::EntityRef PhysicsComponent::RaycastSingle | ( | mathfu::vec3 & | start, |
mathfu::vec3 & | end, | ||
short | layer_mask | ||
) |
Performs a raycast into the world, returning the first Entity hit.
[in] | start | The start point (origin) of the ray. |
[in] | end | The end point of the ray. |
[in] | layer_mask | A bit field used to specify which layers the raycast could hit. |
corgi::EntityRef PhysicsComponent::RaycastSingle | ( | mathfu::vec3 & | start, |
mathfu::vec3 & | end, | ||
mathfu::vec3 * | hit_point | ||
) |
Performs a raycast into the world, returning the first Entity hit.
[in] | start | The start point (origin) of the ray. |
[in] | end | The end point of the ray. |
[out] | hit_point | Captures the output of the value where the ray hit the Entity in world position, as a vec3. |
corgi::EntityRef PhysicsComponent::RaycastSingle | ( | mathfu::vec3 & | start, |
mathfu::vec3 & | end, | ||
short | layer_mask, | ||
mathfu::vec3 * | hit_point | ||
) |
Performs a raycast into the world, returning the first Entity hit.
[in] | start | The start point (origin) of the ray. |
[in] | end | The end point of the ray. |
[in] | layer_mask | A bit field used to specify which layers the raycast could hit. |
[out] | hit_point | Captures the output of the value where the ray hit the Entity in world position, as a vec3. |
|
inline |
Sets the callback function for collisions.
[in] | callback | The event callback to call when a collision occurs. If a callback is registered, then it is called in addition to evaluating the graph. |
[in] | user_data | A void pointer to any data provided to for the callback . |
|
inline |
Set the gravity value.
[in] | gravity | A float to set as the new gravity value. |
|
inline |
Set the max steps.
[in] | max_steps | An int to set as the new max steps value. |
|
virtual |
Update the physics data for all Entities registered with this Component.
[in] | delta_time | The time delta since the last call. |
Reimplemented from corgi::Component< PhysicsData >.
void PhysicsComponent::UpdatePhysicsFromTransform | ( | const corgi::EntityRef & | entity | ) |
Update the physics world to match the transform for a given Entity.
[in] | entity | The Entity whose physics data should be updated to match the transform data. |
void PhysicsComponent::UpdatePhysicsScale | ( | const corgi::EntityRef & | entity | ) |
Update the physics scale to match the transform for a given Entity.
[in] | entity | The Entity whose physics scale should be updated to match the transform data. |