diff options
author | 53hornet <53hornet@gmail.com> | 2019-02-02 23:33:15 -0500 |
---|---|---|
committer | 53hornet <53hornet@gmail.com> | 2019-02-02 23:33:15 -0500 |
commit | db072ad4dc181eca5a1458656b130beb43f475bf (patch) | |
tree | a3c03c7f5497cb70503e2486662fa85cfb53415a /hw4/include/intersectionPoint.h | |
download | csci427-master.tar.xz csci427-master.zip |
Diffstat (limited to 'hw4/include/intersectionPoint.h')
-rw-r--r-- | hw4/include/intersectionPoint.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/hw4/include/intersectionPoint.h b/hw4/include/intersectionPoint.h new file mode 100644 index 0000000..ed465d5 --- /dev/null +++ b/hw4/include/intersectionPoint.h @@ -0,0 +1,110 @@ +/******************************************************************/ +/* This file is part of the homework assignments for CSCI-427/527 */ +/* at The College of William & Mary and authored by Pieter Peers. */ +/* No part of this file, whether altered or in original form, can */ +/* be distributed or used outside the context of CSCI-427/527 */ +/* without consent of either the College of William & Mary or */ +/* Pieter Peers. */ +/******************************************************************/ +#ifndef _INTERSECTIONPOINT_H_ +#define _INTERSECTIONPOINT_H_ + +#include <memory> +#include <ostream> + +#include "ray.h" +#include "vec3d.h" +#include "vec2d.h" +#include "color.h" +#include "constants.h" +#include "lightSample.h" +#include "transformation3d.h" +#include "shaderProperties.h" +#include "coordinateTransform.h" + + +class intersectionPoint +{ + public: + ///////////////// + // Constructor // + ///////////////// + intersectionPoint(void); + intersectionPoint(const ray& r, float rayParameter=+LARGE, const std::shared_ptr<const class shader_base>& shader=nullptr, const vec3d& normal=vec3d(0.0f, 0.0f, 1.0f), const vec3d& axis=vec3d(1.0f, 0.0f, 0.0f), const vec2d& textureCoordinate=vec2d(0.0f, 0.0f)); + intersectionPoint(const intersectionPoint& ip); + + /////////////// + // Operators // + /////////////// + intersectionPoint& operator=(const intersectionPoint& ip); + + bool operator<(const intersectionPoint& ip) const; + bool operator>(const intersectionPoint& ip) const; + bool operator<(const lightSample& ls) const; + bool operator>(const lightSample& ls) const; + + //////////////// + // Inspectors // + //////////////// + bool isHit(void) const; + bool hasShader(void) const; + shaderProperties getShaderProperties(void) const; + float distance(const intersectionPoint& ip) const; + const vec3d& position(void) const; + const vec3d& direction(void) const; + const vec2d& textureCoordinate(void) const; + const vec3d& normal(void) const; + coordinateTransformation shadingFrame(void) const; + + ////////////// + // Mutators // + ////////////// + void transform(const transformation3d& t); + void inverseTransform(const transformation3d& t); + + void transformShadingFrame(const transformation3d& sft); + void inverseTransformShadingFrame(const transformation3d& sft); + + void setShader(const std::shared_ptr<const class shader_base>& shader); + + ///////////// + // Methods // + ///////////// + color shade(const vec3d& out) const; + color shade(const lightSample& ls) const; + + ///////////// + // Friends // + ///////////// + friend void swap(intersectionPoint& a, intersectionPoint& b) { a._swap(b); } + + friend bool operator<(const lightSample& ls, const intersectionPoint& ip) { return (ip > ls); } + friend bool operator>(const lightSample& ls, const intersectionPoint& ip) { return (ip < ls); } + + friend std::ostream& operator<<(std::ostream& s, const intersectionPoint& ip) + { + if(ip._hit) s << "IntersectionPoint: ray=" << ip._ray << ", position=" << ip._position << " (parameter=" << ip._rayParameter << ", normal=" << ip._normal << ", shading axis=" << ip._axis << ", texture coordinate=" << ip._textureCoordinate; + else s << "IntersectionPoint: empty"; + return s; + } + + private: + ///////////////////// + // Private Methods // + ///////////////////// + void _assign(const intersectionPoint& ip); + void _swap(intersectionPoint& ip); + + ////////////////// + // Data Members // + ////////////////// + ray _ray; + bool _hit; + float _rayParameter; + vec3d _position; + vec3d _normal, _axis; + vec2d _textureCoordinate; + std::shared_ptr<const class shader_base> _shader; +}; + +#endif /* _INTERSECTIONPOINT_H_ */ |