Clean up constructors for Object and Sphere
Use default arguments instead of multiple constructors. I forgot about those! Use Vector4s all around.
This commit is contained in:
parent
8ccfbc0498
commit
ab9ac5e963
4 changed files with 28 additions and 49 deletions
|
@ -12,32 +12,26 @@
|
|||
#include "basics.h"
|
||||
#include "material.h"
|
||||
#include "object.h"
|
||||
#include "basics/basics.hh"
|
||||
|
||||
|
||||
using charles::basics::Vector4;
|
||||
|
||||
|
||||
namespace charles {
|
||||
|
||||
#pragma mark - Objects
|
||||
|
||||
/*
|
||||
* Object::Object --
|
||||
*
|
||||
* Default constructor. Create a new Object with an origin at (0, 0, 0).
|
||||
*/
|
||||
Object::Object()
|
||||
: Object(Vector3::Zero)
|
||||
{ }
|
||||
|
||||
|
||||
/*
|
||||
* Object::Object --
|
||||
*
|
||||
* Constructor. Create a new Object with an origin at o.
|
||||
*/
|
||||
Object::Object(Vector3 origin)
|
||||
: mOrigin(origin),
|
||||
Object::Object(const Vector4& origin)
|
||||
: mTranslation(basics::TranslationMatrix(origin.X(), origin.Y(), origin.Z())),
|
||||
mMaterial()
|
||||
{ }
|
||||
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
|
||||
Vector3
|
||||
Object::GetOrigin()
|
||||
const
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "stats.hh"
|
||||
#include "texture.h"
|
||||
#include "types.hh"
|
||||
#include "basics/basics.hh"
|
||||
|
||||
|
||||
namespace charles {
|
||||
|
||||
|
@ -25,8 +27,7 @@ struct Object
|
|||
{
|
||||
typedef std::shared_ptr<Object> Ptr;
|
||||
|
||||
Object();
|
||||
Object(Vector3 o);
|
||||
Object(const basics::Vector4& origin = basics::Vector4());
|
||||
virtual ~Object();
|
||||
|
||||
Vector3 GetOrigin() const;
|
||||
|
|
|
@ -14,32 +14,19 @@
|
|||
#include "object.h"
|
||||
#include "objectSphere.hh"
|
||||
|
||||
|
||||
using charles::basics::Vector4;
|
||||
|
||||
|
||||
namespace charles {
|
||||
|
||||
/*
|
||||
* Sphere::Sphere --
|
||||
*
|
||||
* Default constructor. Create a Sphere with radius 1.0.
|
||||
* charles::Sphere::Sphere --
|
||||
*/
|
||||
Sphere::Sphere()
|
||||
: Sphere(1.0)
|
||||
{ }
|
||||
|
||||
|
||||
/*
|
||||
* Sphere::Sphere --
|
||||
*
|
||||
* Constructor. Create a Sphere with the given radius.
|
||||
*/
|
||||
Sphere::Sphere(Double r)
|
||||
: Sphere(Vector3::Zero, r)
|
||||
{ }
|
||||
|
||||
|
||||
Sphere::Sphere(Vector3 o,
|
||||
Double r)
|
||||
: Object(o),
|
||||
mRadius(r)
|
||||
Sphere::Sphere(const Vector4& origin,
|
||||
Double radius)
|
||||
: Object(origin),
|
||||
mRadius(radius)
|
||||
{ }
|
||||
|
||||
|
||||
|
@ -69,13 +56,10 @@ Sphere::DoesIntersect(const Ray& ray,
|
|||
{
|
||||
stats.sphereIntersectionTests++;
|
||||
|
||||
/* Origin of the vector in object space. */
|
||||
Vector3 rayOriginObj = ray.origin - GetOrigin();
|
||||
|
||||
/* Coefficients for quadratic equation. */
|
||||
Double a = ray.direction.dot(ray.direction);
|
||||
Double b = ray.direction.dot(rayOriginObj) * 2.0;
|
||||
Double c = rayOriginObj.dot(rayOriginObj) - (mRadius * mRadius);
|
||||
Double b = ray.direction.dot(ray.origin) * 2.0;
|
||||
Double c = ray.origin.dot(ray.origin) - (mRadius * mRadius);
|
||||
|
||||
/* Discriminant for the quadratic equation. */
|
||||
Double discrim = (b * b) - (4.0 * a * c);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "basics.h"
|
||||
#include "object.h"
|
||||
#include "basics/basics.hh"
|
||||
|
||||
|
||||
namespace charles {
|
||||
|
||||
|
@ -17,9 +19,7 @@ class Sphere
|
|||
: public Object
|
||||
{
|
||||
public:
|
||||
Sphere();
|
||||
Sphere(Double r);
|
||||
Sphere(Vector3 o, Double r);
|
||||
Sphere(const basics::Vector4& origin = basics::Vector4(), Double radius = 1.0);
|
||||
|
||||
Double GetRadius() const;
|
||||
void SetRadius(Double r);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue