Modernize object_sphere

Rename files objectSphere. Clean up dependencies.
This commit is contained in:
Eryn Wells 2014-08-03 17:35:12 -07:00
parent a0fbecf483
commit b1c818ac20
6 changed files with 29 additions and 38 deletions

View file

@ -24,8 +24,8 @@ files = [
'material.cc', 'material.cc',
'object.cc', 'object.cc',
'objectBox.cc', 'objectBox.cc',
'object_sphere.cc',
'objectPlane.cc', 'objectPlane.cc',
'objectSphere.cc',
'reader_yaml.cc', 'reader_yaml.cc',
'scene.cc', 'scene.cc',
'stats.cc', 'stats.cc',

View file

@ -11,9 +11,6 @@
#include "basics.h" #include "basics.h"
#include "log.hh" #include "log.hh"
#include "light.h" #include "light.h"
#include "material.h"
#include "object_sphere.h"
//#include "object_plane.h"
#include "reader_yaml.hh" #include "reader_yaml.hh"
#include "scene.h" #include "scene.h"
#include "writer_png.h" #include "writer_png.h"

View file

@ -12,7 +12,7 @@
#include "basics.h" #include "basics.h"
#include "object.h" #include "object.h"
#include "object_sphere.h" #include "objectSphere.hh"
namespace charles { namespace charles {
@ -31,33 +31,30 @@ Sphere::Sphere()
* *
* Constructor. Create a Sphere with the given radius. * Constructor. Create a Sphere with the given radius.
*/ */
Sphere::Sphere(float r) Sphere::Sphere(Double r)
: Sphere(Vector3::Zero, r) : Sphere(Vector3::Zero, r)
{ } { }
Sphere::Sphere(Vector3 o, float r) Sphere::Sphere(Vector3 o,
Double r)
: Object(o), : Object(o),
radius(r) mRadius(r)
{ } { }
/* Double
* Sphere::get_radius -- Sphere::GetRadius()
* Sphere::set_radius -- const
*
* Get and set the radius of this Sphere.
*/
float
Sphere::get_radius()
{ {
return radius; return mRadius;
} }
void 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. */ /* Coefficients for quadratic equation. */
Double a = ray.direction.dot(ray.direction); Double a = ray.direction.dot(ray.direction);
Double b = ray.direction.dot(rayOriginObj) * 2.0; 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. */ /* Discriminant for the quadratic equation. */
Double discrim = (b * b) - (4.0 * a * c); Double discrim = (b * b) - (4.0 * a * c);
@ -137,11 +134,11 @@ Sphere::point_is_on_surface(const Vector3 &p)
const const
{ {
Vector3 o = GetOrigin(); Vector3 o = GetOrigin();
float x = p.x - o.x; Double x = p.x - o.x;
float y = p.y - o.y; Double y = p.y - o.y;
float z = p.z - o.z; 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) Sphere::Write(std::ostream& ost)
const const
{ {
ost << "[Sphere origin=" << GetOrigin() << " r=" << radius << "]"; ost << "[Sphere origin=" << GetOrigin() << " r=" << mRadius << "]";
} }
} /* namespace charles */ } /* namespace charles */

View file

@ -5,8 +5,8 @@
* Eryn Wells <eryn@erynwells.me> * Eryn Wells <eryn@erynwells.me>
*/ */
#ifndef __OBJECT_SPHERE_H__ #ifndef __OBJECTSPHERE_HH__
#define __OBJECT_SPHERE_H__ #define __OBJECTSPHERE_HH__
#include "basics.h" #include "basics.h"
#include "object.h" #include "object.h"
@ -17,14 +17,12 @@ class Sphere
: public Object : public Object
{ {
public: public:
typedef std::shared_ptr<Sphere> Ptr;
Sphere(); Sphere();
Sphere(float r); Sphere(Double r);
Sphere(Vector3 o, float r); Sphere(Vector3 o, Double r);
float get_radius(); Double GetRadius() const;
void set_radius(float r); void SetRadius(Double r);
bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const; bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const;
bool point_is_on_surface(const Vector3 &p) const; bool point_is_on_surface(const Vector3 &p) const;
@ -34,9 +32,9 @@ public:
void Write(std::ostream& ost) const; void Write(std::ostream& ost) const;
private: private:
float radius; Double mRadius;
}; };
} /* namespace charles */ } /* namespace charles */
#endif #endif /* __OBJECTSPHERE_HH__ */

View file

@ -14,7 +14,7 @@
#include "object.h" #include "object.h"
#include "objectBox.hh" #include "objectBox.hh"
#include "objectPlane.hh" #include "objectPlane.hh"
#include "object_sphere.h" #include "objectSphere.hh"
#include "yaml/objectParser.hh" #include "yaml/objectParser.hh"
#include "yaml/vectorParser.hh" #include "yaml/vectorParser.hh"
@ -196,7 +196,7 @@ ObjectParser::HandleRadiusEvent(yaml_event_t& event)
/* TODO: Clean this up. */ /* TODO: Clean this up. */
assert(false); assert(false);
} }
std::dynamic_pointer_cast<Sphere>(mObject)->set_radius(radius); std::dynamic_pointer_cast<Sphere>(mObject)->SetRadius(radius);
mSection = NoSection; mSection = NoSection;
SetShouldExpectKey(true); SetShouldExpectKey(true);
} }

View file

@ -9,7 +9,6 @@
#ifndef __YAML_OBJECTPARSER_HH__ #ifndef __YAML_OBJECTPARSER_HH__
#define __YAML_OBJECTPARSER_HH__ #define __YAML_OBJECTPARSER_HH__
#include "object_sphere.h"
#include "yaml/parsers.hh" #include "yaml/parsers.hh"
#include "yaml/scalarMappingParser.hh" #include "yaml/scalarMappingParser.hh"