mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
check if plane intersect with ray
This commit is contained in:
parent
0b38f93655
commit
bd99b001bb
1 changed files with 17 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "Geometry.h"
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
void Geometry::setTransform(const Matrix4f &transform) {
|
||||
this->transform = transform;
|
||||
}
|
||||
|
@ -13,4 +15,18 @@ bool Sphere::intersect(const Ray &r) const {
|
|||
return b * b - 4 * a * c >= 0;
|
||||
}
|
||||
|
||||
bool Rectangle::intersect(const Ray &r) const { return false; }
|
||||
bool Rectangle::intersect(const Ray &r) const {
|
||||
Vector3f normal = (p2 - p1).cross(p3 - p1).normalized();
|
||||
float d = normal.dot(p1);
|
||||
|
||||
float denom = normal.dot(r.getDirection());
|
||||
if (abs(denom) < 1e-6f)
|
||||
return false;
|
||||
|
||||
float t = (normal.dot(r.getOrigin() - p1) - d) / denom;
|
||||
if (t <= 0)
|
||||
return false;
|
||||
|
||||
Vector3f p = r.getOrigin() + t * r.getDirection();
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue