add ray constructor

This commit is contained in:
Shuo Feng 2024-02-19 14:18:22 -05:00
parent 29c5fe91d9
commit e4e2d26a16
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
2 changed files with 23 additions and 2 deletions

View file

@ -4,6 +4,13 @@ void Geometry::setTransform(const Matrix4f &transform) {
this->transform = transform;
}
bool Sphere::intersect(const Ray &r) const { return false; }
bool Sphere::intersect(const Ray &r) const {
Vector3f originCenter = r.getOrigin() - center;
int a = r.getDirection().dot(r.getDirection());
int b = 2 * originCenter.dot(r.getDirection());
int c = originCenter.dot(originCenter) - radius * radius;
return b * b - 4 * a * c >= 0;
}
bool Rectangle::intersect(const Ray &r) const { return false; }