Camera Collision fix. Still have some minor bugs #345

Merged
maverickdgg merged 8 commits from SP3-141-Camera-System into main 2023-02-04 02:39:55 +08:00
7 changed files with 245 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

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

View File

@ -0,0 +1,167 @@
[Window][MainStatusBar]
Pos=0,989
Size=2560,20
Collapsed=0
[Window][SHEditorMenuBar]
Pos=0,48
Size=2560,941
Collapsed=0
[Window][Hierarchy Panel]
Pos=0,187
Size=300,802
Collapsed=0
DockId=0x00000004,0
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Inspector]
Pos=2074,48
Size=486,941
Collapsed=0
DockId=0x00000006,0
[Window][Profiler]
Pos=0,48
Size=300,137
Collapsed=0
DockId=0x00000003,0
[Window][Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌð‡Žoû]
Pos=60,60
Size=32,64
Collapsed=0
[Window][ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ]
Pos=60,60
Size=999,581
Collapsed=0
[Window][ð‡]
Pos=60,60
Size=32,64
Collapsed=0
[Window][ÌÌÌÌ]
Pos=60,60
Size=553,422
Collapsed=0
[Window][]
Pos=60,60
Size=770,394
Collapsed=0
[Window][ Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][ Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][î<> Viewport]
Pos=302,48
Size=1770,705
Collapsed=0
DockId=0x0000000B,0
[Window][V]
Pos=310,722
Size=1501,338
Collapsed=0
DockId=0x00000008,0
[Window][p£€Ê]
Pos=310,750
Size=1501,310
Collapsed=0
DockId=0x0000000A,0
[Window][ Asset Browser]
Pos=302,755
Size=1770,234
Collapsed=0
DockId=0x0000000C,0
[Window][Material Inspector]
Pos=2074,48
Size=486,941
Collapsed=0
DockId=0x00000006,1
[Window][Save scene as...]
Pos=1197,693
Size=165,120
Collapsed=0
[Window][Create New Asset]
Pos=896,472
Size=464,144
Collapsed=0
[Window][Collider Tag Panel]
Pos=302,48
Size=1770,705
Collapsed=0
DockId=0x0000000B,1
[Window][Input Bindings Panel]
Pos=2074,48
Size=486,941
Collapsed=0
DockId=0x00000006,2
[Window][Save Scene As]
Pos=877,444
Size=165,120
Collapsed=0
[Table][0x9D40AE32,17]
Column 0 Weight=1.0696
Column 1 Weight=0.9194
Column 2 Weight=0.9945
Column 3 Weight=1.0320
Column 4 Weight=0.9570
Column 5 Weight=0.9945
Column 6 Weight=0.9945
Column 7 Weight=0.9945
Column 8 Weight=0.9945
Column 9 Weight=1.0320
Column 10 Weight=0.9570
Column 11 Weight=1.0133
Column 12 Weight=0.9945
Column 13 Weight=0.8444
Column 14 Weight=0.9945
Column 15 Weight=0.8632
Column 16 Weight=1.3510
[Docking][Data]
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
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,863 Selected=0xE096E5AE
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=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=0xE7039252

View File

@ -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
@ -9627,8 +9627,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:
@ -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
@ -9701,7 +9701,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
@ -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,12 +9727,12 @@
Scripts:
- Type: SHADE_Scripting.ThirdPersonCamera
Enabled: true
armLength: 1
armLength: 3
turnSpeedPitch: 0.300000012
turnSpeedYaw: 0.5
pitchClamp: 45
inverseXControls: true
inverseYControls: true
inverseXControls: false
inverseYControls: false
- EID: 9
Name: PlayerBag
IsActive: true

View File

@ -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<SHTransformComponent>(camera->GetEID()) == true && camera != &editorCamera)
if (SHComponentManager::HasComponent<SHTransformComponent>(camera->GetEID()) == true && camera != &editorCamera)
{
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(camera->GetEID());
SHVec3 rotation = transform->GetWorldRotation();
@ -174,14 +174,47 @@ 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)(SHCollisionTagMatrix::GetTag("Camera")->GetMask());
info.distance = pivot.armLength;
info.continuous = false;
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 * 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);
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;
}
}
////auto result = physicsSystem->Raycast(pivot.ray);
//if (result && result.distance < pivot.GetArmLength())
//{
//
@ -196,8 +229,6 @@ namespace SHADE
// //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA");
//}
//
//
// pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix);
@ -234,7 +265,8 @@ namespace SHADE
{
camera.offset = arm->GetOffset();
if (arm->lookAtCameraOrigin)
CameraLookAt(camera, camera.position + arm->GetTargetOffset());
CameraLookAt(camera, camera.position);
}
}
@ -418,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;
@ -441,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;
}
@ -457,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;
@ -499,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

View File

@ -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;