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',
'object.cc',
'objectBox.cc',
'object_sphere.cc',
'objectPlane.cc',
'objectSphere.cc',
'reader_yaml.cc',
'scene.cc',
'stats.cc',

View file

@ -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"

View file

@ -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 */

View file

@ -5,8 +5,8 @@
* Eryn Wells <eryn@erynwells.me>
*/
#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<Sphere> 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__ */

View file

@ -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<Sphere>(mObject)->set_radius(radius);
std::dynamic_pointer_cast<Sphere>(mObject)->SetRadius(radius);
mSection = NoSection;
SetShouldExpectKey(true);
}

View file

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