/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "Camera.hpp" namespace OpenVulkano::Scene { Ray Camera::CastRay(const Math::Vector2i& xy) const { using namespace Math::Utils; // nds float ndsX = (2.f * xy.x) / m_width - 1.0f; float ndsY = (2.f * xy.y) / m_height - 1.0f; Math::Vector4f rayClip = { ndsX, ndsY, 0, 1.f }; Math::Vector4f rayEye = inverse(m_projection) * rayClip; rayEye.z = -1; rayEye.a = 0; Math::Vector3f rayWorld = normalize(GetWorldMatrix() * rayEye); Ray r(GetPosition(), rayWorld); return r; } }