code refactoring
This commit is contained in:
@@ -14,9 +14,8 @@ namespace OpenVulkano
|
|||||||
m_camera = camera;
|
m_camera = camera;
|
||||||
m_actionCastRay = m_inputManager->GetAction("cast ray");
|
m_actionCastRay = m_inputManager->GetAction("cast ray");
|
||||||
m_actionCastRay->BindKey(Input::InputKey::Mouse::BUTTON_1);
|
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_X);
|
||||||
|
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraController::Tick()
|
void CameraController::Tick()
|
||||||
@@ -30,7 +29,9 @@ namespace OpenVulkano
|
|||||||
Math::Vector2i pos = mouse->GetMousePosition();
|
Math::Vector2i pos = mouse->GetMousePosition();
|
||||||
mouse->onLeftButtonClick.NotifyAll(pos);
|
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();
|
Math::Vector2i pos = touch->GetTapPosition();
|
||||||
touch->OnTap.NotifyAll(pos);
|
touch->OnTap.NotifyAll(pos);
|
||||||
|
|||||||
@@ -52,17 +52,17 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res)
|
//if (res)
|
||||||
{
|
//{
|
||||||
if (SimpleDrawable* sd = dynamic_cast<SimpleDrawable*>(res->drawable))
|
// if (SimpleDrawable* sd = dynamic_cast<SimpleDrawable*>(res->drawable))
|
||||||
{
|
// {
|
||||||
Logger::APP->info("Ray intersects object {}", sd->GetMesh()->name);
|
// Logger::APP->info("Ray intersects object {}", sd->GetMesh()->name);
|
||||||
}
|
// }
|
||||||
else if (LabelDrawable* sd = dynamic_cast<LabelDrawable*>(res->drawable))
|
// else if (LabelDrawable* sd = dynamic_cast<LabelDrawable*>(res->drawable))
|
||||||
{
|
// {
|
||||||
Logger::APP->info("Ray intersects label {}", sd->GetTexts().front().GetText());
|
// Logger::APP->info("Ray intersects label {}", sd->GetTexts().front().GetText());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,15 @@ namespace OpenVulkano::Scene
|
|||||||
UpdateWorldMatrix(parent ? parent->GetWorldMatrix() : Math::Matrix4f(1));
|
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)
|
void Node::UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat)
|
||||||
{
|
{
|
||||||
worldMat = parentWorldMat * localMat;
|
worldMat = parentWorldMat * localMat;
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ namespace OpenVulkano::Scene
|
|||||||
|
|
||||||
void SetMatrix(const Math::Matrix4f& mat);
|
void SetMatrix(const Math::Matrix4f& mat);
|
||||||
|
|
||||||
|
[[nodiscard]] Node* GetRoot();
|
||||||
|
|
||||||
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(localMat); }
|
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(localMat); }
|
||||||
|
|
||||||
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
||||||
|
|||||||
@@ -88,7 +88,10 @@ namespace OpenVulkano
|
|||||||
virtual void SetCamera(Camera* camera)
|
virtual void SetCamera(Camera* camera)
|
||||||
{
|
{
|
||||||
this->camera = camera;
|
this->camera = camera;
|
||||||
camera->scene = this;
|
if (!camera->scene)
|
||||||
|
{
|
||||||
|
this->GetRoot()->AddChild(camera->GetRoot());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera* GetCamera() const
|
Camera* GetCamera() const
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
#include "Scene/Geometry.hpp"
|
#include "Scene/Geometry.hpp"
|
||||||
#include "Scene/Shader/Shader.hpp"
|
#include "Scene/Shader/Shader.hpp"
|
||||||
#include "Base/Logger.hpp"
|
#include "Base/Logger.hpp"
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
@@ -40,20 +42,24 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
m_mesh->CalculateAABB();
|
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 (GetShader()->topology == Topology::TRIANGLE_LIST)
|
||||||
{
|
{
|
||||||
if (m_mesh->indexCount != 0)
|
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)
|
if (m_mesh->indexType == VertexIndexType::UINT16)
|
||||||
{
|
{
|
||||||
uint16_t* indices = m_mesh->GetIndices16();
|
uint16_t* indices = m_mesh->GetIndices16();
|
||||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i * 3]].position,
|
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i]].position,
|
||||||
m_mesh->vertices[indices[i * 3 + 1]].position,
|
m_mesh->vertices[indices[i + 1]].position,
|
||||||
m_mesh->vertices[indices[i * 3 + 2]].position))
|
m_mesh->vertices[indices[i + 2]].position))
|
||||||
{
|
{
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
@@ -61,9 +67,9 @@ namespace OpenVulkano::Scene
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32_t* indices = m_mesh->GetIndices32();
|
uint32_t* indices = m_mesh->GetIndices32();
|
||||||
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i * 3]].position,
|
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[indices[i]].position,
|
||||||
m_mesh->vertices[indices[i * 3 + 1]].position,
|
m_mesh->vertices[indices[i + 1]].position,
|
||||||
m_mesh->vertices[indices[i * 3 + 2]].position))
|
m_mesh->vertices[indices[i + 2]].position))
|
||||||
{
|
{
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
@@ -72,17 +78,22 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
else
|
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,
|
if (auto hit = ray.IntersectTriangle(m_mesh->vertices[i].position,
|
||||||
m_mesh->vertices[i * 3 + 1].position,
|
m_mesh->vertices[i + 1].position,
|
||||||
m_mesh->vertices[i * 3 + 2].position))
|
m_mesh->vertices[i + 2].position))
|
||||||
{
|
{
|
||||||
return hit;
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenVulkano::Scene
|
|||||||
Math::AABB& GetBoundingBox() { return m_bbox; }
|
Math::AABB& GetBoundingBox() { return m_bbox; }
|
||||||
TextConfig& GetConfig() { return m_cfg; }
|
TextConfig& GetConfig() { return m_cfg; }
|
||||||
Shader* GetShader() { return m_shader; }
|
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; }
|
std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||||
private:
|
private:
|
||||||
Geometry m_geometry;
|
Geometry m_geometry;
|
||||||
|
|||||||
Reference in New Issue
Block a user