Updates for Plane

This commit is contained in:
Eryn Wells 2014-08-09 10:58:30 -07:00
parent 392871a1ee
commit 590f10a756
2 changed files with 42 additions and 46 deletions

View file

@ -10,22 +10,28 @@
#include <cstdlib>
#include <cstdio>
#include "basics.h"
#include "object.h"
#include "objectPlane.hh"
using charles::basics::Ray;
using charles::basics::Vector4;
namespace charles {
/*
* charles::Plane::Plane --
*/
Plane::Plane()
: mNormal(Vector3::Y),
: mNormal(0, 1, 0),
mDistance(0.0)
{ }
const Vector3&
/*
* charles::Plane::GetNormal --
*/
const Vector4&
Plane::GetNormal()
const
{
@ -33,13 +39,19 @@ Plane::GetNormal()
}
/*
* charles::Plane::SetNormal --
*/
void
Plane::SetNormal(const Vector3& normal)
Plane::SetNormal(const Vector4& normal)
{
mNormal = normal.normalized();
mNormal = basics::Normalized(normal);
}
/*
* charles::Plane::GetDistance --
*/
Double
Plane::GetDistance()
const
@ -48,6 +60,9 @@ Plane::GetDistance()
}
/*
* charles::Plane::SetDistance --
*/
void
Plane::SetDistance(Double distance)
{
@ -59,9 +74,9 @@ Plane::SetDistance(Double distance)
* charles::Plane::DoesIntersect --
*/
bool
Plane::DoesIntersect(const Ray &ray,
TVector& t,
Stats& stats)
Plane::DoIntersect(const Ray& ray,
TVector& t,
Stats& stats)
const
{
/*
@ -94,14 +109,14 @@ Plane::DoesIntersect(const Ray &ray,
stats.planeIntersectionTests++;
/* The denominator for the t equation above. */
Double vd = mNormal.dot(ray.direction);
Double vd = mNormal.Dot(ray.direction);
if (NearZero(vd)) {
/* The ray is parallel to the plane. */
return false;
}
/* The numerator of the equation for t above. */
Double vo = -(mNormal.dot(ray.origin) + mDistance);
Double vo = -(mNormal.Dot(ray.origin) + mDistance);
Double t0 = vo / vd;
if (t0 < 0.0) {
@ -119,33 +134,14 @@ Plane::DoesIntersect(const Ray &ray,
}
/*
* charles::Plane::point_is_on_surface --
*/
bool
Plane::point_is_on_surface(const Vector3 &p)
const
{
/*
* Plug point p into the equation for a plane:
*
* A * x + B * y + C * z + D = 0
*
* where (A, B, C) are the coordinates of the normal vector, and D is the
* distance along that vector from the origin.
*/
return NearZero(mNormal.dot(p) + mDistance);
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
/*
* charles::Plane::compute_normal --
* charles::Plane::DoNormal --
*/
Vector3
Plane::compute_normal(const Vector3 &p)
Vector4
Plane::DoNormal(const Vector4& p)
const
{
return mNormal;
@ -154,6 +150,9 @@ Plane::compute_normal(const Vector3 &p)
#pragma clang diagnostic pop
/*
* charles::Plane::Write --
*/
void
Plane::Write(std::ostream& ost)
const

View file

@ -8,9 +8,9 @@
#ifndef __OBJECT_PLANE_H__
#define __OBJECT_PLANE_H__
#include "basics.h"
#include "object.h"
#include "types.hh"
#include "object.hh"
#include "basics/basics.hh"
namespace charles {
@ -21,25 +21,22 @@ public:
/** Default constructor. Creates a plane with a normal along the Y axis. */
Plane();
const Vector3& GetNormal() const;
void SetNormal(const Vector3& normal);
const basics::Vector4& GetNormal() const;
void SetNormal(const basics::Vector4& normal);
Double GetDistance() const;
void SetDistance(Double distance);
/**
* @see charles::Object::DoesIntersect
*/
bool DoesIntersect(const Ray &ray, TVector& t, Stats& stats) const;
bool point_is_on_surface(const Vector3 &p) const;
Vector3 compute_normal(const Vector3 &p) const;
/** @see charles::Object::Write */
void Write(std::ostream& ost) const;
protected:
bool DoIntersect(const basics::Ray& ray, TVector& t, Stats& stats) const;
basics::Vector4 DoNormal(const basics::Vector4& p) const;
private:
/** A normal vector, which specified the orientation of the plane. */
Vector3 mNormal;
basics::Vector4 mNormal;
/**
* The distance from the origin along the normal vector that this plane is