rework API

This commit is contained in:
ohyzha
2024-11-06 09:48:53 +02:00
parent e2df88ca22
commit 3521ddeb1d
21 changed files with 296 additions and 230 deletions

View File

@@ -5,24 +5,14 @@
*/
#include "Camera.hpp"
#include "Scene/Scene.hpp"
#include "Scene/SimpleDrawable.hpp"
#include "Scene/Geometry.hpp"
#include "Scene/Shader/Shader.hpp"
#include "Scene/TextDrawable.hpp"
#include "Scene/Prefabs/LabelDrawable.hpp"
#include "Scene/Ray.hpp"
#include "Scene/TextDrawable.hpp"
namespace OpenVulkano::Scene
{
std::optional<DrawableRayHit> PerspectiveCamera::CastRay(const Math::Vector2i& xy) const
Ray Camera::CastRay(const Math::Vector2i& xy) const
{
using namespace Math::Utils;
auto scene = GetScene();
// nds
float ndsX = (2.f * xy.x) / m_width - 1.0f;
float ndsY = (2.f * xy.y) / m_height - 1.0f;
@@ -34,35 +24,8 @@ namespace OpenVulkano::Scene
rayEye.a = 0;
Math::Vector3f rayWorld = normalize(inverse(m_view) * rayEye);
std::optional<DrawableRayHit> res;
for (Drawable* d: scene->rayHittableDrawables)
{
const auto& m = d->GetNodes()[0]->GetWorldMatrix();
const Math::Vector3f rayLocalDir = normalize(inverse(m) * Math::Vector4f(rayWorld, 0));
const Math::Vector4f rayLocalPos = inverse(m) * m_camPosition;
const Ray ray(rayLocalPos, rayLocalDir);
if (auto hit = d->Intersect(ray))
{
// choose the closest one
if (!res || (hit->distance < res->distance))
{
res = hit;
res->drawable = d;
}
}
}
//if (res)
//{
// if (SimpleDrawable* sd = dynamic_cast<SimpleDrawable*>(res->drawable))
// {
// Logger::APP->info("Ray intersects object {}", sd->GetMesh()->name);
// }
// else if (LabelDrawable* sd = dynamic_cast<LabelDrawable*>(res->drawable))
// {
// Logger::APP->info("Ray intersects label {}", sd->GetTexts().front().GetText());
// }
//}
return res;
Ray r(GetPosition(), rayWorld);
return r;
}
}