From 88b2d4f63f72c3c5c249ad13d32848bd3b2cb005 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 7 Sep 2018 13:26:08 +0300 Subject: Add fovhorizontal property to cameras MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a boolean property. If it is true, the fov value will be interpreted as horizontal angle. Task-number: QT3DS-708 Change-Id: I5642c6cd2e32fb4d0872d0422b58077f0f8af2f7 Reviewed-by: Teemu Tamminen Reviewed-by: Tomi Korpipää Reviewed-by: Mahmoud Badri --- .../Systems/Qt3DSDMComposerTypeDefinitions.cpp | 1 + .../Systems/Qt3DSDMComposerTypeDefinitions.h | 1 + .../Studio/Render/StudioRendererTranslation.cpp | 1 + .../Qt3DSRenderRuntimeBindingImplTranslation.cpp | 1 + .../GraphObjects/Qt3DSRenderCamera.cpp | 21 +++++++++++++++++---- .../GraphObjects/Qt3DSRenderCamera.h | 4 ++++ .../Include/Qt3DSRenderUIPSharedTranslation.h | 1 + .../RendererImpl/Qt3DSRendererImpl.cpp | 3 ++- .../Qt3DSRendererImplLayerRenderData.cpp | 2 +- .../Source/Qt3DSRenderUIPLoader.cpp | 1 + .../Source/Runtime/Include/Qt3DSAttributeHashes.h | 1 + .../Source/Runtime/Include/Qt3DSAttributeHashes.txt | 1 + .../Source/Runtime/Source/Qt3DSAttributeHashes.cpp | 1 + .../res/DataModelMetadata/en-us/MetaData.xml | 3 +++ 14 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp index d7ac3b60..2c998ae8 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp @@ -208,6 +208,7 @@ struct DataConstructor #define QT3DS_WCHAR_T_shdwfilter L"shdwfilter" #define QT3DS_WCHAR_T_orthographic L"orthographic" #define QT3DS_WCHAR_T_fov L"fov" +#define QT3DS_WCHAR_T_fovhorizontal L"fovhorizontal" #define QT3DS_WCHAR_T_clipnear L"clipnear" #define QT3DS_WCHAR_T_clipfar L"clipfar" #define QT3DS_WCHAR_T_lookatlock L"lookatlock" diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h index c23a930e..d72eea1e 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h @@ -255,6 +255,7 @@ class IPropertySystem; #define ITERATE_COMPOSER_CAMERA_PROPERTIES \ HANDLE_COMPOSER_PROPERTY(orthographic, m_Orthographic, bool, false) \ HANDLE_COMPOSER_PROPERTY(fov, m_Fov, float, 60.f) \ + HANDLE_COMPOSER_PROPERTY(fovhorizontal, m_FovHorizontal, bool, false) \ HANDLE_COMPOSER_PROPERTY(clipnear, m_ClipNear, float, 10.f) \ HANDLE_COMPOSER_PROPERTY(clipfar, m_ClipFar, float, 100000.f) \ HANDLE_COMPOSER_PROPERTY(scalemode, m_ScaleMode, TDataStrPtr, L"Fit") \ diff --git a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp index 9187f57a..b38b1003 100644 --- a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp @@ -382,6 +382,7 @@ struct STranslatorDataModelParser #define Camera_ClipNear m_Camera.m_ClipNear #define Camera_ClipFar m_Camera.m_ClipFar #define Camera_FOV m_Camera.m_Fov +#define Camera_FOVHorizontal m_Camera.m_FovHorizontal #define Camera_Orthographic m_Camera.m_Orthographic #define Camera_ScaleMode m_Camera.m_ScaleMode #define Camera_ScaleAnchor m_Camera.m_ScaleAnchor diff --git a/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp b/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp index 8b3f90a8..1eb7fa48 100644 --- a/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp +++ b/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp @@ -522,6 +522,7 @@ struct SRuntimePropertyParser #define Camera_ClipNear ATTRIBUTE_CLIPNEAR #define Camera_ClipFar ATTRIBUTE_CLIPFAR #define Camera_FOV ATTRIBUTE_FOV +#define Camera_FOVHorizontal ATTRIBUTE_FOVHORIZONTAL #define Camera_Orthographic ATTRIBUTE_ORTHOGRAPHIC #define Camera_ScaleMode ATTRIBUTE_SCALEMODE #define Camera_ScaleAnchor ATTRIBUTE_SCALEANCHOR diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.cpp index 218dfd16..062a36c5 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.cpp @@ -33,9 +33,8 @@ #include "render/Qt3DSRenderTexture2D.h" #include "render/Qt3DSRenderContext.h" #include "Qt3DSTextRenderer.h" -/* -#include -*/ + +#include using namespace qt3ds::render; @@ -159,6 +158,7 @@ SCamera::SCamera() , m_ClipNear(10) , m_ClipFar(10000) , m_FOV(60) + , m_FOVHorizontal(false) , m_ScaleMode(CameraScaleModes::Fit) , m_ScaleAnchor(CameraScaleAnchors::Center) { @@ -201,7 +201,7 @@ bool SCamera::ComputeFrustumPerspective(const NVRenderRectF &inViewport, const QT3DSVec2 &inDesignDimensions) { m_Projection = QT3DSMat44::createIdentity(); - QT3DSF32 theAngleInRadians = m_FOV / 2.0f; + QT3DSF32 theAngleInRadians = verticalFov(inViewport) / 2.0f; QT3DSF32 theDeltaZ = m_ClipFar - m_ClipNear; QT3DSF32 theSine = sinf(theAngleInRadians); QT3DSF32 designAspect = GetAspectRatio(inDesignDimensions); @@ -471,3 +471,16 @@ QT3DSVec3 SCamera::UnprojectToPosition(const QT3DSVec3 &inGlobalPos, const SRay NVPlane theCameraPlane(theCameraDir, theDistance); return inRay.Intersect(theCameraPlane); } + +QT3DSF32 SCamera::verticalFov(QT3DSF32 aspectRatio) const +{ + if (m_FOVHorizontal) + return 2.0f * qAtan(qTan(qreal(m_FOV) / 2.0) / qreal(aspectRatio)); + else + return m_FOV; +} + +QT3DSF32 SCamera::verticalFov(const NVRenderRectF &inViewport) const +{ + return verticalFov(GetAspectRatio(inViewport)); +} diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.h b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.h index 3939276e..d6d8ce82 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderCamera.h @@ -102,6 +102,7 @@ namespace render { QT3DSF32 m_ClipFar; QT3DSF32 m_FOV; // Radians + bool m_FOVHorizontal; QT3DSMat44 m_Projection; CameraScaleModes::Enum m_ScaleMode; @@ -166,6 +167,9 @@ namespace render { // plane as inGlobalPos. // Expects CalculateGlobalVariables has been called or doesn't need to be. QT3DSVec3 UnprojectToPosition(const QT3DSVec3 &inGlobalPos, const SRay &inRay) const; + + QT3DSF32 verticalFov(QT3DSF32 aspectRatio) const; + QT3DSF32 verticalFov(const NVRenderRectF &inViewport) const; }; } } diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h index 00727d53..eb19f51f 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h @@ -339,6 +339,7 @@ namespace render { HANDLE_QT3DS_RENDER_PROPERTY(Camera, ClipNear, Dirty) \ HANDLE_QT3DS_RENDER_PROPERTY(Camera, ClipFar, Dirty) \ HANDLE_QT3DS_RENDER_RADIAN_PROPERTY(Camera, FOV, Dirty) \ + HANDLE_QT3DS_RENDER_PROPERTY(Camera, FOVHorizontal, Dirty) \ HANDLE_QT3DS_NODE_FLAGS_PROPERTY(Camera, Orthographic, Dirty) \ HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Camera, ScaleMode, Dirty) \ HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Camera, ScaleAnchor, Dirty) diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImpl.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImpl.cpp index 94fe815d..d6fb3b1b 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImpl.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImpl.cpp @@ -1649,11 +1649,12 @@ namespace render { QT3DSF32 R2 = pLayer->m_AoDistance * pLayer->m_AoDistance * 0.16f; QT3DSF32 rw = 100, rh = 100; - QT3DSF32 fov = (pCamera) ? pCamera->m_FOV : 1.0f; + if (inDepthTexture && inDepthTexture.GetTexture()) { rw = (QT3DSF32)inDepthTexture.GetTexture()->GetTextureDetails().m_Width; rh = (QT3DSF32)inDepthTexture.GetTexture()->GetTextureDetails().m_Height; } + QT3DSF32 fov = (pCamera) ? pCamera->verticalFov(rw / rh) : 1.0f; QT3DSF32 tanHalfFovY = tanf(0.5f * fov * (rh / rw)); QT3DSF32 invFocalLenX = tanHalfFovY * (rw / rh); diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp index 51bff7f4..15070b64 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp @@ -316,7 +316,7 @@ namespace render { QT3DSVec3 camY(dataPtr[4], dataPtr[5], dataPtr[6]); QT3DSVec3 camZ(dataPtr[8], dataPtr[9], dataPtr[10]); - float tanFOV = tanf(inCamera.m_FOV * 0.5f); + float tanFOV = tanf(inCamera.verticalFov(inViewPort) * 0.5f); float asTanFOV = tanFOV * inViewPort.m_Width / inViewPort.m_Height; camEdges[0] = -asTanFOV * camX + tanFOV * camY + camZ; camEdges[1] = asTanFOV * camX + tanFOV * camY + camZ; diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp index 8167e577..70280b0e 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp @@ -713,6 +713,7 @@ struct SRenderUIPLoader : public IDOMReferenceResolver #define Camera_ClipNear "clipnear" #define Camera_ClipFar "clipfar" #define Camera_FOV "fov" +#define Camera_FOVHorizontal "fovhorizontal" #define Camera_Orthographic "orthographic" #define Camera_ScaleMode "scalemode" #define Camera_ScaleAnchor "scaleanchor" diff --git a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h index 51a6163f..2a497bf4 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h @@ -74,6 +74,7 @@ enum EAttribute { ATTRIBUTE_CLIPNEAR = 0x0068FF28, // clipnear ATTRIBUTE_CLIPFAR = 0x037EF699, // clipfar ATTRIBUTE_FOV = 0x00D60213, // fov + ATTRIBUTE_FOVHORIZONTAL = 0x01BDB34F, // fovhorizontal ATTRIBUTE_SCALEMODE = 0x01FD2FD3, // scalemode ATTRIBUTE_SCALEANCHOR = 0x02CFCF41, // scaleanchor ATTRIBUTE_BRIGHTNESS = 0x0230D3AF, // brightness diff --git a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt index 7e0a3f0d..90948c07 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt @@ -34,6 +34,7 @@ orthographic clipnear clipfar fov +fovhorizontal scalemode scaleanchor diff --git a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp index 60d748cb..4d201d72 100644 --- a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp +++ b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp @@ -83,6 +83,7 @@ const char *GetAttributeString(const EAttribute inAttribute) case ATTRIBUTE_CLIPNEAR: return "clipnear"; case ATTRIBUTE_CLIPFAR: return "clipfar"; case ATTRIBUTE_FOV: return "fov"; + case ATTRIBUTE_FOVHORIZONTAL: return "fovhorizontal"; case ATTRIBUTE_SCALEMODE: return "scalemode"; case ATTRIBUTE_SCALEANCHOR: return "scaleanchor"; case ATTRIBUTE_BRIGHTNESS: return "brightness"; diff --git a/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml b/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml index e2cfd852..cdfb282c 100644 --- a/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml +++ b/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml @@ -46,6 +46,9 @@ + + + -- cgit v1.2.3