From 9e9d7351bdf2562d3b54c6d639a6460276ba73d8 Mon Sep 17 00:00:00 2001 From: vonhyou Date: Thu, 14 Mar 2024 18:43:28 -0400 Subject: [PATCH] reformat ray and hitrecord --- src/Geometry.cc | 12 ++++++------ src/HitRecord.cc | 12 ++++++------ src/HitRecord.h | 10 +++++----- src/Light.cc | 2 +- src/Ray.cc | 4 ++-- src/Ray.h | 10 +++++----- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Geometry.cc b/src/Geometry.cc index 9e3a87c..6b544c4 100644 --- a/src/Geometry.cc +++ b/src/Geometry.cc @@ -17,9 +17,9 @@ void Geometry::setTransform(const Matrix4f &transform) { } Optional Sphere::intersect(const Ray &r) const { - Vector3f originCenter = r.getOrigin() - center; - float a = r.getDirection().dot(r.getDirection()); - float b = 2.0f * originCenter.dot(r.getDirection()); + Vector3f originCenter = r.origin() - center; + float a = r.direction().dot(r.direction()); + float b = 2.0f * originCenter.dot(r.direction()); float c = originCenter.dot(originCenter) - radius * radius; float delta = b * b - 4 * a * c; @@ -52,15 +52,15 @@ bool isInRectangle(const Vector3f &p, const Vector3f &a, const Vector3f &b, } Optional Rectangle::intersect(const Ray &r) const { - float denom = normal_.dot(r.getDirection()); + float denom = normal_.dot(r.direction()); if (abs(denom) < 1e-6f) return Optional::nullopt; - float t = -normal_.dot(r.getOrigin() - p1) / denom; + float t = -normal_.dot(r.origin() - p1) / denom; if (t <= 0) return Optional::nullopt; - Vector3f p = r.getOrigin() + t * r.getDirection(); + Vector3f p = r.origin() + t * r.direction(); return isInRectangle(p, p1, p2, p3, p4, normal_) ? Optional(t) : Optional::nullopt; diff --git a/src/HitRecord.cc b/src/HitRecord.cc index d40c5b6..261e449 100644 --- a/src/HitRecord.cc +++ b/src/HitRecord.cc @@ -4,16 +4,16 @@ bool HitRecord::operator<(const HitRecord &other) const { return this->t > other.t; // to get the nearest t } -Geometry *HitRecord::geometry() const { return g; } +Geometry *HitRecord::geometry() const { return geometry_; } -Vector3f HitRecord::getPoint() const { - return r.getOrigin() + t * r.getDirection(); +Vector3f HitRecord::point() const { + return ray_.origin() + t * ray_.direction(); } Vector3f HitRecord::viewDirection() const { - return -r.getDirection().normalized(); + return -ray_.direction().normalized(); } -Vector3f HitRecord::normal() const { return n; } +Vector3f HitRecord::normal() const { return normal_; } -void HitRecord::calcNormal() { n = g->normal(getPoint()); } +void HitRecord::calcNormal() { normal_ = geometry_->normal(point()); } diff --git a/src/HitRecord.h b/src/HitRecord.h index c7fad17..599db5a 100644 --- a/src/HitRecord.h +++ b/src/HitRecord.h @@ -9,18 +9,18 @@ using Eigen::Vector3f; class HitRecord { public: - HitRecord(float t, const Ray &r, Geometry *g) : t(t), r(r), g(g) {} + HitRecord(float t, const Ray &r, Geometry *g) : t(t), ray_(r), geometry_(g) {} bool operator<(const HitRecord &) const; private: float t; - Ray r; - Vector3f n; - Geometry *g; + Ray ray_; + Vector3f normal_; + Geometry *geometry_; public: Geometry *geometry() const; - Vector3f getPoint() const; + Vector3f point() const; Vector3f viewDirection() const; Vector3f normal() const; void calcNormal(); diff --git a/src/Light.cc b/src/Light.cc index 0aa9539..ba199b8 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -20,7 +20,7 @@ bool Light::isUse() const { return use; } Vector3f PointLight::illumination(const HitRecord &hit, const vector &geometries) const { - Vector3f shadingPoint = hit.getPoint(); + Vector3f shadingPoint = hit.point(); Vector3f rayDirection = (center - shadingPoint).normalized(); Geometry *geometry = hit.geometry(); Ray shadowRay(shadingPoint, rayDirection); diff --git a/src/Ray.cc b/src/Ray.cc index 4cafd1d..fddd2f5 100644 --- a/src/Ray.cc +++ b/src/Ray.cc @@ -1,5 +1,5 @@ #include "Ray.h" -Vector3f Ray::getOrigin() const { return origin; } +Vector3f Ray::origin() const { return origin_; } -Vector3f Ray::getDirection() const { return direction; } +Vector3f Ray::direction() const { return direction_; } diff --git a/src/Ray.h b/src/Ray.h index 9fe5b37..a344e5d 100644 --- a/src/Ray.h +++ b/src/Ray.h @@ -7,15 +7,15 @@ using Eigen::Vector3f; class Ray { public: - Ray(const Vector3f &o, const Vector3f &d) : origin(o), direction(d) {} + Ray(const Vector3f &o, const Vector3f &d) : origin_(o), direction_(d) {} private: - Vector3f origin; - Vector3f direction; + Vector3f origin_; + Vector3f direction_; public: - Vector3f getOrigin() const; - Vector3f getDirection() const; + Vector3f origin() const; + Vector3f direction() const; }; #endif // !RAY_H_