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 "basics.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
|
using charles::basics::Vector4;
|
||||||
|
|
||||||
|
|
||||||
namespace charles {
|
namespace charles {
|
||||||
|
|
||||||
#pragma mark - Objects
|
#pragma mark - Objects
|
||||||
|
|
||||||
/*
|
Object::Object(const Vector4& origin)
|
||||||
* Object::Object --
|
: mTranslation(basics::TranslationMatrix(origin.X(), origin.Y(), origin.Z())),
|
||||||
*
|
|
||||||
* 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),
|
|
||||||
mMaterial()
|
mMaterial()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
Vector3
|
Vector3
|
||||||
Object::GetOrigin()
|
Object::GetOrigin()
|
||||||
const
|
const
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "stats.hh"
|
#include "stats.hh"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace charles {
|
namespace charles {
|
||||||
|
|
||||||
|
@ -25,8 +27,7 @@ struct Object
|
||||||
{
|
{
|
||||||
typedef std::shared_ptr<Object> Ptr;
|
typedef std::shared_ptr<Object> Ptr;
|
||||||
|
|
||||||
Object();
|
Object(const basics::Vector4& origin = basics::Vector4());
|
||||||
Object(Vector3 o);
|
|
||||||
virtual ~Object();
|
virtual ~Object();
|
||||||
|
|
||||||
Vector3 GetOrigin() const;
|
Vector3 GetOrigin() const;
|
||||||
|
|
|
@ -14,32 +14,19 @@
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "objectSphere.hh"
|
#include "objectSphere.hh"
|
||||||
|
|
||||||
|
|
||||||
|
using charles::basics::Vector4;
|
||||||
|
|
||||||
|
|
||||||
namespace charles {
|
namespace charles {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sphere::Sphere --
|
* charles::Sphere::Sphere --
|
||||||
*
|
|
||||||
* Default constructor. Create a Sphere with radius 1.0.
|
|
||||||
*/
|
*/
|
||||||
Sphere::Sphere()
|
Sphere::Sphere(const Vector4& origin,
|
||||||
: Sphere(1.0)
|
Double radius)
|
||||||
{ }
|
: Object(origin),
|
||||||
|
mRadius(radius)
|
||||||
|
|
||||||
/*
|
|
||||||
* 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)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,13 +56,10 @@ Sphere::DoesIntersect(const Ray& ray,
|
||||||
{
|
{
|
||||||
stats.sphereIntersectionTests++;
|
stats.sphereIntersectionTests++;
|
||||||
|
|
||||||
/* Origin of the vector in object space. */
|
|
||||||
Vector3 rayOriginObj = ray.origin - GetOrigin();
|
|
||||||
|
|
||||||
/* 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(ray.origin) * 2.0;
|
||||||
Double c = rayOriginObj.dot(rayOriginObj) - (mRadius * mRadius);
|
Double c = ray.origin.dot(ray.origin) - (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);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace charles {
|
namespace charles {
|
||||||
|
|
||||||
|
@ -17,9 +19,7 @@ class Sphere
|
||||||
: public Object
|
: public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Sphere();
|
Sphere(const basics::Vector4& origin = basics::Vector4(), Double radius = 1.0);
|
||||||
Sphere(Double r);
|
|
||||||
Sphere(Vector3 o, Double r);
|
|
||||||
|
|
||||||
Double GetRadius() const;
|
Double GetRadius() const;
|
||||||
void SetRadius(Double r);
|
void SetRadius(Double r);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue