Base refactor

This commit is contained in:
2023-11-14 09:16:48 -06:00
parent 214082d00f
commit 1817dcaf3a
410 changed files with 749 additions and 20823 deletions

View File

@@ -1,10 +0,0 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Ray3D.cpp
)

View File

@@ -1,51 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Ray3D.hpp"
#include "assert/assert.hpp"
using namespace Dawn;
bool_t Dawn::raytestQuad(
const struct Ray3D ray,
const glm::vec2 min,
const glm::vec2 max,
const glm::mat4 transform,
glm::vec3 &point,
glm::vec3 &normal,
float_t &distance
) {
// transform ray into local space of the quad
glm::mat4 inverseTransform = glm::inverse(transform);
glm::vec3 localRayOrigin = glm::vec3(
inverseTransform * glm::vec4(ray.origin, 1.0f)
);
glm::vec3 localRayDirection = glm::vec3(
inverseTransform * glm::vec4(ray.direction, 0.0f)
);
// perform ray-quad intersection test
float_t t = -localRayOrigin.z / localRayDirection.z; // intersection distance along ray
if(t < 0) return false; // intersection is behind the ray origin
glm::vec2 intersectionPoint = (
glm::vec2(localRayOrigin) + t * glm::vec2(localRayDirection)
);
if(
glm::any(glm::lessThan(intersectionPoint, min)) ||
glm::any(glm::greaterThan(intersectionPoint, max))
) {
return false; // intersection is outside the quad
}
distance = t;
// compute point and normal of intersection in world space
glm::vec3 localIntersectionPoint = glm::vec3(intersectionPoint, 0.0f);
point = glm::vec3(transform * glm::vec4(localIntersectionPoint, 1.0f));
normal = glm::normalize(
glm::vec3(transform * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f))
);
return true; // intersection found
}

View File

@@ -1,36 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Ray3D {
glm::vec3 origin;
glm::vec3 direction;
};
/**
* Tests whether a ray intersects a quad within 3D space.
*
* @param ray Ray to test.
* @param min Minimum point of the quad.
* @param max Maximum point of the quad.
* @param transform Transform of the quad.
* @param point Out point of intersection.
* @param normal Out normal of the quad at the point of intersection.
* @param distance Out distance from the ray origin to the intersection.
* @return True if the ray intersects the quad, false otherwise.
*/
bool_t raytestQuad(
const struct Ray3D ray,
const glm::vec2 min,
const glm::vec2 max,
const glm::mat4 transform,
glm::vec3 &point,
glm::vec3 &normal,
float_t &distance
);
}

View File

@@ -1,6 +0,0 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_subdirectory(3d)