diff options
author | Julian T <julian@jtle.dk> | 2020-08-11 21:21:02 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-08-11 21:21:02 +0200 |
commit | 690b72664ca8d471f5c117f6ed87aeae2de0a208 (patch) | |
tree | 8bc30efc009462d4390ac6eb8fe28ccbdbbd88a1 /src/object.cpp | |
parent | 3b8893902ac5f529faf15accaa3fb5360771d3b3 (diff) |
Defuse coloring
Diffstat (limited to 'src/object.cpp')
-rw-r--r-- | src/object.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/object.cpp b/src/object.cpp index 179785a..6c61d07 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -4,12 +4,27 @@ #include <iostream> #include "common.hpp" -Sphere::Sphere(Vec3d center, double radius) { +void Color::clamp() { + if (m_x > 1) { m_x = 1; } + if (m_y > 1) { m_y = 1; } + if (m_z > 1) { m_z = 1; } +} + +Material::Material(Color color, double defuse) { + m_color = color; + m_defuse = defuse; +} + +Color Material::reflect(const Vec3d &normal, const Vec3d &in, const Vec3d &out) const { + return Vec3d(m_color) * (out.dot(normal) * m_defuse); +} + +Sphere::Sphere(const Material &mat, Vec3d center, double radius) : Shape(mat) { m_center = center; m_radius = radius; } -Plane::Plane(Vec3d start, Vec3d norm) { +Plane::Plane(const Material &mat, Vec3d start, Vec3d norm) : Shape(mat) { m_start = start; m_norm = norm; |