work on raytracing

This commit is contained in:
2017-09-06 08:34:20 +02:00
parent c21925e86f
commit e4cd9c6b8d
32 changed files with 2790 additions and 3 deletions

63
tests/geo/TestSphere3.cpp Normal file
View File

@@ -0,0 +1,63 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../geo/Sphere3.h"
TEST(Sphere3, contains) {
Sphere3 a(Point3(0,0,0), 10);
Sphere3 b1(Point3(8,0,0), 1);
Sphere3 b2(Point3(0,8,0), 1);
Sphere3 b3(Point3(0,0,8), 1);
ASSERT_TRUE(a.contains(b1));
ASSERT_TRUE(a.contains(b2));
ASSERT_TRUE(a.contains(b3));
ASSERT_FALSE(b1.contains(a));
ASSERT_FALSE(b2.contains(a));
ASSERT_FALSE(b3.contains(a));
Sphere3 c1(Point3(8,0,0), 2.01);
Sphere3 c2(Point3(0,8,0), 2.01);
Sphere3 c3(Point3(0,0,8), 2.01);
ASSERT_FALSE(a.contains(c1));
ASSERT_FALSE(a.contains(c2));
ASSERT_FALSE(a.contains(c3));
ASSERT_FALSE(c1.contains(a));
ASSERT_FALSE(c2.contains(a));
ASSERT_FALSE(c3.contains(a));
}
TEST(Sphere3, join) {
// no overlap
Sphere3 a1(Point3(-1,0,0), 1);
Sphere3 a2(Point3(+1,0,0), 1);
Sphere3 a3 = Sphere3::join(a1, a2);
ASSERT_EQ(Point3(0,0,0), a3.center);
ASSERT_EQ(2, a3.radius);
// overlap
Sphere3 b1(Point3(-1,0,0), 1.5);
Sphere3 b2(Point3(+1,0,0), 1.5);
Sphere3 b3 = Sphere3::join(b1, b2);
ASSERT_EQ(Point3(0,0,0), b3.center);
ASSERT_EQ(2.5, b3.radius);
// fully within
Sphere3 c1(Point3(-1,0,0), 3.6);
Sphere3 c2(Point3(+1,0,0), 1.5);
Sphere3 c3 = Sphere3::join(c1, c2);
ASSERT_EQ(c1.center, c3.center);
ASSERT_EQ(c1.radius, c3.radius);
Sphere3 c4 = Sphere3::join(c2, c1);
ASSERT_EQ(c1.center, c4.center);
ASSERT_EQ(c1.radius, c4.radius);
}
#endif

View File

@@ -0,0 +1,36 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../geo/Triangle3.h"
// https://stackoverflow.com/questions/17458562/efficient-aabb-triangle-intersection-in-c-sharp
// http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/tribox3.txt
TEST(Triangle3, intersect) {
Point3 dst;
{
Triangle3 tria(Point3(-1,0,0), Point3(+1,0,0), Point3(0,1,0));
Ray3 ray(Point3(0,0.5,-1), Point3(0,0,1));
ASSERT_TRUE(tria.intersects(ray, dst));
ASSERT_EQ(Point3(0, 0.5, 0), dst);
}
{
Triangle3 tria(Point3(-1,0,0), Point3(+1,0,0), Point3(0,1,1));
Ray3 ray(Point3(0,0.5,-1), Point3(0,0,1));
ASSERT_TRUE(tria.intersects(ray, dst));
ASSERT_EQ(Point3(0, 0.5, 0.5), dst);
}
{
Triangle3 tria(Point3(10.4253730774, 49.0029830933, 0.00995028018951), Point3(10.4253730774, 49.0029830933, 3.99004983902), Point3(10.4253730774, 50.197013855, 3.99004983902));
Ray3 ray(Point3(67.2000045776, 36.0, 3.5), Point3(0.154123231769, -0.631025910378, -0.76029753685));
ASSERT_FALSE(tria.intersects(ray, dst));
}
}
#endif