fixed collision

This commit is contained in:
maverickdgg 2023-02-04 02:10:08 +08:00
parent 44e28f0d3f
commit 94fe055aa9
5 changed files with 47 additions and 39 deletions

View File

@ -1,4 +1,4 @@
Start Maximized: true Start Maximized: true
Working Scene ID: 91685359 Working Scene ID: 86098106
Window Size: {x: 1920, y: 1013} Window Size: {x: 1920, y: 1013}
Style: 0 Style: 0

View File

@ -1,16 +1,16 @@
[Window][MainStatusBar] [Window][MainStatusBar]
Pos=0,981 Pos=0,989
Size=1920,20 Size=2560,20
Collapsed=0 Collapsed=0
[Window][SHEditorMenuBar] [Window][SHEditorMenuBar]
Pos=0,48 Pos=0,48
Size=1920,933 Size=2560,941
Collapsed=0 Collapsed=0
[Window][Hierarchy Panel] [Window][Hierarchy Panel]
Pos=0,186 Pos=0,187
Size=300,795 Size=300,802
Collapsed=0 Collapsed=0
DockId=0x00000004,0 DockId=0x00000004,0
@ -20,14 +20,14 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Inspector] [Window][Inspector]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Window][Profiler] [Window][Profiler]
Pos=0,48 Pos=0,48
Size=300,136 Size=300,137
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000003,0
@ -76,7 +76,7 @@ DockId=0x0000000B,0
[Window][ Viewport] [Window][ Viewport]
Pos=302,48 Pos=302,48
Size=1130,697 Size=1770,705
Collapsed=0 Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
@ -93,14 +93,14 @@ Collapsed=0
DockId=0x0000000A,0 DockId=0x0000000A,0
[Window][ Asset Browser] [Window][ Asset Browser]
Pos=302,747 Pos=302,755
Size=1130,234 Size=1770,234
Collapsed=0 Collapsed=0
DockId=0x0000000C,0 DockId=0x0000000C,0
[Window][Material Inspector] [Window][Material Inspector]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,1 DockId=0x00000006,1
@ -116,13 +116,13 @@ Collapsed=0
[Window][Collider Tag Panel] [Window][Collider Tag Panel]
Pos=302,48 Pos=302,48
Size=1130,697 Size=1770,705
Collapsed=0 Collapsed=0
DockId=0x0000000B,1 DockId=0x0000000B,1
[Window][Input Bindings Panel] [Window][Input Bindings Panel]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,2 DockId=0x00000006,2
@ -151,7 +151,7 @@ Column 15 Weight=0.8632
Column 16 Weight=1.3510 Column 16 Weight=1.3510
[Docking][Data] [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=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 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=0x00000002 Parent=0x00000005 SizeRef=1130,1036 Split=Y Selected=0xB41284E7
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=1501,672 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=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=0x0000000C Parent=0x00000009 SizeRef=1501,234 Selected=0xB128252A
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6 DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532 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

View File

@ -9719,7 +9719,7 @@
Camera Arm Component: Camera Arm Component:
Arm Pitch: 0 Arm Pitch: 0
Arm Yaw: 0 Arm Yaw: 0
Arm Length: 1 Arm Length: 3
Look At Camera Origin: true Look At Camera Origin: true
Target Offset: {x: 0, y: 0, z: 0} Target Offset: {x: 0, y: 0, z: 0}
Camera Collision: true Camera Collision: true
@ -9727,7 +9727,7 @@
Scripts: Scripts:
- Type: SHADE_Scripting.ThirdPersonCamera - Type: SHADE_Scripting.ThirdPersonCamera
Enabled: true Enabled: true
armLength: 1 armLength: 3
turnSpeedPitch: 0.300000012 turnSpeedPitch: 0.300000012
turnSpeedYaw: 0.5 turnSpeedYaw: 0.5
pitchClamp: 45 pitchClamp: 45

View File

@ -185,7 +185,7 @@ namespace SHADE
//info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask()); //info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask());
info.layers = (uint16_t)(SHCollisionTag::Layer::ALL); info.layers = (uint16_t)(SHCollisionTag::Layer::ALL);
info.distance = 1000000.0f; info.distance = 1000000.0f;
info.continuous = true; info.continuous = false;
info.ray.position = cameraTarget; info.ray.position = cameraTarget;
info.SetColliderID(2); info.SetColliderID(2);
info.ray.direction = SHVec3::Normalise(cameraPos - cameraTarget); info.ray.direction = SHVec3::Normalise(cameraPos - cameraTarget);
@ -200,16 +200,20 @@ namespace SHADE
newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw()))); newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw())));
newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance); newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance);
pivot.offset = newOffset; pivot.offset = newOffset;
cameraPos = camera->position + pivot.offset; //cameraPos = camera->position + pivot.offset;
SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length()); //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<SHTransformComponent>(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; break;
} }
} }
////auto result = physicsSystem->Raycast(pivot.ray); ////auto result = physicsSystem->Raycast(pivot.ray);
//if (result && result.distance < pivot.GetArmLength()) //if (result && result.distance < pivot.GetArmLength())
//{ //{
@ -262,6 +266,7 @@ namespace SHADE
camera.offset = arm->GetOffset(); camera.offset = arm->GetOffset();
if (arm->lookAtCameraOrigin) if (arm->lookAtCameraOrigin)
CameraLookAt(camera, camera.position); 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; float initPitch = pitch;
@ -468,15 +473,18 @@ namespace SHADE
mtx = SHMatrix::Inverse(mtx); mtx = SHMatrix::Inverse(mtx);
SHVec4 translate = mtx* dotPos; SHVec4 translate = mtx* dotPos;
if (takePos)
{
pos.x = translate.x; pos.x = translate.x;
pos.y = translate.y; pos.y = translate.y;
pos.z = translate.z; 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; 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; camera.dirtyView = true;
} }
@ -484,7 +492,7 @@ namespace SHADE
void SHCameraSystem::CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept 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 //lets off set it abit so the view is nt fked
target.z -= 0.0001f; target.z -= 0.0001f;
@ -526,7 +534,7 @@ namespace SHADE
viewMtx(2, 3) = -forward.Dot(camera.position + camera.offset); viewMtx(2, 3) = -forward.Dot(camera.position + camera.offset);
SetCameraViewMatrix(camera, viewMtx); SetCameraViewMatrix(camera, viewMtx,false);
} }
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept

View File

@ -54,8 +54,8 @@ namespace SHADE
void ClampCameraRotation(SHCameraComponent& camera) noexcept; void ClampCameraRotation(SHCameraComponent& camera) noexcept;
void UpdateEditorCamera(double dt) noexcept; void UpdateEditorCamera(double dt) noexcept;
void SetMainCamera(EntityID eid, size_t directorIndex) noexcept; void SetMainCamera(EntityID eid, size_t directorIndex) noexcept;
void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos, bool takePos) noexcept;
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;