aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.DS_Storebin8196 -> 0 bytes
-rw-r--r--src/illuminate/illuminate.cpp2
-rw-r--r--src/intersect/intersect.cpp22
-rw-r--r--src/raytracer/raytracer.cpp2
4 files changed, 15 insertions, 11 deletions
diff --git a/src/.DS_Store b/src/.DS_Store
deleted file mode 100644
index 5d99fdf..0000000
--- a/src/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/src/illuminate/illuminate.cpp b/src/illuminate/illuminate.cpp
index a651924..d031e6d 100644
--- a/src/illuminate/illuminate.cpp
+++ b/src/illuminate/illuminate.cpp
@@ -93,4 +93,4 @@ glm::vec4 RayTracer::illuminatePixel(
illumination += reflect(intersectionWorld, normalWorld, incidentDir, shape, scene, depth + 1);
return illumination;
-} \ No newline at end of file
+}
diff --git a/src/intersect/intersect.cpp b/src/intersect/intersect.cpp
index 69512e3..d5ab015 100644
--- a/src/intersect/intersect.cpp
+++ b/src/intersect/intersect.cpp
@@ -59,11 +59,11 @@ glm::vec4 intersectCone(
isHit = false;
float t = FINF;
// updated to 4d
- // x^2 + y^2 - z^2 - w^2= 0, conic top
+ // x^2 + z^2 - y^2 - w^2= 0, conic top
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,8 @@ glm::vec4 intersectCone(
auto pwBase = p + twBase * d;
if (
twBase > 0 &&
- pwBase.x*pwBase.x + pwBase.z*pwBase.z <= pwBase.y*pwBase.y
+ pwBase.x*pwBase.x + pwBase.z*pwBase.z <= pwBase.y*pwBase.y + .25f &&
+ pwBase.y >= -.5f && pwBase.y <= .5f
)
{
t = std::min(t, twBase);
@@ -108,7 +109,8 @@ glm::vec4 intersectCone(
auto pyBase = p + tyBase * d;
if (
tyBase > 0 &&
- pyBase.x*pyBase.x + pyBase.z*pyBase.z <= pyBase[3]*pyBase[3]
+ pyBase.x*pyBase.x + pyBase.z*pyBase.z <= pyBase[3]*pyBase[3] +.25f &&
+ pyBase[3] >= -.5f && pyBase[3] <= .5f
)
{
t = std::min(t, tyBase);
@@ -172,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/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp
index 71a1c7f..4d48848 100644
--- a/src/raytracer/raytracer.cpp
+++ b/src/raytracer/raytracer.cpp
@@ -99,7 +99,7 @@ glm::vec4 RayTracer::getPixelFromRay(
continue;
}
- auto newIntersectionWorld = shape.ctm * newIntersectionObj;
+ auto newIntersectionWorld = Vec4Ops::transformPoint4(newIntersectionObj,shape.ctm,shape.translation4d);
float newDist = glm::distance(newIntersectionWorld, pWorld);
if (
newDist < minDist // closer intersection