Techneck/code/source-c/world_physics.c

51 lines
2.1 KiB
C

#include <world.h>
#include <stddef.h> // For NULL
#include <stdio.h>
void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
{
tc_chunk_s *chunk = chunk_entity->specific;
tc_world_s *world = chunk->location.world;
tc_physics_simulation_s *simulation = world->physics;
tc_physics_entity_s *chunk_body = tc_new_physics_group(simulation);
tc_vec3f_s block_start;
block_start.x = -0.5f;
block_start.y = -0.5f;
block_start.z = -0.5f;
tc_vec3f_s block_size;
block_size.x = 1.0f;
block_size.y = 1.0f;
block_size.z = 1.0f;
tc_physics_mesh_s block_mesh = tc_wrap_aabb(block_start, block_size);
for(u32_t x = 0; x < 32; ++x)
for(u32_t y = 0; y < 32; ++y)
for(u32_t z = 0; z < 32; ++z)
{
tc_physics_entity_s *block_entity = tc_new_physics_entity(simulation);
block_entity->relative_position.x = x;
block_entity->relative_position.y = y;
block_entity->relative_position.z = z;
block_entity->type = TC_PHYSICS_ENTITY;
block_entity->value.entity.mesh = block_mesh;
tc_add_physics_object_to(chunk_body, block_entity);
}
tc_add_physics_object(world->physics, chunk_body);
tc_set_pointer_for_entity(chunk_entity, "physics_body", chunk_body);
}
void tc_create_world_physics(tc_world_s *world, void *userdata)
{
world->physics = tc_new_physics_simulation();
tc_add_to_hooklist(&world->on_chunk_create, (tc_fn_hook) tc_initialize_chunk_physics, NULL);
tc_add_to_hooklist(&world->on_chunk_update, (tc_fn_hook) tc_initialize_chunk_physics, NULL);
}