From db072ad4dc181eca5a1458656b130beb43f475bf Mon Sep 17 00:00:00 2001 From: 53hornet <53hornet@gmail.com> Date: Sat, 2 Feb 2019 23:33:15 -0500 Subject: Init. --- hw4/include/intersectionPoint.h | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 hw4/include/intersectionPoint.h (limited to 'hw4/include/intersectionPoint.h') 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 +#include + +#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& 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& 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 _shader; +}; + +#endif /* _INTERSECTIONPOINT_H_ */ -- cgit v1.2.3