From 94217187eb2785939458f08d96c7b1b9e55439ab Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 17 Jan 2021 00:09:15 +0100 Subject: Minor changed and draft for random sampling --- src/core/common.hpp | 2 +- src/core/random.hpp | 20 ++++++++++++++++++++ src/core/spectrum.hpp | 2 +- src/core/vector.cpp | 14 ++++++++++++++ src/core/vector.hpp | 17 +++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/core/random.hpp (limited to 'src/core') diff --git a/src/core/common.hpp b/src/core/common.hpp index a3e682e..7965815 100644 --- a/src/core/common.hpp +++ b/src/core/common.hpp @@ -5,6 +5,6 @@ #define ZERO_APPROX 1e-6 -#define INFINITY std::numeric_limits::infinity() +#define INFTY std::numeric_limits::infinity() #endif diff --git a/src/core/random.hpp b/src/core/random.hpp new file mode 100644 index 0000000..bc6a173 --- /dev/null +++ b/src/core/random.hpp @@ -0,0 +1,20 @@ +#ifndef RANDOM_H +#define RANDOM_H + +#include + +// TODO think more about +class Random { + public: + Random(int seed = 0) : m_gen(seed), m_dist(0, 1) {} + + inline double getDouble() { + return m_dist(m_gen); + }; + + private: + std::minstd_rand m_gen; + std::uniform_real_distribution m_dist; +}; + +#endif diff --git a/src/core/spectrum.hpp b/src/core/spectrum.hpp index de9355d..2a293fa 100644 --- a/src/core/spectrum.hpp +++ b/src/core/spectrum.hpp @@ -16,7 +16,7 @@ public: Spectrum operator*(const Spectrum &o) const; Spectrum operator/(const Spectrum &o) const; - Spectrum clamp(double low = 0, double high = INFINITY) const; + Spectrum clamp(double low = 0, double high = INFTY) const; double R() const { return c[0]; } double G() const { return c[1]; } diff --git a/src/core/vector.cpp b/src/core/vector.cpp index 51d8e2e..c790741 100644 --- a/src/core/vector.cpp +++ b/src/core/vector.cpp @@ -1,8 +1,22 @@ #include "vector.hpp" +#include #include #include +Vec2d::Vec2d() { + set(0, 0); +} + +Vec2d::Vec2d(double x, double y) { + set(x, y); +} + +void Vec2d::set(double x, double y) { + m_x = x; + m_y = y; +} + Vec3d::Vec3d() { set(0, 0, 0); } diff --git a/src/core/vector.hpp b/src/core/vector.hpp index 20e8210..adc0bae 100644 --- a/src/core/vector.hpp +++ b/src/core/vector.hpp @@ -2,12 +2,29 @@ #define VECTOR_H #include +#include + +class Vec2d { + public: + Vec2d(); + Vec2d(double x, double y); + + void set(double x, double y); + + double m_x, m_y, m_z; +}; class Vec3d { public: Vec3d(); Vec3d(double x, double y, double z); + static inline Vec3d FromSpherical(double sinTheta, double cosTheta, double phi) { + return Vec3d(sinTheta * std::cos(phi), + sinTheta * std::sin(phi), + cosTheta); + } + void set(double x, double y, double z); void normalize(); -- cgit v1.2.3