From 690b72664ca8d471f5c117f6ed87aeae2de0a208 Mon Sep 17 00:00:00 2001 From: Julian T Date: Tue, 11 Aug 2020 21:21:02 +0200 Subject: Defuse coloring --- src/object.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/object.cpp') 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 #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; -- cgit v1.2.3