From b1c818ac20e6715d5da9e1e5319620dbfd7998fe Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 3 Aug 2014 17:35:12 -0700 Subject: [PATCH] Modernize object_sphere Rename files objectSphere. Clean up dependencies. --- src/SConscript | 2 +- src/charles.cc | 3 -- src/{object_sphere.cc => objectSphere.cc} | 39 +++++++++++------------ src/{object_sphere.h => objectSphere.hh} | 18 +++++------ src/yaml/objectParser.cc | 4 +-- src/yaml/objectParser.hh | 1 - 6 files changed, 29 insertions(+), 38 deletions(-) rename src/{object_sphere.cc => objectSphere.cc} (83%) rename src/{object_sphere.h => objectSphere.hh} (70%) diff --git a/src/SConscript b/src/SConscript index 517ae22..a3dffe4 100644 --- a/src/SConscript +++ b/src/SConscript @@ -24,8 +24,8 @@ files = [ 'material.cc', 'object.cc', 'objectBox.cc', - 'object_sphere.cc', 'objectPlane.cc', + 'objectSphere.cc', 'reader_yaml.cc', 'scene.cc', 'stats.cc', diff --git a/src/charles.cc b/src/charles.cc index 1e4621e..22260fe 100644 --- a/src/charles.cc +++ b/src/charles.cc @@ -11,9 +11,6 @@ #include "basics.h" #include "log.hh" #include "light.h" -#include "material.h" -#include "object_sphere.h" -//#include "object_plane.h" #include "reader_yaml.hh" #include "scene.h" #include "writer_png.h" diff --git a/src/object_sphere.cc b/src/objectSphere.cc similarity index 83% rename from src/object_sphere.cc rename to src/objectSphere.cc index 863be39..5adfb4d 100644 --- a/src/object_sphere.cc +++ b/src/objectSphere.cc @@ -12,7 +12,7 @@ #include "basics.h" #include "object.h" -#include "object_sphere.h" +#include "objectSphere.hh" namespace charles { @@ -31,33 +31,30 @@ Sphere::Sphere() * * Constructor. Create a Sphere with the given radius. */ -Sphere::Sphere(float r) +Sphere::Sphere(Double r) : Sphere(Vector3::Zero, r) { } -Sphere::Sphere(Vector3 o, float r) +Sphere::Sphere(Vector3 o, + Double r) : Object(o), - radius(r) + mRadius(r) { } -/* - * Sphere::get_radius -- - * Sphere::set_radius -- - * - * Get and set the radius of this Sphere. - */ -float -Sphere::get_radius() +Double +Sphere::GetRadius() + const { - return radius; + return mRadius; } + void -Sphere::set_radius(float r) +Sphere::SetRadius(Double r) { - radius = (radius >= 0.0) ? r : -r; + mRadius = std::fabs(r); } @@ -78,7 +75,7 @@ Sphere::DoesIntersect(const Ray& ray, /* Coefficients for quadratic equation. */ Double a = ray.direction.dot(ray.direction); Double b = ray.direction.dot(rayOriginObj) * 2.0; - Double c = rayOriginObj.dot(rayOriginObj) - (radius * radius); + Double c = rayOriginObj.dot(rayOriginObj) - (mRadius * mRadius); /* Discriminant for the quadratic equation. */ Double discrim = (b * b) - (4.0 * a * c); @@ -137,11 +134,11 @@ Sphere::point_is_on_surface(const Vector3 &p) const { Vector3 o = GetOrigin(); - float x = p.x - o.x; - float y = p.y - o.y; - float z = p.z - o.z; + Double x = p.x - o.x; + Double y = p.y - o.y; + Double z = p.z - o.z; - return x*x + y*y + z*z == radius*radius; + return x*x + y*y + z*z == mRadius*mRadius; } @@ -166,7 +163,7 @@ void Sphere::Write(std::ostream& ost) const { - ost << "[Sphere origin=" << GetOrigin() << " r=" << radius << "]"; + ost << "[Sphere origin=" << GetOrigin() << " r=" << mRadius << "]"; } } /* namespace charles */ diff --git a/src/object_sphere.h b/src/objectSphere.hh similarity index 70% rename from src/object_sphere.h rename to src/objectSphere.hh index 8792fe3..12f9061 100644 --- a/src/object_sphere.h +++ b/src/objectSphere.hh @@ -5,8 +5,8 @@ * Eryn Wells */ -#ifndef __OBJECT_SPHERE_H__ -#define __OBJECT_SPHERE_H__ +#ifndef __OBJECTSPHERE_HH__ +#define __OBJECTSPHERE_HH__ #include "basics.h" #include "object.h" @@ -17,14 +17,12 @@ class Sphere : public Object { public: - typedef std::shared_ptr Ptr; - Sphere(); - Sphere(float r); - Sphere(Vector3 o, float r); + Sphere(Double r); + Sphere(Vector3 o, Double r); - float get_radius(); - void set_radius(float r); + Double GetRadius() const; + void SetRadius(Double r); bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const; bool point_is_on_surface(const Vector3 &p) const; @@ -34,9 +32,9 @@ public: void Write(std::ostream& ost) const; private: - float radius; + Double mRadius; }; } /* namespace charles */ -#endif +#endif /* __OBJECTSPHERE_HH__ */ diff --git a/src/yaml/objectParser.cc b/src/yaml/objectParser.cc index 660a540..f21b511 100644 --- a/src/yaml/objectParser.cc +++ b/src/yaml/objectParser.cc @@ -14,7 +14,7 @@ #include "object.h" #include "objectBox.hh" #include "objectPlane.hh" -#include "object_sphere.h" +#include "objectSphere.hh" #include "yaml/objectParser.hh" #include "yaml/vectorParser.hh" @@ -196,7 +196,7 @@ ObjectParser::HandleRadiusEvent(yaml_event_t& event) /* TODO: Clean this up. */ assert(false); } - std::dynamic_pointer_cast(mObject)->set_radius(radius); + std::dynamic_pointer_cast(mObject)->SetRadius(radius); mSection = NoSection; SetShouldExpectKey(true); } diff --git a/src/yaml/objectParser.hh b/src/yaml/objectParser.hh index ea5cd1f..80bf7e8 100644 --- a/src/yaml/objectParser.hh +++ b/src/yaml/objectParser.hh @@ -9,7 +9,6 @@ #ifndef __YAML_OBJECTPARSER_HH__ #define __YAML_OBJECTPARSER_HH__ -#include "object_sphere.h" #include "yaml/parsers.hh" #include "yaml/scalarMappingParser.hh"