Merge pull request #379 from SHADE-DP/SP3-141-Camera-System
Rotates target offset based on camera arm's rotation
This commit is contained in:
commit
dfd1f59b02
|
@ -1,6 +1,6 @@
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHCameraArmComponent.h"
|
#include "SHCameraArmComponent.h"
|
||||||
|
#include "Math/SHMathHelpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -16,6 +16,11 @@ namespace SHADE
|
||||||
|
|
||||||
SHVec3 const& SHCameraArmComponent::GetOffset() const noexcept
|
SHVec3 const& SHCameraArmComponent::GetOffset() const noexcept
|
||||||
{
|
{
|
||||||
|
SHVec3 result = offset;
|
||||||
|
|
||||||
|
result = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(GetPitch())));
|
||||||
|
result = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(GetYaw())));
|
||||||
|
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,11 +172,6 @@ namespace SHADE
|
||||||
|
|
||||||
void SHCameraSystem::UpdateCameraArmComponent(SHCameraArmComponent& pivot) noexcept
|
void SHCameraSystem::UpdateCameraArmComponent(SHCameraArmComponent& pivot) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SHVec3 offset{ 0.0f,0.0f, 1.0f };
|
SHVec3 offset{ 0.0f,0.0f, 1.0f };
|
||||||
offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch())));
|
offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch())));
|
||||||
offset = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(pivot.GetYaw())));
|
offset = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(pivot.GetYaw())));
|
||||||
|
@ -212,12 +207,18 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Camera Collision stuff
|
||||||
|
|
||||||
SHVec3 cameraPos = camera->position + pivot.offset;
|
SHVec3 cameraPos = camera->position + pivot.offset;
|
||||||
SHVec3 cameraTarget = camera->position;
|
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;
|
SHRaycaster::RaycastInfo info;
|
||||||
//info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask());
|
|
||||||
info.layers = (uint16_t)(SHCollisionTagMatrix::GetTag("Camera")->GetMask());
|
info.layers = (uint16_t)(SHCollisionTagMatrix::GetTag("Camera")->GetMask());
|
||||||
info.distance = pivot.armLength;
|
info.distance = pivot.armLength;
|
||||||
info.continuous = false;
|
info.continuous = false;
|
||||||
|
@ -235,38 +236,10 @@ namespace SHADE
|
||||||
newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw())));
|
newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw())));
|
||||||
newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance * 0.95f);
|
newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance * 0.95f);
|
||||||
pivot.offset = newOffset;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////auto result = physicsSystem->Raycast(pivot.ray);
|
|
||||||
//if (result && result.distance < pivot.GetArmLength())
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
// SHVec3 newOffset = SHVec3{ 0.0f,0.0f, result.distance * 0.8f };
|
|
||||||
// newOffset = SHVec3::RotateX(newOffset, -(SHMath::DegreesToRadians(pivot.GetPitch())));
|
|
||||||
// newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw())));
|
|
||||||
// pivot.offset = newOffset;
|
|
||||||
// //SHLOG_INFO("CAMERA COLLISION HIT, {}", result.distance);
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA");
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
// pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue