Added files for physics engine

This commit is contained in:
Eric-Paul Ickhorn 2023-10-15 10:21:36 +02:00
parent dc3a81b7b4
commit 636b98dfea
8 changed files with 238 additions and 3 deletions

View File

@ -290,9 +290,6 @@ bool update()
tc_update_world(tc_game_state_g.main_world);
// uint64_t current_ms = SDL_GetTicks64();
// uint32_t ticks_between = current_ms - tc_last_update;
return true;
}

View File

@ -0,0 +1,4 @@
#include "primitives.h"

View File

@ -0,0 +1,3 @@
#include "primitives.h"

View File

@ -0,0 +1,42 @@
#include "simulation.h"
tc_physics_simulation_s tc_new_physics_simulation()
{
}
void tc_add_physics_object(tc_physics_simulation_s *simulation, tc_physics_entity object)
{
}
void tc_add_physics_object_to(tc_physics_entity_s *container, tc_physics_entity_s object)
{
}
tc_phyiscs_entity_s tc_new_physics_entity()
{
}
void tc_tick_physics(tc_physics_simulation_s *simulation, float delta)
{
}

View File

@ -0,0 +1,4 @@
#include "primitives.h"

View File

@ -0,0 +1,97 @@
#ifndef TC_PHYSICS_PRIMITIVES_H
#define TC_PHYSICS_PRIMITIVES_H
#include <stdbool.h>
#include <stdint.h>
#include "../utility.h"
typedef struct tc_physics_mesh tc_physics_mesh_s;
typedef struct tc_aabb tc_aabb_s;
typedef struct tc_obb tc_obb_s;
typedef struct tc_plane tc_plane_s;
typedef struct tc_ellipsoid tc_ellipsoid_s;
typedef struct tc_ray tc_ray_s;
typedef struct tc_line tc_line_s;
typedef enum
{
TC_PRIMITIVE_AABB,
TC_PRIMITIVE_OBB,
TC_PRIMITIVE_PLANE,
TC_PRIMITIVE_ELLIPSOID,
TC_PRIMITIVE_RAY,
TC_PRIMITIVE_LINE
} tc_primitive_type_e;
struct tc_aabb
{
tc_vec3_s start;
tc_vec3_s size;
};
struct tc_obb
{
tc_vec3_s start;
tc_vec3_s size;
tc_vec3_s rotation;
};
struct tc_plane
{
tc_vec3_s center;
tc_vec3_s rotation;
tc_vec2i_s size;
};
struct tc_ellipsoid
{
tc_vec3_s center;
tc_vec3_s extent;
};
struct tc_ray
{
tc_vec3_s start;
tc_vec3_s rotation;
};
struct tc_line
{
tc_vec3_s start;
tc_vec3_s end;
};
typedef union tc_primitive
{
tc_aabb_s aabb;
tc_obb_s obb;
tc_plane_s plane;
tc_ellipsoid_s sphere;
tc_plane_s plane;
tc_line_s line;
tc_ray_s ray;
} tc_primitive_u;
typedef struct tc_primitive
{
tc_primitive_type_e type;
tc_primitive_u data;
} tc_primitive_s;
struct tc_physics_mesh
{
uint32_t primitives_capacity;
uint32_t num_primitives;
tc_primitive_s *primitives;
};
#endif // TC_PHYSICS_PRIMITIVES_H

View File

@ -0,0 +1,10 @@
#include "primitives.h"
tc_primitive_s * tc_cast_line(tc_physics_simulation_s *simulation, tc_line_s line)
{
}

View File

@ -0,0 +1,78 @@
#ifndef TC_PHYSICS_SIMULATION_H
#define TC_PHYSICS_SIMULATION_H
#include <stdint.h>
#include <utility/utility.h>
#include <../entity.h>
typedef struct tc_physics_entity tc_physics_entity_s;
typedef struct tc_entity_physics_attributes tc_entity_physics_attributes;
struct tc_entity_physics_attributes
{
bool has_gravity;
bool raw_movement;
bool raw_rotation;
tc_vec3_s acceleration;
tc_vec3_s spin;
};
typedef enum
{
TC_PHYSICS_ENTITY,
TC_PHYSICS_ENTITY_GROUP
} tc_physics_entity_type_e;
struct tc_physics_entity
{
tc_physics_entity *super;
// relative_position: The position of this physics entity relative to its super-entity
tc_vec3_s relative_position;
tc_physics_entity_e type;
union specific
{
struct entity
{
tc_entity_s *entity;
} entity;
struct subentity_group
{
uint32_t num_entities;
tc_physics_entity_s *entities;
} group;
} value;
};
typedef struct tc_physics_simulation
{
tc_vec3_s limits;
tc_physics_entity_s world_root;
} tc_physics_simulation_s;
tc_physics_simulation_s tc_new_physics_simulation ();
void tc_add_physics_object (tc_physics_simulation_s *simulation, tc_physics_entity object);
void tc_add_physics_object_to (tc_physics_entity_s *container, tc_physics_entity_s object);
tc_phyiscs_entity_s tc_new_physics_entity ();
void tc_tick_physics (tc_physics_simulation_s *simulation, float delta);
tc_primitive_s tc_cast_line (tc_physics_simulation_s *simulation, tc_line_s line);
#endif