move sources to src directory
This commit is contained in:
1 parent
b5e4655f03
commit
24b4b48555
58 files changed
+7
-5
No files matched your search
@@ -0,0 +1,57 @@
|
||||
|
||||
#include "Plane.h"
|
||||
#include "util/Solver.h"
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
Plane::Plane(double a, double b, double c, double d)
|
||||
{
|
||||
m_a = a;
|
||||
m_b = b;
|
||||
m_c = c;
|
||||
m_d = d;
|
||||
m_normal = Vector(m_a, m_b, m_c);
|
||||
m_normal.normalize();
|
||||
}
|
||||
|
||||
Shape::IntersectionList Plane::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
{
|
||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||
|
||||
IntersectionList res;
|
||||
/*
|
||||
* Plane equation: ax + by + cz + d = 0
|
||||
* Ray equation: R = R0 + tRd
|
||||
* x = R0x + tRdx
|
||||
* y = R0y + tRdy
|
||||
* z = R0z + tRdz
|
||||
* Combined: a(R0x + tRdx) + b(R0y + tRdy) + c(R0z + tRdz) + d = 0
|
||||
* aR0x + (t)aRdx + bR0y + (t)bRdy + cR0z + (t)cRdz + d = 0
|
||||
* (t)(aRdx + bRdy + cRdz) + aR0x + bR0y + cR0z + d = 0
|
||||
*/
|
||||
LinearSolver solver( m_a * ray_inv.getDirection()[0]
|
||||
+ m_b * ray_inv.getDirection()[1]
|
||||
+ m_c * ray_inv.getDirection()[2],
|
||||
m_a * ray_inv.getOrigin()[0]
|
||||
+ m_b * ray_inv.getOrigin()[1]
|
||||
+ m_c * ray_inv.getOrigin()[2]
|
||||
+ m_d);
|
||||
Solver::Result solutions = solver.solve();
|
||||
if (solutions.numResults > 0)
|
||||
{
|
||||
if (solutions.results[0] > 0.0)
|
||||
{
|
||||
Vector isect_point = ray_inv[solutions.results[0]];
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point),
|
||||
m_transform.transform_normal(m_normal)));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
refptr<Shape> Plane::clone()
|
||||
{
|
||||
return new Plane(*this);
|
||||
}
|
||||
Reference in new issue
Block a user