Skip to content
Snippets Groups Projects
Commit fe5d63f6 authored by Yoel's avatar Yoel
Browse files

RectanglePlane refactor: New method used as intended

parent 5e3fd8e2
No related branches found
No related tags found
No related merge requests found
...@@ -30,11 +30,18 @@ std::optional<cam::Hit> RectanglePlane::intersect(const cam::Ray& r) const { ...@@ -30,11 +30,18 @@ std::optional<cam::Hit> RectanglePlane::intersect(const cam::Ray& r) const {
if (r.in_range(t) && std::abs(t_hitpoint.x()) <= width / 2 && if (r.in_range(t) && std::abs(t_hitpoint.x()) <= width / 2 &&
std::abs(t_hitpoint.z()) <= depth / 2) { std::abs(t_hitpoint.z()) <= depth / 2) {
return std::optional<cam::Hit>({t_hitpoint, n, t, material}); return std::optional<cam::Hit>(
{t_hitpoint, n, texture_coordinates(t_hitpoint), t, material});
} else { } else {
return std::nullopt; return std::nullopt;
} }
} }
std::pair<float, float> RectanglePlane::texture_coordinates(
const util::Vec3& pos) const {
return std::pair<float, float>(
{pos.x() / width + 0.5, pos.z() / depth + 0.5});
}
util::AxisAlignedBoundingBox RectanglePlane::bounds() const { util::AxisAlignedBoundingBox RectanglePlane::bounds() const {
return util::AxisAlignedBoundingBox(util::Vec3(-width / 2, 0, -depth / 2), return util::AxisAlignedBoundingBox(util::Vec3(-width / 2, 0, -depth / 2),
util::Vec3(width / 2, 0, depth / 2)); util::Vec3(width / 2, 0, depth / 2));
...@@ -44,8 +51,9 @@ util::SurfacePoint RectanglePlane::sampleLight() const { ...@@ -44,8 +51,9 @@ util::SurfacePoint RectanglePlane::sampleLight() const {
float x = util::disMinus1To1(util::gen) * width / 2; float x = util::disMinus1To1(util::gen) * width / 2;
// Z coord of the sampled point. // Z coord of the sampled point.
float z = util::disMinus1To1(util::gen) * depth / 2; float z = util::disMinus1To1(util::gen) * depth / 2;
return util::SurfacePoint(util::Vec3(x, 0, z), util::Vec3(0, 1, 0), util::Vec3 pos(x, 0, z);
material); return util::SurfacePoint(pos, util::Vec3(0, 1, 0),
texture_coordinates(pos), material);
// The sampled point will be in local coordinates. // The sampled point will be in local coordinates.
} }
util::Vec3 RectanglePlane::calculateLightEmission(const util::SurfacePoint& p, util::Vec3 RectanglePlane::calculateLightEmission(const util::SurfacePoint& p,
......
...@@ -9,6 +9,8 @@ class RectanglePlane : public Light, public Shape { ...@@ -9,6 +9,8 @@ class RectanglePlane : public Light, public Shape {
RectanglePlane(float width, float depth, bool twofaced, RectanglePlane(float width, float depth, bool twofaced,
const std::shared_ptr<material::Material>& material); const std::shared_ptr<material::Material>& material);
std::optional<cam::Hit> intersect(const cam::Ray& r) const override; std::optional<cam::Hit> intersect(const cam::Ray& r) const override;
std::pair<float, float> texture_coordinates(
const util::Vec3& pos) const override;
util::AxisAlignedBoundingBox bounds() const override; util::AxisAlignedBoundingBox bounds() const override;
util::SurfacePoint sampleLight() const override; util::SurfacePoint sampleLight() const override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment