mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 14:43:08 +02:00
git-subtree-dir: Programming/TRAK git-subtree-mainline:e11d703c3egit-subtree-split:777937fb9e
27 lines
782 B
C++
27 lines
782 B
C++
#ifndef PLANE_H
|
|
|
|
class Plane {
|
|
public:
|
|
Vector3 point; // A point on the plane
|
|
Vector3 normal; // Normal to the plane
|
|
Vector3 color;
|
|
|
|
Plane(const Vector3& p, const Vector3& n, const Vector3& col)
|
|
: point(p), normal(n.normalize()), color(col) {}
|
|
|
|
bool intersect(const Vector3& ray_origin, const Vector3& ray_direction, double& t, Vector3& hit_point, Vector3& hit_normal) const {
|
|
double denom = normal.dot(ray_direction);
|
|
if (std::abs(denom) > 1e-6) {
|
|
t = (point - ray_origin).dot(normal) / denom;
|
|
if (t >= 1e-4) {
|
|
hit_point = ray_origin + ray_direction * t;
|
|
hit_normal = normal;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
|
|
#endif |