29 lines
923 B
C++
29 lines
923 B
C++
#include "InfinitePlane.h"
|
|
#include "RenderObject.h"
|
|
#include <iostream>
|
|
|
|
raytry::InfinitePlane::InfinitePlane() : zLevel{0.0f}, normalVec{0.0, 0.0, 1.0} {}
|
|
|
|
raytry::InfinitePlane::InfinitePlane(float zLevel, QVector3D normalVec) : zLevel{zLevel}, normalVec{normalVec} {}
|
|
|
|
std::optional<float> raytry::InfinitePlane::intersects(const Ray &ray) const {
|
|
auto normalDotDir = QVector3D::dotProduct(normalVec, ray.directionVec);
|
|
if (qFuzzyIsNull(normalDotDir)) {
|
|
return std::nullopt;
|
|
}
|
|
auto t = (-QVector3D::dotProduct(normalVec, ray.originVec) - zLevel) / normalDotDir;
|
|
if (t < RenderObject::nearCrop) {
|
|
return std::nullopt;
|
|
} else {
|
|
return std::make_optional<float>(t);
|
|
}
|
|
}
|
|
|
|
raytry::RenderMaterial raytry::InfinitePlane::material() const {
|
|
return {{240, 240, 240}};
|
|
}
|
|
|
|
QVector3D raytry::InfinitePlane::calculateNormal(QVector3D hitpoint) const {
|
|
return normalVec;
|
|
}
|