/******************************************************************/ /* 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& U=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._U << ", 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, _U; vec2d _textureCoordinate; std::shared_ptr _shader; }; #endif /* _INTERSECTIONPOINT_H_ */