code refactoring
This commit is contained in:
@@ -14,9 +14,8 @@ namespace OpenVulkano
|
||||
m_camera = camera;
|
||||
m_actionCastRay = m_inputManager->GetAction("cast ray");
|
||||
m_actionCastRay->BindKey(Input::InputKey::Mouse::BUTTON_1);
|
||||
// BIND FOR TOUCH
|
||||
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_X);
|
||||
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_X);
|
||||
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_Y);
|
||||
}
|
||||
|
||||
void CameraController::Tick()
|
||||
@@ -30,7 +29,9 @@ namespace OpenVulkano
|
||||
Math::Vector2i pos = mouse->GetMousePosition();
|
||||
mouse->onLeftButtonClick.NotifyAll(pos);
|
||||
}
|
||||
else if (touch)
|
||||
// not sure about second condition here, but here should be something
|
||||
else if (touch && (touch->GetAxis(Input::InputKey::Touch::AXIS_TAP_X) != 0
|
||||
|| touch->GetAxis(Input::InputKey::Touch::AXIS_TAP_Y) != 0))
|
||||
{
|
||||
Math::Vector2i pos = touch->GetTapPosition();
|
||||
touch->OnTap.NotifyAll(pos);
|
||||
|
||||
@@ -52,17 +52,17 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,15 @@ namespace OpenVulkano::Scene
|
||||
UpdateWorldMatrix(parent ? parent->GetWorldMatrix() : Math::Matrix4f(1));
|
||||
}
|
||||
|
||||
Node* Node::GetRoot()
|
||||
{
|
||||
if (IsRoot() || !parent)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
return parent->GetRoot();
|
||||
}
|
||||
|
||||
void Node::UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat)
|
||||
{
|
||||
worldMat = parentWorldMat * localMat;
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace OpenVulkano::Scene
|
||||
|
||||
void SetMatrix(const Math::Matrix4f& mat);
|
||||
|
||||
[[nodiscard]] Node* GetRoot();
|
||||
|
||||
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(localMat); }
|
||||
|
||||
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
||||
|
||||
@@ -88,7 +88,10 @@ namespace OpenVulkano
|
||||
virtual void SetCamera(Camera* camera)
|
||||
{
|
||||
this->camera = camera;
|
||||
camera->scene = this;
|
||||
if (!camera->scene)
|
||||
{
|
||||
this->GetRoot()->AddChild(camera->GetRoot());
|
||||
}
|
||||
}
|
||||
|
||||
Camera* GetCamera() const
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
#include "Scene/Geometry.hpp"
|
||||
#include "Scene/Shader/Shader.hpp"
|
||||
#include "Base/Logger.hpp"
|
||||
#include <magic_enum.hpp>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
@@ -40,20 +42,24 @@ namespace OpenVulkano::Scene
|
||||
{
|
||||
m_mesh->CalculateAABB();
|
||||
}
|
||||
if (ray.IntersectAABB(m_mesh->aabb))
|
||||
auto bboxHit = ray.IntersectAABB(m_mesh->aabb);
|
||||
if (!bboxHit)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (GetShader()->topology == Topology::TRIANGLE_LIST)
|
||||
{
|
||||
if (m_mesh->indexCount != 0)
|
||||
{
|
||||
for (int i = 0; i < m_mesh->indexCount / 3; i++)
|
||||
assert(m_mesh->indexCount % 3 == 0 && "Topology is TRIANGLE_LIST but index count is not divisible by 3");
|
||||
for (int i = 0; i < m_mesh->indexCount; i += 3)
|
||||
{
|
||||
if (m_mesh->indexType == VertexIndexType::UINT16)
|
||||
{
|
||||
uint16_t* indices = m_mesh->GetIndices16();
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i * 3]].position,
|
||||
m_mesh->vertices[indices[i * 3 + 1]].position,
|
||||
m_mesh->vertices[indices[i * 3 + 2]].position))
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i]].position,
|
||||
m_mesh->vertices[indices[i + 1]].position,
|
||||
m_mesh->vertices[indices[i + 2]].position))
|
||||
{
|
||||
return hit;
|
||||
}
|
||||
@@ -61,9 +67,9 @@ namespace OpenVulkano::Scene
|
||||
else
|
||||
{
|
||||
uint32_t* indices = m_mesh->GetIndices32();
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i * 3]].position,
|
||||
m_mesh->vertices[indices[i * 3 + 1]].position,
|
||||
m_mesh->vertices[indices[i * 3 + 2]].position))
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i]].position,
|
||||
m_mesh->vertices[indices[i + 1]].position,
|
||||
m_mesh->vertices[indices[i + 2]].position))
|
||||
{
|
||||
return hit;
|
||||
}
|
||||
@@ -72,17 +78,22 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_mesh->vertexCount / 3; i++)
|
||||
assert(m_mesh->indexCount % 3 == 0 && "Topology is TRIANGLE_LIST but vertex count is not divisible by 3");
|
||||
for (int i = 0; i < m_mesh->vertexCount; i += 3)
|
||||
{
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[i * 3].position,
|
||||
m_mesh->vertices[i * 3 + 1].position,
|
||||
m_mesh->vertices[i * 3 + 2].position))
|
||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[i].position,
|
||||
m_mesh->vertices[i + 1].position,
|
||||
m_mesh->vertices[i + 2].position))
|
||||
{
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::APP->debug("Bbox is hit, but intersection check for topology {} is not implemented", magic_enum::enum_name(GetShader()->topology));
|
||||
return bboxHit;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenVulkano::Scene
|
||||
Math::AABB& GetBoundingBox() { return m_bbox; }
|
||||
TextConfig& GetConfig() { return m_cfg; }
|
||||
Shader* GetShader() { return m_shader; }
|
||||
std::string& GetText() { return m_text; }
|
||||
[[nodiscard]] const std::string& GetText() const { return m_text; }
|
||||
std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||
private:
|
||||
Geometry m_geometry;
|
||||
|
||||
Reference in New Issue
Block a user