/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "entityphysics.h" #include "entity/entitymanager.h" #include "entity/component/display/entityposition.h" #include "physics/physicsmanager.h" #include "assert/assert.h" #include "util/memory.h" void entityPhysicsInit( const entityid_t entityId, const componentid_t componentId ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); memoryZero(phys, sizeof(entityphysics_t)); // Default to cube phys->type = PHYSICS_BODY_DYNAMIC; phys->shape.type = PHYSICS_SHAPE_CUBE; phys->shape.data.cube.halfExtents[0] = 0.5f; phys->shape.data.cube.halfExtents[1] = 0.5f; phys->shape.data.cube.halfExtents[2] = 0.5f; phys->gravityScale = 1.0f; phys->onGround = false; } entityphysics_t *entityPhysicsGet( const entityid_t entityId, const componentid_t componentId ) { return componentGetData(entityId, componentId, COMPONENT_TYPE_PHYSICS); } void entityPhysicsSetShape( const entityid_t entityId, const componentid_t componentId, const physicsshape_t shape ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); phys->shape = shape; // TODO: Do I need to reset the state for ground/active? } physicsshape_t entityPhysicsGetShape( const entityid_t entityId, const componentid_t componentId ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); return phys->shape; } void entityPhysicsGetVelocity( const entityid_t entityId, const componentid_t componentId, vec3 dest ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); glm_vec3_copy(phys->velocity, dest); } void entityPhysicsSetVelocity( const entityid_t entityId, const componentid_t componentId, vec3 velocity ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); glm_vec3_copy(velocity, phys->velocity); } void entityPhysicsApplyImpulse( const entityid_t entityId, const componentid_t componentId, vec3 impulse ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); if(phys->type == PHYSICS_BODY_STATIC) return; glm_vec3_add(phys->velocity, impulse, phys->velocity); } bool_t entityPhysicsIsOnGround( const entityid_t entityId, const componentid_t componentId ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); return phys->onGround; } void entityPhysicsSetBodyType( const entityid_t entityId, const componentid_t componentId, const physicsbodytype_t type ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); phys->type = type; } physicsbodytype_t entityPhysicsGetBodyType( const entityid_t entityId, const componentid_t componentId ) { entityphysics_t *phys = entityPhysicsGet(entityId, componentId); assertNotNull(phys, "Failed to get physics component data"); return phys->type; } void entityPhysicsDispose( const entityid_t entityId, const componentid_t componentId ) { }