1
Fork 0

Use const more in ray_triangle

This commit is contained in:
Joshua Goins 2024-09-25 10:45:33 +02:00
parent d61450aacb
commit a844a5c2d7

View file

@ -4,7 +4,7 @@
#include "ray.h"
constexpr float epsilon = std::numeric_limits<float>().epsilon();
constexpr float epsilon = std::numeric_limits<float>::epsilon();
namespace intersections {
inline bool ray_sphere(const Ray ray, const glm::vec4 sphere) {
@ -30,20 +30,20 @@ namespace intersections {
float& t,
float& u,
float& v) {
glm::vec3 e1 = v1 - v0;
glm::vec3 e2 = v2 - v0;
const glm::vec3 e1 = v1 - v0;
const glm::vec3 e2 = v2 - v0;
glm::vec3 pvec = glm::cross(ray.direction, e2);
float det = glm::dot(e1, pvec);
const glm::vec3 pvec = glm::cross(ray.direction, e2);
const float det = glm::dot(e1, pvec);
// if determinant is zero then ray is
// parallel with the triangle plane
if (det > -epsilon && det < epsilon)
return false;
float invdet = 1.0 / det;
const float invdet = 1.0 / det;
// calculate distance from m[0] to origin
glm::vec3 tvec = ray.origin - v0;
const glm::vec3 tvec = ray.origin - v0;
// u and v are the barycentric coordinates
// in triangle if u >= 0, v >= 0 and u + v <= 1
@ -53,7 +53,7 @@ namespace intersections {
if (u < 0.0 || u > 1.0)
return false;
glm::vec3 qvec = glm::cross(tvec, e1);
const glm::vec3 qvec = glm::cross(tvec, e1);
v = glm::dot(ray.direction, qvec) * invdet;
// check against other edges