Techneck/code/source-c/physics/simulation.h

83 lines
2.3 KiB
C
Raw Permalink Normal View History

2023-10-15 08:21:36 +00:00
#ifndef TC_PHYSICS_SIMULATION_H
#define TC_PHYSICS_SIMULATION_H
#include <stdint.h>
2023-10-15 12:41:53 +00:00
#include <physics/primitives.h>
2023-10-15 08:21:36 +00:00
#include <utility/utility.h>
2023-10-17 14:37:19 +00:00
#include <entity/entity.h>
2023-10-15 08:21:36 +00:00
typedef struct tc_physics_entity tc_physics_entity_s;
2023-10-15 12:41:53 +00:00
typedef struct tc_entity_physics_attributes tc_entity_physics_attributes_s;
typedef struct tc_physics_simulation tc_physics_simulation_s;
2023-10-15 08:21:36 +00:00
struct tc_entity_physics_attributes
{
2023-10-15 12:41:53 +00:00
bool_t has_gravity;
2023-10-15 08:21:36 +00:00
2023-10-15 12:41:53 +00:00
bool_t raw_movement;
bool_t raw_rotation;
2023-10-15 08:21:36 +00:00
2023-10-15 12:41:53 +00:00
tc_vec3f_s acceleration;
tc_vec3f_s spin;
2023-10-15 08:21:36 +00:00
};
typedef enum
{
TC_PHYSICS_ENTITY,
TC_PHYSICS_ENTITY_GROUP
} tc_physics_entity_type_e;
struct tc_physics_entity
{
tc_physics_simulation_s *simulation;
2023-10-15 12:41:53 +00:00
tc_physics_entity_s *super;
2023-10-15 08:21:36 +00:00
// relative_position: The position of this physics entity relative to its super-entity
2023-10-15 12:41:53 +00:00
tc_vec3f_s relative_position;
2023-10-15 08:21:36 +00:00
2023-10-15 12:41:53 +00:00
tc_physics_entity_type_e type;
2023-10-15 08:21:36 +00:00
union specific
{
struct entity
{
2023-10-15 12:41:53 +00:00
char *name;
tc_physics_mesh_s mesh;
2023-10-15 08:21:36 +00:00
} entity;
struct subentity_group
{
u32_t entities_capacity;
2023-10-15 12:41:53 +00:00
u32_t num_entities;
tc_physics_entity_s **entities;
2023-10-15 08:21:36 +00:00
} group;
} value;
};
struct tc_physics_simulation
2023-10-15 08:21:36 +00:00
{
tc_physics_entity_s *root;
2023-10-15 08:21:36 +00:00
};
tc_physics_simulation_s * tc_new_physics_simulation ();
void tc_add_physics_object (tc_physics_simulation_s *simulation, tc_physics_entity_s *object);
void tc_add_physics_object_to (tc_physics_entity_s *container, tc_physics_entity_s *object);
2023-10-15 08:21:36 +00:00
tc_physics_entity_s * tc_new_physics_entity (tc_physics_simulation_s *simulation);
tc_physics_entity_s * tc_new_physics_group (tc_physics_simulation_s *simulation);
2023-10-15 08:21:36 +00:00
void tc_remove_physics_entity (tc_physics_entity_s *entity);
2023-10-15 08:21:36 +00:00
2023-10-15 12:41:53 +00:00
void tc_tick_physics (tc_physics_simulation_s *simulation, f32_t delta);
2023-10-15 08:21:36 +00:00
2023-10-15 12:41:53 +00:00
tc_primitive_s * tc_cast_line (tc_physics_simulation_s *simulation, tc_line_s line);
2023-10-15 08:21:36 +00:00
#endif