Physics working

This commit is contained in:
Confideo-IOM
2026-08-24 20:59:24 +01:00
parent 20c0794d10
commit 1253571c17
146 changed files with 4469 additions and 1273 deletions
+19 -16
View File
@@ -6,7 +6,9 @@
#include "../ecs/HydraEntityManager.h"
#include "../ecs/HydraECS.h"
#include "../ecs/components/HydraPositionComponent.h"
#include "../ecs/components/HydraPhysicsComponent.h"
#include "../ecs/systems/HydraTransformSystem.h"
#include "../ecs/systems/HydraPhysicsSystem.h"
#include "../fileaccess/HydraGLTFLoader.h"
#include "../task/actor/HydraLoadGLTFFileTask.hpp"
#include "../scheduler/HydraTaskScheduler.h"
@@ -167,18 +169,11 @@ void HydraActorManager::SetPosition(HydraID actorID, glm::dvec3 position)
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
pos_comp.position = position;
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
// {
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
// // const float* matrix = glm::value_ptr<float>(GetActorPose(actorID));
// phys_comp.physics_definition.pose = GetActorPose(actorID);
// }
if(!pos_comp.needs_update)
if(!pos_comp.needs_update)
{
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
}
}
@@ -189,16 +184,24 @@ void HydraActorManager::SetOrientation(HydraID actorID, float x, float y, float
pos_comp.orientation = glm::vec3(x, y, z);
if(!pos_comp.needs_update)
{
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
// {
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
// phys_comp.physics_definition.pose = GetActorPose(actorID);
// }
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
}
}
void HydraActorManager::SetPositionAndOrientation(HydraID actorID, glm::dvec3 position, glm::vec3 euler_angles, bool ignore_physics)
{
HydraECS *ecs = GetEngine()->ECS();
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
pos_comp.position = position;
pos_comp.orientation = glm::vec3(euler_angles.x,euler_angles.y,euler_angles.z);
if(!pos_comp.needs_update)
{
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID, ignore_physics);
}
}
void HydraActorManager::SetScale(HydraID actor_id, glm::dvec3 scaling)
{
HydraECS *ecs = GetEngine()->ECS();
@@ -48,6 +48,7 @@ class CLASS_DEFINE HydraActorManager : public HydraObject
void SetPosition(HydraID actorID, glm::dvec3 position);
void SetOrientation(HydraID actorID, float x, float y, float z);
void SetPositionAndOrientation(HydraID actorID, glm::dvec3 position, glm::vec3 euler_angles, bool ignore_physics = false);
void SetScale(HydraID actor_id, glm::dvec3 scaling);
void TranslateActor(HydraID actorID, glm::dvec3 translation);
+12 -13
View File
@@ -7,6 +7,7 @@
#include "../ecs/components/HydraMeshComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraPhysicsComponent.h"
#include "../buffer/HydraMaterialBufferManager.h"
#include "../buffer/HydraTextureBufferManager.h"
#include "../buffer/HydraMaterialBuffer.h"
@@ -23,6 +24,7 @@ void HydraPlaneActor::InitialiseComponents()
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
_CreatePhysics();
}
void HydraPlaneActor::DeferredInitialiseComponents()
@@ -183,21 +185,18 @@ void HydraPlaneActor::_CreateMaterial()
void HydraPlaneActor::_CreatePhysics()
{
// HydraECSPhysicsComponent physics_component;
// physics_component.physics_state = Hydra_State::Waiting;
// physics_component.physics_definition.actor_id = GetID();
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
// physics_component.physics_definition.mass = 100000.0f;
// physics_component.physics_definition.extent_x = 1000.0f;
// physics_component.physics_definition.extent_y = 0.5f;
// physics_component.physics_definition.extent_z = 1000.0f;
// physics_component.physics_definition.dynamic_friction = 0.5f;
// physics_component.physics_definition.restitution = 0.5f;
HydraEngine *engine = GetEngine();
HydraPhysicsComponent phys_comp = {};
phys_comp.mass = 0;
phys_comp.phyics_type = HYDRA_PHYSICS_TYPE::HYDRA_STATIC_BODY;
phys_comp.physics_shape = HYDRA_PHYSICS_SHAPE::HYDRA_PHYSICS_BOX;
// HydraECS* ecs = GetEngine()->ECS();
phys_comp.depth = 1000.0f;
phys_comp.height = 1.0f;
phys_comp.width = 1000.0f;
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
engine->ECS()->AddComponent<HydraPhysicsComponent>(GetID(), phys_comp);
}
void HydraPlaneActor::_CreateRenderableComponent()
{
+11 -14
View File
@@ -7,6 +7,7 @@
#include "../ecs/components/HydraMeshComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraPhysicsComponent.h"
#include "../buffer/HydraMaterialBufferManager.h"
#include "../buffer/HydraTextureBufferManager.h"
#include "../buffer/HydraMaterialBuffer.h"
@@ -18,7 +19,7 @@ void HydraTestCubeActor::InitialiseComponents()
// HydraECS* ecs = GetEngine()->ECS();
// HydraID entity_id = ecs->CreateEntity();
_CreatePosition();
// _CreatePhysics();
_CreatePhysics();
_CreateMaterial();
_CreateMesh();
@@ -183,21 +184,17 @@ void HydraTestCubeActor::_CreateMaterial()
void HydraTestCubeActor::_CreatePhysics()
{
// HydraECSPhysicsComponent physics_component;
// physics_component.physics_state = Hydra_State::Waiting;
// physics_component.physics_definition.actor_id = GetID();
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
// physics_component.physics_definition.mass = 100000.0f;
// physics_component.physics_definition.extent_x = 1000.0f;
// physics_component.physics_definition.extent_y = 0.5f;
// physics_component.physics_definition.extent_z = 1000.0f;
// physics_component.physics_definition.dynamic_friction = 0.5f;
// physics_component.physics_definition.restitution = 0.5f;
HydraEngine *engine = GetEngine();
HydraPhysicsComponent phys_comp = {};
phys_comp.mass = 0;
phys_comp.phyics_type = HYDRA_PHYSICS_TYPE::HYDRA_RIGID_BODY;
phys_comp.physics_shape = HYDRA_PHYSICS_SHAPE::HYDRA_PHYSICS_BOX;
// HydraECS* ecs = GetEngine()->ECS();
phys_comp.depth = 1.0f;
phys_comp.height = 1.0f;
phys_comp.width = 1.0f;
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
engine->ECS()->AddComponent<HydraPhysicsComponent>(GetID(), phys_comp);
}
void HydraTestCubeActor::_CreateRenderableComponent()
{