Camera Component, Editor Viewport Widget refactoring.

- Handle changing of active camera entirely inside CameraComponentController
- Remove a LOT of legacy Cry things related to cameras
- Add a CameraSystemComponent to handle ActiveCameraRequestBus and CameraSystemRequestBus

Signed-off-by: Yuriy Toporovskyy <toporovskyy.y@gmail.com>
This commit is contained in:
Yuriy Toporovskyy
2021-08-04 10:39:57 -04:00
parent 6d2765ef42
commit 73fee0c57e
47 changed files with 1126 additions and 6046 deletions
@@ -58,10 +58,10 @@ DebugCamera::~DebugCamera()
///////////////////////////////////////////////////////////////////////////////
void DebugCamera::OnEnable()
{
m_position = gEnv->pSystem->GetViewCamera().GetPosition();
m_position = Vec3_Zero; // gEnv->pSystem->GetViewCamera().GetPosition();
m_moveInput = Vec3_Zero;
Ang3 cameraAngles = Ang3(gEnv->pSystem->GetViewCamera().GetMatrix());
Ang3 cameraAngles = Ang3(ZERO); // Ang3(gEnv->pSystem->GetViewCamera().GetMatrix());
m_cameraYaw = RAD2DEG(cameraAngles.z);
m_cameraPitch = RAD2DEG(cameraAngles.x);
m_view = Matrix33(Ang3(DEG2RAD(m_cameraPitch), 0.0f, DEG2RAD(m_cameraYaw)));
@@ -126,13 +126,13 @@ void DebugCamera::Update()
///////////////////////////////////////////////////////////////////////////////
void DebugCamera::PostUpdate()
{
if (m_cameraMode == DebugCamera::ModeOff)
{
return;
}
//if (m_cameraMode == DebugCamera::ModeOff)
//{
// return;
//}
CCamera& camera = gEnv->pSystem->GetViewCamera();
camera.SetMatrix(Matrix34(m_view, m_position));
//CCamera& camera = gEnv->pSystem->GetViewCamera();
//camera.SetMatrix(Matrix34(m_view, m_position));
}
///////////////////////////////////////////////////////////////////////////////
+58 -56
View File
@@ -57,77 +57,79 @@ void CView::Release()
//------------------------------------------------------------------------
void CView::Update(float frameTime, bool isActive)
{
//FIXME:some cameras may need to be updated always
if (!isActive)
{
return;
}
(void)(frameTime, isActive);
AZ_ErrorOnce("CryLegacy", false, "CryLegacy view system no longer available (CView::Update)");
////FIXME:some cameras may need to be updated always
//if (!isActive)
//{
// return;
//}
if (m_azEntity)
{
m_viewParams.SaveLast();
//if (m_azEntity)
//{
// m_viewParams.SaveLast();
CCamera* pSysCam = &m_pSystem->GetViewCamera();
// CCamera* pSysCam = &m_pSystem->GetViewCamera();
//process screen shaking
ProcessShaking(frameTime);
// //process screen shaking
// ProcessShaking(frameTime);
//FIXME:to let the updateView implementation use the correct shakeVector
m_viewParams.currentShakeShift = m_viewParams.rotation * m_viewParams.currentShakeShift;
// //FIXME:to let the updateView implementation use the correct shakeVector
// m_viewParams.currentShakeShift = m_viewParams.rotation * m_viewParams.currentShakeShift;
m_viewParams.frameTime = frameTime;
//update view position/rotation
if (m_azEntity != nullptr)
{
auto entityTransform = m_azEntity->GetTransform();
if (entityTransform != nullptr)
{
AZ::Transform transform = entityTransform->GetWorldTM();
m_viewParams.position = AZVec3ToLYVec3(transform.GetTranslation());
m_viewParams.rotation = AZQuaternionToLYQuaternion(transform.GetRotation());
}
}
// m_viewParams.frameTime = frameTime;
// //update view position/rotation
// if (m_azEntity != nullptr)
// {
// auto entityTransform = m_azEntity->GetTransform();
// if (entityTransform != nullptr)
// {
// AZ::Transform transform = entityTransform->GetWorldTM();
// m_viewParams.position = AZVec3ToLYVec3(transform.GetTranslation());
// m_viewParams.rotation = AZQuaternionToLYQuaternion(transform.GetRotation());
// }
// }
ApplyFrameAdditiveAngles(m_viewParams.rotation);
// ApplyFrameAdditiveAngles(m_viewParams.rotation);
const float fNearZ = gEnv->pSystem->GetIViewSystem()->GetDefaultZNear();
// const float fNearZ = gEnv->pSystem->GetIViewSystem()->GetDefaultZNear();
//see if the view have to use a custom near clipping plane
const float nearPlane = (m_viewParams.nearplane >= CAMERA_MIN_NEAR) ? (m_viewParams.nearplane) : fNearZ;
const float farPlane = (m_viewParams.farplane > 0.f) ? m_viewParams.farplane : DEFAULT_FAR;
float fov = (m_viewParams.fov < 0.001f) ? DEFAULT_FOV : m_viewParams.fov;
// //see if the view have to use a custom near clipping plane
// const float nearPlane = (m_viewParams.nearplane >= CAMERA_MIN_NEAR) ? (m_viewParams.nearplane) : fNearZ;
// const float farPlane = (m_viewParams.farplane > 0.f) ? m_viewParams.farplane : DEFAULT_FAR;
// float fov = (m_viewParams.fov < 0.001f) ? DEFAULT_FOV : m_viewParams.fov;
m_camera.SetFrustum(pSysCam->GetViewSurfaceX(), pSysCam->GetViewSurfaceZ(), fov, nearPlane, farPlane, pSysCam->GetPixelAspectRatio());
// m_camera.SetFrustum(pSysCam->GetViewSurfaceX(), pSysCam->GetViewSurfaceZ(), fov, nearPlane, farPlane, pSysCam->GetPixelAspectRatio());
//apply shake & set the view matrix
m_viewParams.rotation *= m_viewParams.currentShakeQuat;
m_viewParams.rotation.NormalizeSafe();
m_viewParams.position += m_viewParams.currentShakeShift;
// //apply shake & set the view matrix
// m_viewParams.rotation *= m_viewParams.currentShakeQuat;
// m_viewParams.rotation.NormalizeSafe();
// m_viewParams.position += m_viewParams.currentShakeShift;
// Blending between cameras needs to happen after Camera space rendering calculations have been applied
// so that the m_viewParams.position is in World Space again
m_viewParams.UpdateBlending(frameTime);
// // Blending between cameras needs to happen after Camera space rendering calculations have been applied
// // so that the m_viewParams.position is in World Space again
// m_viewParams.UpdateBlending(frameTime);
// [VR] specific
// Add HMD's pose tracking on top of current camera pose
// Each game-title can decide whether to keep this functionality here or (most likely)
// move it somewhere else.
// // [VR] specific
// // Add HMD's pose tracking on top of current camera pose
// // Each game-title can decide whether to keep this functionality here or (most likely)
// // move it somewhere else.
Quat q = m_viewParams.rotation;
Vec3 pos = m_viewParams.position;
Vec3 p = Vec3(ZERO);
// Quat q = m_viewParams.rotation;
// Vec3 pos = m_viewParams.position;
// Vec3 p = Vec3(ZERO);
Matrix34 viewMtx(q);
viewMtx.SetTranslation(pos + p);
m_camera.SetMatrix(viewMtx);
// Matrix34 viewMtx(q);
// viewMtx.SetTranslation(pos + p);
// m_camera.SetMatrix(viewMtx);
m_camera.SetEntityRotation(m_viewParams.rotation);
m_camera.SetEntityPos(pos);
}
else
{
m_linkedTo = AZ::EntityId(0);
}
// m_camera.SetEntityRotation(m_viewParams.rotation);
// m_camera.SetEntityPos(pos);
//}
//else
//{
// m_linkedTo = AZ::EntityId(0);
//}
}
//-----------------------------------------------------------------------
+19 -16
View File
@@ -253,7 +253,8 @@ void CViewSystem::Update(float frameTime)
}
}
m_pSystem->SetViewCamera(rCamera);
AZ_ErrorOnce("CryLegacy", false, "CryLegacy view system no longer available (CViewSystem::Update)");
//m_pSystem->SetViewCamera(rCamera);
}
}
@@ -557,23 +558,25 @@ void CViewSystem::SetOverrideCameraRotation(bool bOverride, Quat rotation)
//////////////////////////////////////////////////////////////////////////
void CViewSystem::UpdateSoundListeners()
{
assert(gEnv->IsEditor() && !gEnv->IsEditorGameMode());
AZ_ErrorOnce("CryLegacy", false, "CryLegacy view system no longer available (CViewSystem::UpdateSoundListeners)");
// In Editor we may want to control global listeners outside of the game view.
if (m_bControlsAudioListeners)
{
IView* const pActiveView = static_cast<IView*>(GetActiveView());
TViewMap::const_iterator Iter(m_views.begin());
TViewMap::const_iterator const IterEnd(m_views.end());
//assert(gEnv->IsEditor() && !gEnv->IsEditorGameMode());
for (; Iter != IterEnd; ++Iter)
{
IView* const pView = Iter->second;
bool const bIsActive = (pView == pActiveView);
CCamera const& rCamera = bIsActive ? gEnv->pSystem->GetViewCamera() : pView->GetCamera();
pView->UpdateAudioListener(rCamera.GetMatrix());
}
}
//// In Editor we may want to control global listeners outside of the game view.
//if (m_bControlsAudioListeners)
//{
// IView* const pActiveView = static_cast<IView*>(GetActiveView());
// TViewMap::const_iterator Iter(m_views.begin());
// TViewMap::const_iterator const IterEnd(m_views.end());
// for (; Iter != IterEnd; ++Iter)
// {
// IView* const pView = Iter->second;
// bool const bIsActive = (pView == pActiveView);
// CCamera const& rCamera = bIsActive ? gEnv->pSystem->GetViewCamera() : pView->GetCamera();
// pView->UpdateAudioListener(rCamera.GetMatrix());
// }
//}
}
//////////////////////////////////////////////////////////////////