From c88ce23d45d3535958d42f899312d3345246569c Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sat, 4 Feb 2023 00:17:29 +0800 Subject: [PATCH 1/3] WIP collision --- Assets/Application.SHConfig | 2 +- Assets/CollisionTags.SHConfig | 4 +- Assets/Editor/Editor.SHConfig | 2 +- Assets/Editor/Layouts/UserLayout.ini | 26 ++--- Assets/Materials/UIMat.shmat | 2 +- Assets/Scenes/MainGame.shade | 94 +++++++++---------- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 51 +++++++--- .../src/ECS_Base/Managers/SHSystemManager.h | 2 +- 8 files changed, 105 insertions(+), 78 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 61857f68..370665d2 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 97086054 +Starting Scene ID: 86098106 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/CollisionTags.SHConfig b/Assets/CollisionTags.SHConfig index f29443f5..cea40d35 100644 --- a/Assets/CollisionTags.SHConfig +++ b/Assets/CollisionTags.SHConfig @@ -1,10 +1,10 @@ -0 1 3 +0 1 67 1 2 65535 2 3 65534 3 4 65534 4 5 65534 5 6 65534 -6 7 65534 +6 7 65535 7 8 65534 8 9 65534 9 10 65534 diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig index 7a7c92f8..dc5101ee 100644 --- a/Assets/Editor/Editor.SHConfig +++ b/Assets/Editor/Editor.SHConfig @@ -1,4 +1,4 @@ Start Maximized: true -Working Scene ID: 97086054 +Working Scene ID: 87244611 Window Size: {x: 1920, y: 1013} Style: 0 \ No newline at end of file diff --git a/Assets/Editor/Layouts/UserLayout.ini b/Assets/Editor/Layouts/UserLayout.ini index 9a8687ca..769206d3 100644 --- a/Assets/Editor/Layouts/UserLayout.ini +++ b/Assets/Editor/Layouts/UserLayout.ini @@ -1,16 +1,16 @@ [Window][MainStatusBar] -Pos=0,989 +Pos=0,981 Size=1920,20 Collapsed=0 [Window][SHEditorMenuBar] Pos=0,48 -Size=1920,941 +Size=1920,933 Collapsed=0 [Window][Hierarchy Panel] -Pos=0,187 -Size=300,802 +Pos=0,186 +Size=300,795 Collapsed=0 DockId=0x00000004,0 @@ -21,13 +21,13 @@ Collapsed=0 [Window][Inspector] Pos=1434,48 -Size=486,941 +Size=486,933 Collapsed=0 DockId=0x00000006,0 [Window][Profiler] Pos=0,48 -Size=300,137 +Size=300,136 Collapsed=0 DockId=0x00000003,0 @@ -76,7 +76,7 @@ DockId=0x0000000B,0 [Window][ Viewport] Pos=302,48 -Size=1130,705 +Size=1130,697 Collapsed=0 DockId=0x0000000B,0 @@ -93,14 +93,14 @@ Collapsed=0 DockId=0x0000000A,0 [Window][ Asset Browser] -Pos=302,755 +Pos=302,747 Size=1130,234 Collapsed=0 DockId=0x0000000C,0 [Window][Material Inspector] Pos=1434,48 -Size=486,941 +Size=486,933 Collapsed=0 DockId=0x00000006,1 @@ -116,13 +116,13 @@ Collapsed=0 [Window][Collider Tag Panel] Pos=302,48 -Size=1130,705 +Size=1130,697 Collapsed=0 DockId=0x0000000B,1 [Window][Input Bindings Panel] Pos=1434,48 -Size=486,941 +Size=486,933 Collapsed=0 DockId=0x00000006,2 @@ -151,7 +151,7 @@ Column 15 Weight=1.2009 Column 16 Weight=1.0132 [Docking][Data] -DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split=X +DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,77 Size=1920,933 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881 @@ -163,5 +163,5 @@ DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,234 Selected=0xB128252A DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6 DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=486,1036 Selected=0xE7039252 + DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=486,1036 Selected=0xD3697FB6 diff --git a/Assets/Materials/UIMat.shmat b/Assets/Materials/UIMat.shmat index 625021b0..0ca4c7a1 100644 --- a/Assets/Materials/UIMat.shmat +++ b/Assets/Materials/UIMat.shmat @@ -1,6 +1,6 @@ - VertexShader: 46580970 FragmentShader: 35983630 - SubPass: G-Buffer Write + SubPass: UI Properties: data.color: {x: 1, y: 1, z: 1, w: 1} data.textureIndex: 54429632 diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index c55d16ca..116075d2 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8486,7 +8486,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8533,7 +8533,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8580,7 +8580,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8627,7 +8627,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8674,7 +8674,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8721,7 +8721,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8768,7 +8768,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8815,7 +8815,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8862,7 +8862,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8909,7 +8909,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -8960,7 +8960,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9007,7 +9007,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9054,7 +9054,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9101,7 +9101,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9148,7 +9148,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9195,7 +9195,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9246,7 +9246,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9287,7 +9287,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9328,7 +9328,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9369,7 +9369,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9410,9 +9410,9 @@ Scale: {x: 1, y: 1, z: 1} IsActive: true RigidBody Component: - Type: Static + Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9449,9 +9449,9 @@ Scale: {x: 1, y: 1, z: 1} IsActive: true RigidBody Component: - Type: Static + Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9541,8 +9541,8 @@ NumberOfChildren: 3 Components: Transform Component: - Translate: {x: 2.12735963, y: 0.362327814, z: 6.98932981} - Rotate: {x: 0, y: 0, z: 0} + Translate: {x: 2.35245037, y: 0.38365531, z: 7.10571432} + Rotate: {x: -0, y: 0, z: -0} Scale: {x: 0.999999881, y: 1, z: 0.999999881} IsActive: true Renderable Component: @@ -9551,7 +9551,7 @@ IsActive: true RigidBody Component: Type: Dynamic - Drag: 1 + Drag: 0.00999999978 Angular Drag: 0.100000001 Use Gravity: false Interpolate: true @@ -9615,7 +9615,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: -2.98023224e-08, z: 4.76837158e-07} + Translate: {x: 0, y: -5.96046448e-08, z: 0} Rotate: {x: 0, y: 6.28318548, z: 2.23517329e-08} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -9645,8 +9645,8 @@ turnSpeedPitch: 0.300000012 turnSpeedYaw: 0.5 pitchClamp: 45 - inverseXControls: true - inverseYControls: true + inverseXControls: false + inverseYControls: false - EID: 9 Name: PlayerBag IsActive: true @@ -9696,7 +9696,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9741,7 +9741,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9782,7 +9782,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9823,7 +9823,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9864,7 +9864,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9905,7 +9905,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9950,7 +9950,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -9991,7 +9991,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10032,7 +10032,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10073,7 +10073,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10114,7 +10114,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10159,7 +10159,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10200,7 +10200,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10241,7 +10241,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10282,7 +10282,7 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true Interpolate: true Sleeping Enabled: true @@ -10406,9 +10406,9 @@ RigidBody Component: Type: Dynamic Drag: 0.00999999978 - Angular Drag: 0.00999999978 + Angular Drag: 0.100000001 Use Gravity: true - Interpolate: false + Interpolate: true Sleeping Enabled: true Freeze Position X: false Freeze Position Y: false diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 297e03b8..a6b04773 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -142,10 +142,10 @@ namespace SHADE - SHVec3 offset{ 0.0f,0.0f, pivot.GetArmLength() }; + SHVec3 offset{ 0.0f,0.0f, 1.0f }; offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); offset = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(pivot.GetYaw()))); - + offset = SHVec3::Normalise(offset) * pivot.armLength; //pivot.rtMatrix = SHMatrix::RotateX(SHMath::DegreesToRadians(pivot.GetPitch())) // * SHMatrix::RotateY(SHMath::DegreesToRadians(pivot.GetYaw())) @@ -165,7 +165,7 @@ namespace SHADE return; - /*if (SHComponentManager::HasComponent(camera->GetEID()) == true && camera != &editorCamera) + if (SHComponentManager::HasComponent(camera->GetEID()) == true && camera != &editorCamera) { auto transform = SHComponentManager::GetComponent(camera->GetEID()); SHVec3 rotation = transform->GetWorldRotation(); @@ -174,14 +174,43 @@ namespace SHADE camera->roll = SHMath::RadiansToDegrees(rotation.z); camera->position = transform->GetWorldPosition(); camera->dirtyView = true; - }*/ - - pivot.ray.position = camera->GetPosition() + pivot.targetOffset; - pivot.ray.direction = SHVec3::Normalise((camera->position + offset)- pivot.ray.position); + } - //SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z) - //auto result = physicsSystem->Raycast(pivot.ray); + SHVec3 cameraPos = camera->position + pivot.offset; + SHVec3 cameraTarget = camera->position; + + //SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z) + SHRaycaster::RaycastInfo info; + //info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask()); + info.layers = (uint16_t)(SHCollisionTag::Layer::ALL); + info.distance = 1000000.0f; + info.continuous = true; + info.ray.position = cameraTarget; + info.SetColliderID(2); + info.ray.direction = SHVec3::Normalise(cameraPos - cameraTarget); + auto result = physicsSystem->Raycast(info); + for (auto hitResult : result) + { + if (hitResult.distance < pivot.armLength) + { + + SHVec3 newOffset{ 0.0f,0.0f, 1.0f }; + newOffset = SHVec3::RotateX(newOffset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); + newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw()))); + newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance); + pivot.offset = newOffset; + cameraPos = camera->position + pivot.offset; + SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length()); + break; + } + } + + + + + + ////auto result = physicsSystem->Raycast(pivot.ray); //if (result && result.distance < pivot.GetArmLength()) //{ // @@ -196,8 +225,6 @@ namespace SHADE // //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA"); //} - // - // // pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix); @@ -234,7 +261,7 @@ namespace SHADE { camera.offset = arm->GetOffset(); if (arm->lookAtCameraOrigin) - CameraLookAt(camera, camera.position + arm->GetTargetOffset()); + CameraLookAt(camera, camera.position); } } diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h index 995a1cf5..280dee88 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h @@ -94,7 +94,7 @@ namespace SHADE if (systemContainer.find(id) == systemContainer.end()) { - std::cout << "System Manager error: System Version " << version << " does not exit." << std::endl; + std::cout << "System Manager error: System Version "<< typeid(T).name()<<" " << version << " does not exist." << std::endl; return nullptr; } -- 2.40.1 From 94fe055aa99bd65f857062a884b6c05985b99816 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sat, 4 Feb 2023 02:10:08 +0800 Subject: [PATCH 2/3] fixed collision --- Assets/Editor/Editor.SHConfig | 2 +- Assets/Editor/Layouts/UserLayout.ini | 38 +++++++++++----------- Assets/Scenes/MainGame.shade | 4 +-- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 38 +++++++++++++--------- SHADE_Engine/src/Camera/SHCameraSystem.h | 4 +-- 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig index fb0d85dd..9bd51ca8 100644 --- a/Assets/Editor/Editor.SHConfig +++ b/Assets/Editor/Editor.SHConfig @@ -1,4 +1,4 @@ Start Maximized: true -Working Scene ID: 91685359 +Working Scene ID: 86098106 Window Size: {x: 1920, y: 1013} Style: 0 \ No newline at end of file diff --git a/Assets/Editor/Layouts/UserLayout.ini b/Assets/Editor/Layouts/UserLayout.ini index 35170297..781f61c0 100644 --- a/Assets/Editor/Layouts/UserLayout.ini +++ b/Assets/Editor/Layouts/UserLayout.ini @@ -1,16 +1,16 @@ [Window][MainStatusBar] -Pos=0,981 -Size=1920,20 +Pos=0,989 +Size=2560,20 Collapsed=0 [Window][SHEditorMenuBar] Pos=0,48 -Size=1920,933 +Size=2560,941 Collapsed=0 [Window][Hierarchy Panel] -Pos=0,186 -Size=300,795 +Pos=0,187 +Size=300,802 Collapsed=0 DockId=0x00000004,0 @@ -20,14 +20,14 @@ Size=400,400 Collapsed=0 [Window][Inspector] -Pos=1434,48 -Size=486,933 +Pos=2074,48 +Size=486,941 Collapsed=0 DockId=0x00000006,0 [Window][Profiler] Pos=0,48 -Size=300,136 +Size=300,137 Collapsed=0 DockId=0x00000003,0 @@ -76,7 +76,7 @@ DockId=0x0000000B,0 [Window][ Viewport] Pos=302,48 -Size=1130,697 +Size=1770,705 Collapsed=0 DockId=0x0000000B,0 @@ -93,14 +93,14 @@ Collapsed=0 DockId=0x0000000A,0 [Window][ Asset Browser] -Pos=302,747 -Size=1130,234 +Pos=302,755 +Size=1770,234 Collapsed=0 DockId=0x0000000C,0 [Window][Material Inspector] -Pos=1434,48 -Size=486,933 +Pos=2074,48 +Size=486,941 Collapsed=0 DockId=0x00000006,1 @@ -116,13 +116,13 @@ Collapsed=0 [Window][Collider Tag Panel] Pos=302,48 -Size=1130,697 +Size=1770,705 Collapsed=0 DockId=0x0000000B,1 [Window][Input Bindings Panel] -Pos=1434,48 -Size=486,933 +Pos=2074,48 +Size=486,941 Collapsed=0 DockId=0x00000006,2 @@ -151,7 +151,7 @@ Column 15 Weight=0.8632 Column 16 Weight=1.3510 [Docking][Data] -DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,77 Size=1920,933 Split=X +DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=2560,941 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881 @@ -159,9 +159,9 @@ DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,77 Size=1920,933 Split DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1130,1036 Split=Y Selected=0xB41284E7 DockNode ID=0x00000007 Parent=0x00000002 SizeRef=1501,672 Split=Y Selected=0xB41284E7 DockNode ID=0x00000009 Parent=0x00000007 SizeRef=1501,700 Split=Y Selected=0xB41284E7 - DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,705 CentralNode=1 Selected=0x69428B24 + DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,705 CentralNode=1 Selected=0xB41284E7 DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,234 Selected=0xB128252A DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6 DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=486,1036 Selected=0xD3697FB6 + DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=486,1036 Selected=0xE7039252 diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index cf44b840..6fdb93d9 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -9719,7 +9719,7 @@ Camera Arm Component: Arm Pitch: 0 Arm Yaw: 0 - Arm Length: 1 + Arm Length: 3 Look At Camera Origin: true Target Offset: {x: 0, y: 0, z: 0} Camera Collision: true @@ -9727,7 +9727,7 @@ Scripts: - Type: SHADE_Scripting.ThirdPersonCamera Enabled: true - armLength: 1 + armLength: 3 turnSpeedPitch: 0.300000012 turnSpeedYaw: 0.5 pitchClamp: 45 diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index a6b04773..29d9b19c 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -185,7 +185,7 @@ namespace SHADE //info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask()); info.layers = (uint16_t)(SHCollisionTag::Layer::ALL); info.distance = 1000000.0f; - info.continuous = true; + info.continuous = false; info.ray.position = cameraTarget; info.SetColliderID(2); info.ray.direction = SHVec3::Normalise(cameraPos - cameraTarget); @@ -200,15 +200,19 @@ namespace SHADE newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw()))); newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance); pivot.offset = newOffset; - cameraPos = camera->position + pivot.offset; - SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length()); + //cameraPos = camera->position + pivot.offset; + //SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length()); + //SHLOG_INFO("Racoon Position {}, {}, {}, Camera Position: {}, {}, {}, Distance {}", cameraTarget.x, cameraTarget.y, cameraTarget.z, cameraPos.x, cameraPos.y, cameraPos.z, SHVec3::Distance(cameraTarget, cameraPos)); + SHLOG_INFO("Camera Position: {}, {}, {}", cameraPos.x, cameraPos.y, cameraPos.z); + auto otherTransform = SHComponentManager::GetComponent_s(hitResult.entityHit); + SHVec3 otherPos = hitResult.position; + + + + //SHLOG_INFO("hit distance{} other pos: {},{},{}, distance between: {}", hitResult.distance, otherPos.x, otherPos.y, otherPos.z, SHVec3::Distance(cameraTarget,otherPos)); break; } } - - - - ////auto result = physicsSystem->Raycast(pivot.ray); //if (result && result.distance < pivot.GetArmLength()) @@ -262,6 +266,7 @@ namespace SHADE camera.offset = arm->GetOffset(); if (arm->lookAtCameraOrigin) CameraLookAt(camera, camera.position); + } } @@ -445,7 +450,7 @@ namespace SHADE } } - void SHCameraSystem::DecomposeViewMatrix(SHMatrix const& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept + void SHCameraSystem::DecomposeViewMatrix(SHMatrix const& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos, bool takePos) noexcept { float initPitch = pitch; @@ -468,15 +473,18 @@ namespace SHADE mtx = SHMatrix::Inverse(mtx); SHVec4 translate = mtx* dotPos; - pos.x = translate.x; - pos.y = translate.y; - pos.z = translate.z; + if (takePos) + { + pos.x = translate.x; + pos.y = translate.y; + pos.z = translate.z; + } } - void SHCameraSystem::SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept + void SHCameraSystem::SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept { SHVec3 pos; - DecomposeViewMatrix(viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position); + DecomposeViewMatrix(viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position, takePos); camera.dirtyView = true; } @@ -484,7 +492,7 @@ namespace SHADE void SHCameraSystem::CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept { - if (camera.position == target) + if (camera.position + camera.offset == target) { //lets off set it abit so the view is nt fked target.z -= 0.0001f; @@ -526,7 +534,7 @@ namespace SHADE viewMtx(2, 3) = -forward.Dot(camera.position + camera.offset); - SetCameraViewMatrix(camera, viewMtx); + SetCameraViewMatrix(camera, viewMtx,false); } SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index db680adb..baf0ed09 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -54,8 +54,8 @@ namespace SHADE void ClampCameraRotation(SHCameraComponent& camera) noexcept; void UpdateEditorCamera(double dt) noexcept; void SetMainCamera(EntityID eid, size_t directorIndex) noexcept; - void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; - void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; + void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos, bool takePos) noexcept; + void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; -- 2.40.1 From c5296db6f6f90b6d5d93db16226a4781e760d789 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sat, 4 Feb 2023 02:20:42 +0800 Subject: [PATCH 3/3] Camera Collision fix --- Assets/CollisionTags.SHConfig | 4 ++-- Assets/Scenes/MainGame.shade | 20 ++++++++++---------- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Assets/CollisionTags.SHConfig b/Assets/CollisionTags.SHConfig index 6181419b..9390b383 100644 --- a/Assets/CollisionTags.SHConfig +++ b/Assets/CollisionTags.SHConfig @@ -1,10 +1,10 @@ -0 StaticObject 1100000000000000 +0 StaticObject 1110000000000000 1 Player 1100000000000000 2 Food 1000000000000000 3 Breakable 1100000000000000 4 ScoringWallCollider 0100000000000000 5 Homeowner 1100000000000000 -6 Camera 1100000000000000 +6 Camera 0010000000000000 7 8 0000000000000000 8 9 0000000000000000 9 10 0000000000000000 diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 2264f610..5336f881 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8994,7 +8994,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box Half Extents: {x: 0.25, y: 0.25, z: 0.100000001} Friction: 0.400000006 @@ -9041,7 +9041,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box Half Extents: {x: 0.300000012, y: 0.200000003, z: 0.200000003} Friction: 0.400000006 @@ -9088,7 +9088,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box Half Extents: {x: 0.200000003, y: 0.0799999982, z: 0.200000003} Friction: 0.400000006 @@ -9135,7 +9135,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box Half Extents: {x: 0.200000003, y: 0.0500000007, z: 0.200000003} Friction: 0.400000006 @@ -9182,7 +9182,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box Half Extents: {x: 0.25, y: 0.0500000007, z: 0.200000003} Friction: 0.400000006 @@ -9281,7 +9281,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 3 Type: Box Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007} Friction: 0.400000006 @@ -9322,7 +9322,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 3 Type: Box Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007} Friction: 0.400000006 @@ -9363,7 +9363,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 3 Type: Box Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007} Friction: 0.400000006 @@ -9404,7 +9404,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 3 Type: Box Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007} Friction: 0.400000006 @@ -9681,7 +9681,7 @@ throwForce: [8, 10, 8] cameraArmOffSet: [0, 0.25, 0] delayTimer: 1 - aimingLength: 0.5 + aimingLength: 1 throwItem: false rayDistance: 0.5 - EID: 3 diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 29d9b19c..6ebbd078 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -183,8 +183,8 @@ namespace SHADE //SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z) SHRaycaster::RaycastInfo info; //info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask()); - info.layers = (uint16_t)(SHCollisionTag::Layer::ALL); - info.distance = 1000000.0f; + info.layers = (uint16_t)(SHCollisionTagMatrix::GetTag("Camera")->GetMask()); + info.distance = pivot.armLength; info.continuous = false; info.ray.position = cameraTarget; info.SetColliderID(2); @@ -198,12 +198,12 @@ namespace SHADE SHVec3 newOffset{ 0.0f,0.0f, 1.0f }; newOffset = SHVec3::RotateX(newOffset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw()))); - newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance); + newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance * 0.95f); pivot.offset = newOffset; //cameraPos = camera->position + pivot.offset; //SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length()); //SHLOG_INFO("Racoon Position {}, {}, {}, Camera Position: {}, {}, {}, Distance {}", cameraTarget.x, cameraTarget.y, cameraTarget.z, cameraPos.x, cameraPos.y, cameraPos.z, SHVec3::Distance(cameraTarget, cameraPos)); - SHLOG_INFO("Camera Position: {}, {}, {}", cameraPos.x, cameraPos.y, cameraPos.z); + //SHLOG_INFO("Camera Position: {}, {}, {}", cameraPos.x, cameraPos.y, cameraPos.z); auto otherTransform = SHComponentManager::GetComponent_s(hitResult.entityHit); SHVec3 otherPos = hitResult.position; -- 2.40.1