Fixes upDirection Vector for camera

This commit is contained in:
Maximilian Giller 2022-11-11 19:02:52 +01:00
parent da6d2af058
commit 26a8ef7913

View file

@ -8,8 +8,12 @@ Ray PerspectiveCamera::createRay(float x, float y) const {
// in which the camera looks along the positive z-Axis
Vector3d normalVector = normalized(crossProduct(upDirection, forwardDirection));
// Orthogonolize upDirection, to avoid skewing the image
Vector3d orthogonalUpDirection = -crossProduct(normalVector, forwardDirection);
Vector3d normalVector_fov = normalVector * std::abs(tan(this->fovAngle / 360.0f * PI));
Vector3d upVector_fov = this->upDirection * std::abs(tan(this->fovAngle / 360.0f * PI));
Vector3d upVector_fov = orthogonalUpDirection * std::abs(tan(this->fovAngle / 360.0f * PI));
Vector3d directionVector = normalized(forwardDirection + x * normalVector_fov + y * upVector_fov);
return Ray {this->position, directionVector};