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

CirclePlane now has the option to be twofaced

parent e90c8f13
No related branches found
No related tags found
No related merge requests found
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include "math.h" #include "math.h"
namespace shapes { namespace shapes {
CirclePlane::CirclePlane(float radius, CirclePlane::CirclePlane(float radius, bool twofaced,
const std::shared_ptr<material::Material>& material) const std::shared_ptr<material::Material>& material)
: radius(radius), material(material) { : radius(radius), twofaced(twofaced), material(material) {
} }
std::optional<cam::Hit> CirclePlane::intersect(const cam::Ray& r) const { std::optional<cam::Hit> CirclePlane::intersect(const cam::Ray& r) const {
util::Vec3 n(0, 1, 0); util::Vec3 n(0, 1, 0);
...@@ -18,15 +18,17 @@ std::optional<cam::Hit> CirclePlane::intersect(const cam::Ray& r) const { ...@@ -18,15 +18,17 @@ std::optional<cam::Hit> CirclePlane::intersect(const cam::Ray& r) const {
float a = util::dot(d, n); float a = util::dot(d, n);
if (a == 0) { if (a == 0) {
return std::nullopt; return std::nullopt;
} else if (a < 0) { } else if (a > 0) {
float t = -x0[1] / d[1]; if (twofaced)
util::Vec3 t_hitpoint = r(t); n = -n;
else
if (r.in_range(t) && t_hitpoint.length() <= radius) {
return std::optional<cam::Hit>({t_hitpoint, n, t, material});
} else {
return std::nullopt; return std::nullopt;
} }
float t = -x0[1] / d[1];
util::Vec3 t_hitpoint = r(t);
if (r.in_range(t) && t_hitpoint.length() <= radius) {
return std::optional<cam::Hit>({t_hitpoint, n, t, material});
} else { } else {
return std::nullopt; return std::nullopt;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace shapes { namespace shapes {
class CirclePlane : public Light, public Shape { class CirclePlane : public Light, public Shape {
public: public:
CirclePlane(float radius, CirclePlane(float radius, 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;
util::AxisAlignedBoundingBox bounds() const override; util::AxisAlignedBoundingBox bounds() const override;
...@@ -18,5 +18,6 @@ class CirclePlane : public Light, public Shape { ...@@ -18,5 +18,6 @@ class CirclePlane : public Light, public Shape {
private: private:
std::shared_ptr<material::Material> material; std::shared_ptr<material::Material> material;
const float radius; const float radius;
const bool twofaced;
}; };
} // namespace shapes } // namespace shapes
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