From 3d876df5baba009a324848efd90d45ad6ddb05ea Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 25 Oct 2024 20:55:19 -0700 Subject: [PATCH] HnCamera: use scene units for camera transform matrix --- Hydrogent/src/HnCamera.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Hydrogent/src/HnCamera.cpp b/Hydrogent/src/HnCamera.cpp index 95f6bbb9..3c883381 100644 --- a/Hydrogent/src/HnCamera.cpp +++ b/Hydrogent/src/HnCamera.cpp @@ -60,16 +60,18 @@ void HnCamera::Sync(pxr::HdSceneDelegate* SceneDelegate, pxr::HdDirtyBits OrigDirtyBits = *DirtyBits; pxr::HdCamera::Sync(SceneDelegate, RenderParam, DirtyBits); + const float MetersPerUnit = RenderParam ? static_cast(RenderParam)->GetMetersPerUnit() : 0.01f; + const float UnitsPerMeter = 1.f / MetersPerUnit; if (OrigDirtyBits & pxr::HdCamera::DirtyTransform) { - // USD camera looks along -Z axis, while Diligent camera looks along +Z axis - m_WorldMatrix = float4x4::Scale(1, 1, -1) * ToFloat4x4(_transform); + // USD camera transform is defined in scene units, with camera looking along -Z axis. + // Diligent camera transform is defined in world units, with camera looking along +Z axis. + m_WorldMatrix = float4x4::Scale(UnitsPerMeter, UnitsPerMeter, -UnitsPerMeter) * ToFloat4x4(_transform); m_ViewMatrix = m_WorldMatrix.Inverse(); } if (OrigDirtyBits & pxr::HdCamera::DirtyParams) { - const float MetersPerUnit = RenderParam ? static_cast(RenderParam)->GetMetersPerUnit() : 0.01f; const float HorzAperture = GetHorizontalAperture(); const float VertAperture = GetVerticalAperture(); const float FocalLength = GetFocalLength();