15 #ifndef CORGI_COMPONENT_LIBRARY_PHYSICS_H_
16 #define CORGI_COMPONENT_LIBRARY_PHYSICS_H_
21 #include "breadboard/event.h"
23 #include "flatbuffers/reflection.h"
24 #include "fplbase/asset_manager.h"
25 #include "fplbase/renderer.h"
26 #include "fplbase/shader.h"
27 #include "library_components_generated.h"
28 #include "mathfu/glsl_mappings.h"
31 class btBroadphaseInterface;
32 class btCollisionDispatcher;
33 class btCollisionShape;
34 class btDefaultCollisionConfiguration;
35 class btDiscreteDynamicsWorld;
38 class btSequentialImpulseConstraintSolver;
42 namespace component_library {
44 BREADBOARD_DECLARE_EVENT(kCollisionEventId)
47 class PhysicsDebugDrawer;
145 std::unique_ptr<btCollisionShape>
shape;
200 mathfu::vec3 Velocity()
const;
206 void SetVelocity(
const mathfu::vec3& velocity);
211 mathfu::vec3 AngularVelocity()
const;
217 void SetAngularVelocity(
const mathfu::vec3& velocity);
225 int RigidBodyIndex(
const std::string& user_tag)
const;
236 void GetAabb(
int rigid_body_idx, mathfu::vec3* min, mathfu::vec3* max)
const;
256 std::unique_ptr<btTriangleMesh> triangle_mesh_;
259 float gravity_multiplier_;
280 virtual void AddFromRawData(
corgi::EntityRef& entity,
const void* raw_data);
314 void ProcessBulletTickCallback();
351 void AwakenAllEntities();
371 const mathfu::vec3& pt0,
const mathfu::vec3& pt1,
372 const mathfu::vec3& pt2);
387 void FinalizeStaticMesh(
const corgi::EntityRef& entity,
short collision_type,
388 short collides_with,
float mass,
float restitution,
389 const std::string& user_tag);
401 void GenerateRaycastShape(
corgi::EntityRef& entity,
bool result_exportable);
431 mathfu::vec3* hit_point);
444 short layer_mask, mathfu::vec3* hit_point);
458 void DebugDrawWorld(fplbase::Renderer* renderer,
459 const mathfu::mat4& camera_transform);
469 void DebugDrawObject(fplbase::Renderer* renderer,
470 const mathfu::mat4& camera_transform,
472 const mathfu::vec3& color);
478 btDiscreteDynamicsWorld*
bullet_world() {
return bullet_world_.get(); }
513 collision_callback_ = callback;
514 collision_user_data_ = user_data;
520 bool kinematic_only);
528 void* collision_user_data_;
530 std::unique_ptr<btDiscreteDynamicsWorld> bullet_world_;
531 std::unique_ptr<btBroadphaseInterface> broadphase_;
532 std::unique_ptr<btDefaultCollisionConfiguration> collision_configuration_;
533 std::unique_ptr<btCollisionDispatcher> collision_dispatcher_;
534 std::unique_ptr<btSequentialImpulseConstraintSolver> constraint_solver_;
536 std::unique_ptr<PhysicsDebugDrawer> debug_drawer_;
547 corgi::component_library::PhysicsData)
549 #endif // CORGI_COMPONENT_LIBRARY_PHYSICS_H_
static const int kDefaultPhysicsMaxSteps
The default number of max steps to advance per frame.
Definition: physics.h:67
std::unique_ptr< uint8_t, std::function< void(uint8_t *)> > RawDataUniquePtr
A pointer type for exported raw data.
Definition: component_interface.h:63
std::unique_ptr< btRigidBody > rigid_body
The btRigidBody of the RigidBodyData.
Definition: physics.h:155
A Component is an object that encapsulates all data and logic for Entities of a particular type...
Definition: component.h:43
void set_collision_callback(CollisionCallback callback, void *user_data)
Sets the callback function for collisions.
Definition: physics.h:512
corgi::EntityRef this_entity
The first Entity involved in the collision.
Definition: physics.h:76
btDiscreteDynamicsWorld * bullet_world()
Get the bullet world.
Definition: physics.h:478
static const int kMaxPhysicsBodies
The maximum number of physics bodies per Entity.
Definition: physics.h:57
static const float kDefaultPhysicsGravity
The constant for gravity.
Definition: physics.h:62
int max_steps() const
Get the max steps.
Definition: physics.h:498
Data describing which Entities were involed in a collision and where.
Definition: physics.h:72
int WorldTime
A typedef that represents time in the game.
Definition: entity_common.h:49
std::unique_ptr< btMotionState > motion_state
The btMotionState of the RigidBodyData.
Definition: physics.h:150
std::string this_tag
A std::string tag to identify the first Entity involved in the collision.
Definition: physics.h:87
mathfu::vec3 offset
The position offset from the origin of the TransformComponent to the center.
Definition: physics.h:125
std::string user_tag
A user-defined C-string tag to identify this rigid body.
Definition: physics.h:140
CollisionData & collision_data()
Get the collision data.
Definition: physics.h:503
int body_count() const
Get the number of physics shapes for this Entity.
Definition: physics.h:247
mathfu::vec3 other_position
The position of the second Entity involved in the collision.
Definition: physics.h:97
Data for scene object Components.
Definition: physics.h:175
float gravity() const
Get the gravity value.
Definition: physics.h:488
bool should_export
Should the shape be included on export.
Definition: physics.h:160
mathfu::vec3 this_position
The position of the first Entity involved in the collision.
Definition: physics.h:81
corgi::EntityRef other_entity
The second Entity involved in the collision.
Definition: physics.h:92
short collides_with
A bit field determining what types of objects it can collide into.
Definition: physics.h:135
A reference object for pointing into the vector pool. It acts as a pointer for vector pool elements a...
Definition: vector_pool.h:72
bool enabled() const
Check if this physics is enabled for this Entity.
Definition: physics.h:242
std::unique_ptr< btCollisionShape > shape
The btCollisionShape of the RigidBodyData.
Definition: physics.h:145
The Component that manages the physics for every Entity that registers with it.
Definition: physics.h:266
void set_max_steps(int max_steps)
Set the max steps.
Definition: physics.h:493
#define CORGI_REGISTER_COMPONENT(ComponentType, DataType)
Definition: component_id_lookup.h:48
void set_gravity(float gravity)
Set the gravity value.
Definition: physics.h:483
std::string other_tag
A std::string tag to identify the second Entity involved in the collision.
Definition: physics.h:103
Data describing a single Bullet rigid body shape.
Definition: physics.h:115
short collision_type
A bit field determining what type of collision object this is.
Definition: physics.h:130
void(* CollisionCallback)(CollisionData *collision_data, void *user_data)
A function pointer for the callback after a collision.
Definition: physics.h:109