aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/common.hpp2
-rw-r--r--src/core/random.hpp20
-rw-r--r--src/core/spectrum.hpp2
-rw-r--r--src/core/vector.cpp14
-rw-r--r--src/core/vector.hpp17
5 files changed, 53 insertions, 2 deletions
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<double>::infinity()
+#define INFTY std::numeric_limits<double>::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 <random>
+
+// 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<double> 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 <cmath>
#include <math.h>
#include <stdexcept>
+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 <iostream>
+#include <math.h>
+
+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();