diff --git a/imgui.ini b/imgui.ini index 1e264a3..a2c5d73 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,6 +1,6 @@ [Window][WindowOverViewport_11111111] Pos=0,24 -Size=2552,1363 +Size=2560,1371 Collapsed=0 [Window][Debug##Default] @@ -10,31 +10,31 @@ Collapsed=0 [Window][Statistics] Pos=0,24 -Size=224,437 +Size=224,439 Collapsed=0 DockId=0x00000003,0 [Window][Properties] -Pos=2102,24 -Size=450,805 +Pos=2110,24 +Size=450,810 Collapsed=0 DockId=0x00000007,0 [Window][Viewport] Pos=226,61 -Size=1874,956 +Size=1882,964 Collapsed=0 DockId=0x00000012,0 [Window][Dear ImGui Demo] -Pos=2102,831 -Size=450,556 +Pos=2110,836 +Size=450,559 Collapsed=0 DockId=0x00000008,0 [Window][Scene] -Pos=0,463 -Size=224,924 +Pos=0,465 +Size=224,930 Collapsed=0 DockId=0x00000004,0 @@ -143,8 +143,8 @@ Collapsed=0 DockId=0x00000012,1 [Window][Assets] -Pos=226,1019 -Size=1874,368 +Pos=226,1027 +Size=1882,368 Collapsed=0 DockId=0x0000000C,0 @@ -156,12 +156,12 @@ DockId=0x0000000F,0 [Window][##play_state_bar] Pos=226,24 -Size=1874,35 +Size=1882,35 Collapsed=0 DockId=0x00000011,0 [Docking][Data] -DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=2552,1363 Split=X +DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=2560,1371 Split=X DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=820,1386 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=224,1386 Split=Y Selected=0xE601B12F DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,417 Selected=0x553E127E diff --git a/open_engine/include/open_engine/scene/components.hpp b/open_engine/include/open_engine/scene/components.hpp index a896b12..c99dbe9 100644 --- a/open_engine/include/open_engine/scene/components.hpp +++ b/open_engine/include/open_engine/scene/components.hpp @@ -119,17 +119,15 @@ namespace OpenEngine { struct PhysicsBodyComponent { - enum class BodyType { Static = 0, Kinematic, Dynamic }; - BodyID body; - BodyType type = BodyType::Dynamic; - float linear_damping = 0.05f; float angular_damping = 0.05f; float gravity_factor = 1.0f; + EMotionType type = EMotionType::Dynamic; EActivation initial_activation_state = EActivation::Activate; + ObjectLayer layer = Layers::MOVING; PhysicsBodyComponent() = default; PhysicsBodyComponent(const PhysicsBodyComponent&) = default; diff --git a/open_engine/src/open_engine/physics.cpp b/open_engine/src/open_engine/physics.cpp index 7fde043..c3de441 100644 --- a/open_engine/src/open_engine/physics.cpp +++ b/open_engine/src/open_engine/physics.cpp @@ -38,7 +38,9 @@ namespace OpenEngine { tmp_allocator = CreateRef(10 * 1024 * 1024); - job_system = CreateRef(cMaxPhysicsJobs, cMaxPhysicsBarriers, thread::hardware_concurrency() - 1); + job_system = CreateRef(cMaxPhysicsJobs, + cMaxPhysicsBarriers, + thread::hardware_concurrency() - 1); physics_system.Init( 1024, @@ -49,10 +51,10 @@ namespace OpenEngine { object_vs_broadphase_layer_filter, object_vs_object_layer_filter); - physics_system.SetBodyActivationListener(&body_activation_listener); - physics_system.SetContactListener(&contact_listener); + //physics_system.SetBodyActivationListener(&body_activation_listener); + //physics_system.SetContactListener(&contact_listener); - // TODO: Move out of here and check the comment on Jolt's example + // TODO: Check the comment on Jolt's example physics_system.OptimizeBroadPhase(); } diff --git a/open_engine/src/open_engine/scene/scene.cpp b/open_engine/src/open_engine/scene/scene.cpp index 626b18d..07d26d0 100755 --- a/open_engine/src/open_engine/scene/scene.cpp +++ b/open_engine/src/open_engine/scene/scene.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -36,34 +37,40 @@ namespace OpenEngine { // Add it to the world body_interface->AddBody(floor->GetID(), EActivation::DontActivate); - auto view = registry.view(); + // TODO: Cleanup components aquisition + auto view = registry.view(); for (auto e : view) { Entity entity = { e, this }; - TransformComponent* tc; - if (entity.HasComponent()) - tc = &entity.GetComponents(); auto& pbc = entity.GetComponents(); + auto& tc = entity.GetComponents(); - PhysicsShapeComponent* psc; + PhysicsShapeComponent* psc = nullptr; if (entity.HasComponent()) psc = &entity.GetComponents(); + + glm::vec3& pos = tc.translation; + glm::vec3& scale = tc.scale; + glm::vec3& rot = tc.rotation; - glm::vec3& pos = tc->translation; + Quat quat = Quat::sEulerAngles(Vec3(rot.x, rot.y, rot.z)); BodyCreationSettings settings( - new BoxShape(Vec3(0.5f, 0.5f, 0.5f)), + new BoxShape(Vec3(scale.x * 0.5, scale.y * 0.5f, scale.z * 0.5f)), Vec3(pos.x, pos.y, pos.z), - Quat::sIdentity(), - EMotionType::Dynamic, - Layers::MOVING); + quat, + pbc.type, + pbc.layer); + settings.mLinearDamping = pbc.linear_damping; settings.mAngularDamping = pbc.angular_damping; settings.mGravityFactor = pbc.gravity_factor; - settings.mRestitution = psc->restitution; - settings.mFriction = psc->friction; + if (psc != nullptr) { + settings.mRestitution = psc->restitution; + settings.mFriction = psc->friction; + } - pbc.body = body_interface->CreateAndAddBody(settings, EActivation::Activate); + pbc.body = body_interface->CreateAndAddBody(settings, pbc.initial_activation_state); } } @@ -75,8 +82,8 @@ namespace OpenEngine { auto& pbc = entity.GetComponents(); - physics_engine.GetBodyInterface().RemoveBody(pbc.body); - physics_engine.GetBodyInterface().DestroyBody(pbc.body); + body_interface->RemoveBody(pbc.body); + body_interface->DestroyBody(pbc.body); } } @@ -156,7 +163,6 @@ namespace OpenEngine { body_interface->SetRestitution(body.body, shape->restitution); body_interface->SetFriction(body.body, shape->friction); - body_interface->SetGravityFactor(body.body, body.gravity_factor); } } @@ -169,10 +175,17 @@ namespace OpenEngine { auto& transform = entity.GetComponents(); auto& body = entity.GetComponents(); - auto position = physics_engine.GetBodyInterface().GetPosition(body.body); + auto position = body_interface->GetPosition(body.body); + auto rotation = body_interface->GetRotation(body.body).GetEulerAngles(); transform.translation.x = position.GetX(); transform.translation.y = position.GetY(); transform.translation.z = position.GetZ(); + + transform.rotation.x = rotation.GetX(); + transform.rotation.y = rotation.GetY(); + transform.rotation.z = rotation.GetZ(); + + body_interface->SetGravityFactor(body.body, body.gravity_factor); } SceneCamera* main_camera = nullptr; @@ -194,16 +207,16 @@ namespace OpenEngine { auto view = registry.view(); - for (const auto& entity : view) { - auto [transform, mesh] = view.get(entity); + for (const auto& e : view) { + auto [transform, mesh] = view.get(e); - Material material; + Material* material; - Entity _entity(entity, this); - if (_entity.HasComponent()) - material = _entity.GetComponents().material; + Entity entity(e, this); + if (entity.HasComponent()) + material = &entity.GetComponents().material; - Renderer3D::DrawMesh(mesh.mesh, material, GetTransformFromComp(transform)); + Renderer3D::DrawMesh(mesh.mesh, *material, GetTransformFromComp(transform)); /* if (sprite.texture) Renderer2D::DrawQuad(GetTransformFromComp(transform),