Skip to content

Apply translate and rotate to user_defined cameras. #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/v3.8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions source/core/render/tracepixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions source/core/scene/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ namespace pov

void Camera::Translate(const Vector3d& Vector)
{
Location += Vector;
TRANSFORM Trans;

Compute_Translation_Transform(&Trans, Vector);
Transform(&Trans);
}


Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -257,6 +262,8 @@ void Camera::Init()
Location_Fn[i] = nullptr;
Direction_Fn[i] = nullptr;
}

UserTrans = Create_Transform();
}

/*****************************************************************************
Expand Down Expand Up @@ -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;
}

Expand All @@ -397,6 +408,7 @@ Camera::Camera(const Camera& src)
Location_Fn[i] = nullptr;
Direction_Fn[i] = nullptr;
}
UserTrans = nullptr;
operator=(src);
}

Expand Down Expand Up @@ -441,6 +453,7 @@ Camera::~Camera()
if (Direction_Fn[i] != nullptr)
delete Direction_Fn[i];
}
Destroy_Transform(UserTrans);
}

}
1 change: 1 addition & 0 deletions source/core/scene/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down