aboutsummaryrefslogtreecommitdiff
path: root/src/intersect
diff options
context:
space:
mode:
authorFate Bussey <lafayette_bussey@brown.edu>2023-12-13 15:50:58 -0500
committerFate Bussey <lafayette_bussey@brown.edu>2023-12-13 15:50:58 -0500
commit5de0f3b6de57aa0cdc6b1aa7efc57836a99ee59a (patch)
tree68064d5229136a677b4af265df88740cfeb0b54a /src/intersect
parent88ac9032e4a53407c569d6eb7c67619924daf296 (diff)
parent33a1cdc3532d145944b00a4ca03fd01d4d5b9532 (diff)
cone and cylinder intersection final
Diffstat (limited to 'src/intersect')
-rw-r--r--src/intersect/intersect.cpp18
-rw-r--r--src/intersect/normals.cpp9
2 files changed, 15 insertions, 12 deletions
diff --git a/src/intersect/intersect.cpp b/src/intersect/intersect.cpp
index 71cae49..d5ab015 100644
--- a/src/intersect/intersect.cpp
+++ b/src/intersect/intersect.cpp
@@ -63,7 +63,7 @@ glm::vec4 intersectCone(
float radius = 0.5f;
float a = d.x*d.x + d.z*d.z - .25f*(d.y*d.y) - .25f*(d[3]*d[3]);
float b = 2.f*(p.x*d.x + p.z*d.z) - .5f*(p.y*d.y) + .25f*d.y - .5f*(p[3]*d[3]) + .25f*d[3];
- float c = p.x*p.x + p.z*p.z - .25f*(p.y*p.y) + .25f*p.y - .25f*(p[3]*p[3]) + .25f*p[3] - 1/8.f;
+ float c = p.x*p.x + p.z*p.z - .25f*(p.y*p.y) + .25f*p.y - .25f*(p[3]*p[3]) + .25f*p[3] - 1/16.f;
float discriminant = b*b - 4*a*c;
if (discriminant >= 0)
@@ -97,7 +97,7 @@ glm::vec4 intersectCone(
auto pwBase = p + twBase * d;
if (
twBase > 0 &&
- pwBase.x*pwBase.x + pwBase.z*pwBase.z <= pwBase.y*pwBase.y -.25f &&
+ pwBase.x*pwBase.x + pwBase.z*pwBase.z <= pwBase.y*pwBase.y + .25f &&
pwBase.y >= -.5f && pwBase.y <= .5f
)
{
@@ -109,7 +109,7 @@ glm::vec4 intersectCone(
auto pyBase = p + tyBase * d;
if (
tyBase > 0 &&
- pyBase.x*pyBase.x + pyBase.z*pyBase.z <= pyBase[3]*pyBase[3] -.25f &&
+ pyBase.x*pyBase.x + pyBase.z*pyBase.z <= pyBase[3]*pyBase[3] +.25f &&
pyBase[3] >= -.5f && pyBase[3] <= .5f
)
{
@@ -174,21 +174,23 @@ glm::vec4 intersectCylinder(
if (
tTop > 0 &&
pTop.x*pTop.x + pTop.z*pTop.z <= radius*radius &&
- pTop.y >= -.5f && pTop.y <= .5f &&
- pTop[3] >= -.5f && pTop[3] <= .5f)
+ pTop.y >= -.5f && pTop.y <= .5f //&&
+// pTop[3] >= -.5f && pTop[3] <= .5f
+ )
{
t = std::min(t, tTop);
}
// implicit p_y + t*d_y = -.5f, Bottom base
- float tBase = (.5f - p.y - p[3]) / (d[3] + d.y);
+ float tBase = (-.5f - p.y - p[3]) / (d[3] + d.y);
auto pBase = p + tBase * d;
if (
tBase > 0 &&
pBase.x*pBase.x + pBase.z*pBase.z <= radius*radius &&
- pBase.y >= -.5f && pBase.y <= .5f &&
- pBase[3] >= -.5f && pBase[3] <= .5f)
+ pBase.y >= -.5f && pBase.y <= .5f //&&
+// pBase[3] >= -.5f && pBase[3] <= .5f
+ )
{
t = std::min(t, tBase);
}
diff --git a/src/intersect/normals.cpp b/src/intersect/normals.cpp
index 84db534..f9b0ea1 100644
--- a/src/intersect/normals.cpp
+++ b/src/intersect/normals.cpp
@@ -2,6 +2,7 @@
// Created by Michael Foiani on 11/4/23.
//
+#include <iostream>
#include "raytracer/raytracer.h"
glm::vec4 getConeNormal(
@@ -11,7 +12,7 @@ glm::vec4 getConeNormal(
{
return {0.f, -1.f, 0.f, 0.f};
}
- if (RayTracer::floatEquals(intersectPointObject[3], -.5f)) // normal for w base
+ if (RayTracer::floatEquals(intersectPointObject.w, -.5f)) // normal for w base
{
return {0.f, 0.f, 0.f, -1.f};
}
@@ -19,7 +20,7 @@ glm::vec4 getConeNormal(
{
return {0.f, 1.f, 0.f, 0.f};
}
- if (RayTracer::floatEquals(intersectPointObject[3], .5f)) // normal for w top
+ if (RayTracer::floatEquals(intersectPointObject.w, .5f)) // normal for w top
{
return {0.f, 0.f, 0.f, 1.f};
}
@@ -81,11 +82,11 @@ glm::vec4 getCubeNormal(
{
return {0.f, 0.f, 1.f, 0.f};
}
- if (RayTracer::floatEquals(intersectPointObject[3], -.5f)) // neg w
+ if (RayTracer::floatEquals(intersectPointObject.w, -.5f)) // neg w
{
return {0.f, 0.f, 0.f, -1.f};
}
- if (RayTracer::floatEquals(intersectPointObject[3], .5f)) // pos w
+ if (RayTracer::floatEquals(intersectPointObject.w, .5f)) // pos w
{
return {0.f, 0.f, 0.f, 1.f};
}