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. --- hw5/include/triangle.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 hw5/include/triangle.h (limited to 'hw5/include/triangle.h') diff --git a/hw5/include/triangle.h b/hw5/include/triangle.h new file mode 100644 index 0000000..f7d85bf --- /dev/null +++ b/hw5/include/triangle.h @@ -0,0 +1,115 @@ +/******************************************************************/ +/* 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 _TRIANGLE_H_ +#define _TRIANGLE_H_ + +#include +#include +#include +#include + +#include "ray.h" +#include "vec2d.h" +#include "vec3d.h" +#include "boundingBox.h" + +class triangle { + public: + ////////////////// + // Constructors // + ////////////////// + triangle(void); + triangle(const triangle& t); + triangle(triangle&& t); + + triangle(const vec3d& v1, const vec3d& v2, const vec3d& v3); + triangle(size_t v1_idx, size_t v2_idx, size_t v3_idx, const std::shared_ptr>& vertex_list); + + triangle(const vec3d& v1, const vec3d& v2, const vec3d& v3, + const vec3d& n1, const vec3d& n2, const vec3d& n3); + triangle(size_t v1_idx, size_t v2_idx, size_t v3_idx, const std::shared_ptr>& vertex_list, + size_t n1_idx, size_t n2_idx, size_t n3_idx, const std::shared_ptr>& normal_list); + + triangle(const vec3d& v1, const vec3d& v2, const vec3d& v3, + const vec2d& t1, const vec2d& t2, const vec2d& t3); + triangle(size_t v1_idx, size_t v2_idx, size_t v3_idx, const std::shared_ptr>& vertex_list, + size_t t1_idx, size_t t2_idx, size_t t3_idx, const std::shared_ptr>& texcoord_list); + + triangle(const vec3d& v1, const vec3d& v2, const vec3d& v3, + const vec3d& n1, const vec3d& n2, const vec3d& n3, + const vec2d& t1, const vec2d& t2, const vec2d& t3); + triangle(size_t v1_idx, size_t v2_idx, size_t v3_idx, const std::shared_ptr>& vertex_list, + size_t n1_idx, size_t n2_idx, size_t n3_idx, const std::shared_ptr>& normal_list, + size_t t1_idx, size_t t2_idx, size_t t3_idx, const std::shared_ptr>& texcoord_list); + + //////////////// + // Inspectors // + //////////////// + const vec3d& vertex(size_t index) const; + const vec3d& normal(size_t index) const; + const vec2d& textureCoordinate(size_t index) const; + + bool hasPerVertexNormals(void) const; + bool hasPerVertexTextureCoordinates(void) const; + + /////////////// + // Operators // + /////////////// + triangle& operator=(const triangle& t); + triangle& operator=(triangle&& t); + + ///////////// + // Methods // + ///////////// + bool intersect(const ray& r, vec3d& barycentricCoord, float& t) const; + + boundingBox boundingbox(void) const; + vec3d vertex(const vec3d& barycentricCoord) const; + vec3d normal(void) const; + vec3d shadingAxis(void) const; + vec3d normal(const vec3d& barycentricCoord) const; + vec2d textureCoordinate(const vec3d& barycentricCoord) const; + + vec3d sample(float r1, float r2, vec3d& barycentricCoord, float& pdf) const; + float area(void) const; + + ///////////// + // Friends // + ///////////// + friend void swap(triangle& a, triangle& b) { a._swap(b); } + + friend std::ostream& operator<<(std::ostream& s, const triangle& t) + { + s << "Triangle: v=(" << t.vertex(0) << "," << t.vertex(1) << "," << t.vertex(2) << ")"; + if(t._normal_list) + s << ", n=(" << t.normal(0) << "," << t.normal(1) << "," << t.normal(2) << ")"; + if(t._textureCoord_list) + s << ", t=(" << t.textureCoordinate(0) << "," << t.textureCoordinate(1) << "," << t.textureCoordinate(2) << ")"; + return s; + } + +private: + ///////////////////// + // Private Methods // + ///////////////////// + void _assign(const triangle& t); + void _swap(triangle& t); + + ////////////////// + // Data Members // + ////////////////// + std::array _vertex_idx; + std::array _normal_idx; + std::array _textureCoord_idx; + std::shared_ptr> _vertex_list; + std::shared_ptr> _normal_list; + std::shared_ptr> _textureCoord_list; +}; + +#endif /* _TRIANGLE_H_ */ -- cgit v1.2.3