Use const more in ray_triangle
This commit is contained in:
parent
d61450aacb
commit
a844a5c2d7
1 changed files with 8 additions and 8 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "ray.h"
|
#include "ray.h"
|
||||||
|
|
||||||
constexpr float epsilon = std::numeric_limits<float>().epsilon();
|
constexpr float epsilon = std::numeric_limits<float>::epsilon();
|
||||||
|
|
||||||
namespace intersections {
|
namespace intersections {
|
||||||
inline bool ray_sphere(const Ray ray, const glm::vec4 sphere) {
|
inline bool ray_sphere(const Ray ray, const glm::vec4 sphere) {
|
||||||
|
@ -30,20 +30,20 @@ namespace intersections {
|
||||||
float& t,
|
float& t,
|
||||||
float& u,
|
float& u,
|
||||||
float& v) {
|
float& v) {
|
||||||
glm::vec3 e1 = v1 - v0;
|
const glm::vec3 e1 = v1 - v0;
|
||||||
glm::vec3 e2 = v2 - v0;
|
const glm::vec3 e2 = v2 - v0;
|
||||||
|
|
||||||
glm::vec3 pvec = glm::cross(ray.direction, e2);
|
const glm::vec3 pvec = glm::cross(ray.direction, e2);
|
||||||
float det = glm::dot(e1, pvec);
|
const float det = glm::dot(e1, pvec);
|
||||||
|
|
||||||
// if determinant is zero then ray is
|
// if determinant is zero then ray is
|
||||||
// parallel with the triangle plane
|
// parallel with the triangle plane
|
||||||
if (det > -epsilon && det < epsilon)
|
if (det > -epsilon && det < epsilon)
|
||||||
return false;
|
return false;
|
||||||
float invdet = 1.0 / det;
|
const float invdet = 1.0 / det;
|
||||||
|
|
||||||
// calculate distance from m[0] to origin
|
// 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
|
// u and v are the barycentric coordinates
|
||||||
// in triangle if u >= 0, v >= 0 and u + v <= 1
|
// in triangle if u >= 0, v >= 0 and u + v <= 1
|
||||||
|
@ -53,7 +53,7 @@ namespace intersections {
|
||||||
if (u < 0.0 || u > 1.0)
|
if (u < 0.0 || u > 1.0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
glm::vec3 qvec = glm::cross(tvec, e1);
|
const glm::vec3 qvec = glm::cross(tvec, e1);
|
||||||
v = glm::dot(ray.direction, qvec) * invdet;
|
v = glm::dot(ray.direction, qvec) * invdet;
|
||||||
|
|
||||||
// check against other edges
|
// check against other edges
|
||||||
|
|
Loading…
Add table
Reference in a new issue