From 9de1ba5001faae8f4d663ef60d66b7e67154bb83 Mon Sep 17 00:00:00 2001 From: Nicholas McCoy Date: Mon, 17 Feb 2025 20:26:36 -0500 Subject: [PATCH] Apply translate and rotate to user_defined cameras. --- source/core/render/tracepixel.cpp | 61 ++++++++++++++++++++----------- source/core/scene/camera.cpp | 17 ++++++++- source/core/scene/camera.h | 1 + 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/source/core/render/tracepixel.cpp b/source/core/render/tracepixel.cpp index 58bb16910..12ca1907c 100644 --- a/source/core/render/tracepixel.cpp +++ b/source/core/render/tracepixel.cpp @@ -873,32 +873,51 @@ bool TracePixel::CreateCameraRay(Ray& ray, DBL x, DBL y, DBL width, DBL height, break; case USER_DEFINED_CAMERA: - // Convert the x coordinate to be a DBL from -0.5 to 0.5. - x0 = x / width - 0.5; + { + // Convert the x coordinate to be a DBL from -0.5 to 0.5. + x0 = x / width - 0.5; - // Convert the y coordinate to be a DBL from -0.5 to 0.5. - y0 = 0.5 - y / height; + // Convert the y coordinate to be a DBL from -0.5 to 0.5. + y0 = 0.5 - y / height; - for (unsigned int i = 0; i < 3; ++i) - { - if (camera.Location_Fn[i] != nullptr) - cameraLocation[i] = mpCameraLocationFn[i]->Evaluate(x0, y0); - if (!IsFinite(cameraLocation[i])) - return false; - if (camera.Direction_Fn[i] != nullptr) - cameraDirection[i] = mpCameraDirectionFn[i]->Evaluate(x0, y0); - if (!IsFinite(cameraDirection[i])) + bool bLocationFunction = false; + bool bDirectionFunction = false; + + for (unsigned int i = 0; i < 3; ++i) + { + if (camera.Location_Fn[i] != nullptr) + { + cameraLocation[i] = mpCameraLocationFn[i]->Evaluate(x0, y0); + bLocationFunction = true; + } + if (!IsFinite(cameraLocation[i])) + return false; + + if (camera.Direction_Fn[i] != nullptr) + { + cameraDirection[i] = mpCameraDirectionFn[i]->Evaluate(x0, y0); + bDirectionFunction = true; + } + if (!IsFinite(cameraDirection[i])) + return false; + } + + if (bLocationFunction) + MTransPoint(cameraLocation, cameraLocation, camera.UserTrans); + + if (bDirectionFunction) + MTransDirection(cameraDirection, cameraDirection, camera.UserTrans); + + if (cameraDirection.IsNearNull(EPSILON)) return false; - } - if (cameraDirection.IsNearNull(EPSILON)) - return false; - ray.Origin = cameraLocation; - ray.Direction = cameraDirection; + ray.Origin = cameraLocation; + ray.Direction = cameraDirection; - if(useFocalBlur) - JitterCameraRay(ray, x, y, ray_number); + if(useFocalBlur) + JitterCameraRay(ray, x, y, ray_number); - InitRayContainerState(ray, true); + InitRayContainerState(ray, true); + } break; default: diff --git a/source/core/scene/camera.cpp b/source/core/scene/camera.cpp index d863d3ea5..2f69bb233 100644 --- a/source/core/scene/camera.cpp +++ b/source/core/scene/camera.cpp @@ -75,7 +75,10 @@ namespace pov void Camera::Translate(const Vector3d& Vector) { - Location += Vector; + TRANSFORM Trans; + + Compute_Translation_Transform(&Trans, Vector); + Transform(&Trans); } @@ -183,7 +186,9 @@ void Camera::Transform(const TRANSFORM *Trans) MTransPoint(Location, Location, Trans); MTransDirection(Direction, Direction, Trans); MTransDirection(Up, Up, Trans); - MTransDirection(Right, Right, Trans); + MTransDirection(Right, Right, Trans); + + Compose_Transforms (UserTrans, Trans); } @@ -257,6 +262,8 @@ void Camera::Init() Location_Fn[i] = nullptr; Direction_Fn[i] = nullptr; } + + UserTrans = Create_Transform(); } /***************************************************************************** @@ -384,6 +391,10 @@ Camera& Camera::operator=(const Camera& src) } + if (UserTrans != nullptr) + Destroy_Transform(UserTrans); + UserTrans = (src.UserTrans ? Copy_Transform(src.UserTrans) : nullptr); + return *this; } @@ -397,6 +408,7 @@ Camera::Camera(const Camera& src) Location_Fn[i] = nullptr; Direction_Fn[i] = nullptr; } + UserTrans = nullptr; operator=(src); } @@ -441,6 +453,7 @@ Camera::~Camera() if (Direction_Fn[i] != nullptr) delete Direction_Fn[i]; } + Destroy_Transform(UserTrans); } } diff --git a/source/core/scene/camera.h b/source/core/scene/camera.h index 38bcc8c66..c9b8fd059 100644 --- a/source/core/scene/camera.h +++ b/source/core/scene/camera.h @@ -100,6 +100,7 @@ class Camera PIGMENT *Bokeh; // Pigment to use for the bokeh GenericScalarFunctionPtr Location_Fn[3]; // [USER_DEFINED_CAMERA] Set of functions defining the ray's origin for each screen position. GenericScalarFunctionPtr Direction_Fn[3]; // [USER_DEFINED_CAMERA] Set of functions defining the ray's direction for each screen position. + TRANSFORM *UserTrans; // [USER_DEFINED_CAMERA] Transformation to apply after calculating functions // the following declarations are used for the mesh camera unsigned int Face_Distribution_Method; // how to associate a pixel to a face within a mesh