mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Merge pull request #139 from orange-cpp/feature/mesh_line_tracer
Feature/mesh line tracer
This commit is contained in:
@@ -101,7 +101,6 @@ namespace omath::primitives
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
VectorType vertex_position_to_world_space(const Vector3<float>& vertex_position) const
|
VectorType vertex_position_to_world_space(const Vector3<float>& vertex_position) const
|
||||||
requires HasPosition<VertexType>
|
|
||||||
{
|
{
|
||||||
auto abs_vec = get_to_world_matrix()
|
auto abs_vec = get_to_world_matrix()
|
||||||
* mat_column_from_vector<typename Mat4X4::ContainedType, Mat4X4::get_store_ordering()>(
|
* mat_column_from_vector<typename Mat4X4::ContainedType, Mat4X4::get_store_ordering()>(
|
||||||
@@ -112,11 +111,16 @@ namespace omath::primitives
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Triangle<VectorType> make_face_in_world_space(const Ebo::const_iterator vao_iterator) const
|
Triangle<VectorType> make_face_in_world_space(const Ebo::const_iterator vao_iterator) const
|
||||||
requires HasPosition<VertexType>
|
|
||||||
{
|
{
|
||||||
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x).position),
|
if constexpr (HasPosition<VertexType>)
|
||||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y).position),
|
{
|
||||||
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z).position)};
|
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x).position),
|
||||||
|
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y).position),
|
||||||
|
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z).position)};
|
||||||
|
}
|
||||||
|
return {vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->x)),
|
||||||
|
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->y)),
|
||||||
|
vertex_position_to_world_space(m_vertex_buffer.at(vao_iterator->z))};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -33,5 +33,25 @@ namespace omath::collision
|
|||||||
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||||
|
|
||||||
|
template<class MeshType>
|
||||||
|
[[nodiscard]]
|
||||||
|
static Vector3<float> get_ray_hit_point(const Ray& ray, const MeshType& mesh) noexcept
|
||||||
|
{
|
||||||
|
Vector3<float> mesh_hit = ray.end;
|
||||||
|
|
||||||
|
auto begin = mesh.m_element_buffer_object.cbegin();
|
||||||
|
auto end = mesh.m_element_buffer_object.cend();
|
||||||
|
for (auto current = begin; current < end; current = std::next(current))
|
||||||
|
{
|
||||||
|
auto face = mesh.make_face_in_world_space(current);
|
||||||
|
|
||||||
|
auto ray_stop_point = get_ray_hit_point(ray, face);
|
||||||
|
if (ray_stop_point.distance_to(ray.start) < mesh_hit.distance_to(ray.start))
|
||||||
|
mesh_hit = ray_stop_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mesh_hit;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath::collision
|
} // namespace omath::collision
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
// Created by Vladislav on 11.01.2026.
|
// Created by Vladislav on 11.01.2026.
|
||||||
//
|
//
|
||||||
#include "omath/3d_primitives/box.hpp"
|
#include "omath/3d_primitives/box.hpp"
|
||||||
|
#include "omath/collision/line_tracer.hpp"
|
||||||
#include "omath/engines/opengl_engine/primitives.hpp"
|
#include "omath/engines/opengl_engine/primitives.hpp"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(test, test)
|
TEST(test, test)
|
||||||
{
|
{
|
||||||
auto result = omath::primitives::create_box<omath::opengl_engine::BoxMesh>({0.f, 30.f, 0.f}, {}, omath::opengl_engine::k_abs_forward,
|
auto result = omath::primitives::create_box<omath::opengl_engine::BoxMesh>(
|
||||||
omath::opengl_engine::k_abs_right);
|
{0.f, 30.f, 0.f}, {}, omath::opengl_engine::k_abs_forward, omath::opengl_engine::k_abs_right);
|
||||||
|
|
||||||
|
omath::collision::Ray ray{.start = {0, 0, 0}, .end = {-100, 0, 0}};
|
||||||
|
std::ignore = omath::collision::LineTracer::get_ray_hit_point(ray, result);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
Reference in New Issue
Block a user