Skip to content

src/core/ray.h

Namespaces

Name
dakku
dakku namespace

Classes

Name
class dakku::Ray
ray
class dakku::RayDifferential
differential ray

Source code

#ifndef DAKKU_CORE_RAY_H_
#define DAKKU_CORE_RAY_H_
#include <core/vector.h>
#include <core/constants.h>

namespace dakku {
class Ray {
 public:
  Ray() = default;
  explicit Ray(Point3f o, Vector3f d, float t_max = INF)
      : o(std::move(o)), d(std::move(d)), tMax(t_max) {}

  Point3f operator()(float t) const { return o + d * t; }

  [[nodiscard]] bool has_nans() const {
    return o.has_nans() || d.has_nans() || isnan(tMax);
  }

  Point3f o;
  Vector3f d;
  mutable float tMax{INF};
};

class RayDifferential : public Ray {
 public:
  RayDifferential() = default;

  explicit RayDifferential(const Point3f &o, const Vector3f &d,
                           float t_max = INF)
      : Ray(o, d, t_max) {}

  [[nodiscard]] bool has_nans() const {
    return Ray::has_nans() ||
           (has_differentials &&
            (rx_origin.has_nans() || ry_origin.has_nans() ||
             rx_direction.has_nans() || ry_direction.has_nans()));
  }

  void scale_differentials(float s) {
    rx_origin = o + (rx_origin - o) * s;
    ry_origin = o + (ry_origin - o) * s;
    rx_direction = d + (rx_direction - d) * s;
    ry_direction = d + (ry_direction - d) * s;
  }

  bool has_differentials{false};
  Point3f rx_origin;
  Point3f ry_origin;
  Vector3f rx_direction;
  Vector3f ry_direction;
};
}  // namespace dakku
#endif

Updated on 2022-04-30 at 15:46:11 +0000