diff --git a/src/engine/camera/Camera.cpp b/src/engine/camera/Camera.cpp index a5d6f19..0edd6c4 100644 --- a/src/engine/camera/Camera.cpp +++ b/src/engine/camera/Camera.cpp @@ -335,9 +335,9 @@ namespace fgl::engine createFrustum( const float aspect, const float fov_y, const float near, const float far ) { const Plane< CoordinateSpace::Model > near_plane { ModelCoordinate( constants::WORLD_FORWARD * near ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; + NormalVector( constants::WORLD_FORWARD ) }; const Plane< CoordinateSpace::Model > far_plane { ModelCoordinate( constants::WORLD_FORWARD * far ), - NormalVector::bypass( constants::WORLD_BACKWARD ) }; + NormalVector( constants::WORLD_BACKWARD ) }; const float half_height { far * glm::tan( fov_y / 2.0f ) }; const float half_width { half_height * aspect }; diff --git a/src/engine/primitives/Frustum.hpp b/src/engine/primitives/Frustum.hpp index 4d3ff05..ceb3181 100644 --- a/src/engine/primitives/Frustum.hpp +++ b/src/engine/primitives/Frustum.hpp @@ -19,17 +19,15 @@ namespace fgl::engine struct Frustum { Plane< CType > near { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; - Plane< CType > far { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; - Plane< CType > top { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; + NormalVector( constants::WORLD_FORWARD ) }; + Plane< CType > far { Coordinate< CType >( constants::WORLD_CENTER ), NormalVector( constants::WORLD_FORWARD ) }; + Plane< CType > top { Coordinate< CType >( constants::WORLD_CENTER ), NormalVector( constants::WORLD_FORWARD ) }; Plane< CType > bottom { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; + NormalVector( constants::WORLD_FORWARD ) }; Plane< CType > right { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; + NormalVector( constants::WORLD_FORWARD ) }; Plane< CType > left { Coordinate< CType >( constants::WORLD_CENTER ), - NormalVector::bypass( constants::WORLD_FORWARD ) }; + NormalVector( constants::WORLD_FORWARD ) }; Coordinate< CType > m_position {}; @@ -39,6 +37,7 @@ namespace fgl::engine Frustum() = default; + //TODO: Change this to be, near far, top bottom, left right Frustum( const Plane< CType > near_plane, const Plane< CType > far_plane, diff --git a/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp b/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp index ebfaf31..e53d824 100644 --- a/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp +++ b/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp @@ -67,11 +67,11 @@ namespace fgl::engine std::array< Coordinate< CType >, POINT_COUNT > points() const; std::array< LineSegment< CType >, LINE_COUNT > lines() const; - constexpr NormalVector right() const { return NormalVector::bypass( constants::WORLD_RIGHT ); } + constexpr NormalVector right() const { return NormalVector( constants::WORLD_RIGHT ); } - constexpr NormalVector up() const { return NormalVector::bypass( constants::WORLD_UP ); } + constexpr NormalVector up() const { return NormalVector( constants::WORLD_UP ); } - constexpr NormalVector forward() const { return NormalVector::bypass( constants::WORLD_FORWARD ); } + constexpr NormalVector forward() const { return NormalVector( constants::WORLD_FORWARD ); } }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/primitives/boxes/AxisAlignedBoundingCube.hpp b/src/engine/primitives/boxes/AxisAlignedBoundingCube.hpp index 2be7ef2..ecdae94 100644 --- a/src/engine/primitives/boxes/AxisAlignedBoundingCube.hpp +++ b/src/engine/primitives/boxes/AxisAlignedBoundingCube.hpp @@ -28,11 +28,11 @@ namespace fgl::engine float span() const { return this->scale().x; } - constexpr NormalVector right() const { return NormalVector::bypass( constants::WORLD_RIGHT ); } + constexpr NormalVector right() const { return NormalVector( constants::WORLD_RIGHT ); } - constexpr NormalVector up() const { return NormalVector::bypass( constants::WORLD_UP ); } + constexpr NormalVector up() const { return NormalVector( constants::WORLD_UP ); } - constexpr NormalVector forward() const { return NormalVector::bypass( constants::WORLD_FORWARD ); } + constexpr NormalVector forward() const { return NormalVector( constants::WORLD_FORWARD ); } }; } // namespace fgl::engine diff --git a/src/engine/primitives/planes/PointPlane.cpp b/src/engine/primitives/planes/PointPlane.cpp index ffc893b..2a6ac46 100644 --- a/src/engine/primitives/planes/PointPlane.cpp +++ b/src/engine/primitives/planes/PointPlane.cpp @@ -12,7 +12,7 @@ namespace fgl::engine template < CoordinateSpace CType > PointPlane< CType >::PointPlane() : coordinate( constants::WORLD_CENTER ), - vector( NormalVector::bypass( constants::WORLD_FORWARD ) ) + vector( NormalVector( constants::WORLD_FORWARD ) ) {} template < CoordinateSpace CType > diff --git a/src/engine/primitives/vectors/NormalVector.cpp b/src/engine/primitives/vectors/NormalVector.cpp index 97a6dec..21eee97 100644 --- a/src/engine/primitives/vectors/NormalVector.cpp +++ b/src/engine/primitives/vectors/NormalVector.cpp @@ -9,8 +9,6 @@ namespace fgl::engine { - NormalVector::NormalVector( const glm::vec3 vector ) : glm::vec3( glm::normalize( vector ) ) - {} NormalVector::NormalVector( const fgl::engine::Vector vector ) : NormalVector( vector.vec() ) {} diff --git a/src/engine/primitives/vectors/NormalVector.hpp b/src/engine/primitives/vectors/NormalVector.hpp index f68b235..73a22a2 100644 --- a/src/engine/primitives/vectors/NormalVector.hpp +++ b/src/engine/primitives/vectors/NormalVector.hpp @@ -20,21 +20,33 @@ namespace fgl::engine class Vector; - //! A vector that must be a distance of 1 - class NormalVector : private glm::vec3 + inline constexpr float length( glm::vec3 vec ) { - constexpr explicit NormalVector( const glm::vec3 point, [[maybe_unused]] const bool ) : glm::vec3( point ) {} + return std::sqrt( std::pow( vec.x, 2 ) + std::pow( vec.y, 2 ) + std::pow( vec.z, 2 ) ); + } - public: + inline constexpr glm::vec3 normalize( glm::vec3 vec ) + { + if constexpr ( std::is_constant_evaluated() ) + { + const auto len { length( vec ) }; + return glm::vec3( vec.x / len, vec.y / len, vec.z / len ); + } + else + return glm::normalize( vec ); + } - //TODO: Make my own normalize function to bypass the fact glm::normalize can't be constexpr - NormalVector() : glm::vec3( glm::normalize( glm::vec3( 1.0f ) ) ) {} - - NormalVector( const NormalVector& other ) = default; + //! A vector that must be a distance of 1 + struct NormalVector : private glm::vec3 + { + constexpr NormalVector() : glm::vec3( normalize( glm::vec3( 1.0f ) ) ) {} explicit NormalVector( const Vector vec ); - explicit NormalVector( const glm::vec3 vec ); + constexpr explicit NormalVector( const glm::vec3 vec ) : glm::vec3( normalize( vec ) ) {} + + NormalVector( const NormalVector& other ) = default; + NormalVector& operator=( const NormalVector& other ) = default; const glm::vec3& vec() const { return static_cast< const glm::vec3& >( *this ); } @@ -43,9 +55,6 @@ namespace fgl::engine Vector operator*( const float scalar ) const; NormalVector operator-() const { return NormalVector( -static_cast< glm::vec3 >( *this ) ); } - - //Used to bypass the glm::normalize constructor - constexpr static NormalVector bypass( const glm::vec3 point ) { return NormalVector( point, true ); } }; } // namespace fgl::engine