From f905aecd23474797654eefc1bd80827a62c99cab Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 14 Aug 2018 00:10:50 +0200 Subject: [PATCH] Sliced matrix transform extension --- glm/ext/matrix_clip_space.hpp | 531 +++++++++++++++ glm/ext/matrix_clip_space.inl | 534 +++++++++++++++ glm/ext/matrix_projection.hpp | 148 ++++ glm/ext/matrix_projection.inl | 104 +++ glm/ext/matrix_transform.hpp | 601 ----------------- glm/ext/matrix_transform.inl | 634 ------------------ glm/gtc/matrix_transform.hpp | 2 + test/ext/CMakeLists.txt | 6 +- test/ext/ext_matrix_clip_space.cpp | 13 + test/ext/ext_matrix_projection.cpp | 13 + test/ext/ext_matrix_transform.cpp | 18 + test/ext/ext_vector_double1.cpp | 128 ---- test/ext/ext_vector_float1.cpp | 127 ---- test/ext/ext_vector_iec559.cpp | 166 +++++ ...vector_int1.cpp => ext_vector_integer.cpp} | 48 +- test/ext/ext_vector_uint1.cpp | 180 ----- 16 files changed, 1571 insertions(+), 1682 deletions(-) create mode 100644 glm/ext/matrix_clip_space.hpp create mode 100644 glm/ext/matrix_clip_space.inl create mode 100644 glm/ext/matrix_projection.hpp create mode 100644 glm/ext/matrix_projection.inl create mode 100644 test/ext/ext_matrix_clip_space.cpp create mode 100644 test/ext/ext_matrix_projection.cpp delete mode 100644 test/ext/ext_vector_double1.cpp delete mode 100644 test/ext/ext_vector_float1.cpp create mode 100644 test/ext/ext_vector_iec559.cpp rename test/ext/{ext_vector_int1.cpp => ext_vector_integer.cpp} (70%) delete mode 100644 test/ext/ext_vector_uint1.cpp diff --git a/glm/ext/matrix_clip_space.hpp b/glm/ext/matrix_clip_space.hpp new file mode 100644 index 00000000..f001c910 --- /dev/null +++ b/glm/ext/matrix_clip_space.hpp @@ -0,0 +1,531 @@ +/// @ref ext_matrix_clip_space +/// @file glm/ext/matrix_clip_space.hpp +/// +/// @see core (dependence) +/// +/// @defgroup ext_matrix_clip_space GLM_EXT_matrix_clip_space +/// @ingroup ext +/// +/// Include to use the features of this extension. +/// +/// Defines functions that generate common transformation matrices. +/// +/// The matrices generated by this extension use standard OpenGL fixed-function +/// conventions. For example, the lookAt function generates a transform from world +/// space into the specific eye space that the projective matrix functions +/// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility +/// specifications defines the particular layout of this eye space. + +#pragma once + +// Dependencies +#include "../gtc/constants.hpp" +#include "../geometric.hpp" +#include "../trigonometric.hpp" +#include "../matrix.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_matrix_clip_space extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_matrix_clip_space + /// @{ + + /// Creates a matrix for projecting two-dimensional coordinates onto the screen. + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top, T const& zNear, T const& zFar) + /// @see gluOrtho2D man page + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> ortho( + T left, T right, T bottom, T top); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH_ZO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume using right-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH_NO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH_ZO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH_NO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoZO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoNO( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using the default handedness and default near and far clip planes definition. + /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) + /// @see glOrtho man page + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> ortho( + T left, T right, T bottom, T top, T zNear, T zFar); + + /// Creates a left handed frustum matrix. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH_ZO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a left handed frustum matrix. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH_NO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a right handed frustum matrix. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH_ZO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a right handed frustum matrix. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH_NO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a frustum matrix using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumZO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a frustum matrix using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumNO( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a left handed frustum matrix. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a right handed frustum matrix. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH( + T left, T right, T bottom, T top, T near, T far); + + /// Creates a frustum matrix with default handedness, using the default handedness and default near and far clip planes definition. + /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see glFrustum man page + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> frustum( + T left, T right, T bottom, T top, T near, T far); + + + /// Creates a matrix for a right handed, symetric perspective-view frustum. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH_ZO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a right handed, symetric perspective-view frustum. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH_NO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a left handed, symetric perspective-view frustum. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH_ZO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a left handed, symetric perspective-view frustum. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH_NO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a symetric perspective-view frustum using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveZO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a symetric perspective-view frustum using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveNO( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a right handed, symetric perspective-view frustum. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a left handed, symetric perspective-view frustum. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH( + T fovy, T aspect, T near, T far); + + /// Creates a matrix for a symetric perspective-view frustum based on the default handedness and default near and far clip planes definition. + /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @param fovy Specifies the field of view angle in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + /// @see gluPerspective man page + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspective( + T fovy, T aspect, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using right-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH_ZO( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using right-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH_NO( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using left-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH_ZO( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using left-handed coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH_NO( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovZO( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovNO( + T fov, T width, T height, T near, T far); + + /// Builds a right handed perspective projection matrix based on a field of view. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH( + T fov, T width, T height, T near, T far); + + /// Builds a left handed perspective projection matrix based on a field of view. + /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH( + T fov, T width, T height, T near, T far); + + /// Builds a perspective projection matrix based on a field of view and the default handedness and default near and far clip planes definition. + /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @param fov Expressed in radians. + /// @param width Width of the viewport + /// @param height Height of the viewport + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFov( + T fov, T width, T height, T near, T far); + + /// Creates a matrix for a left handed, symmetric perspective-view frustum with far plane at infinite. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspectiveLH( + T fovy, T aspect, T near); + + /// Creates a matrix for a right handed, symmetric perspective-view frustum with far plane at infinite. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspectiveRH( + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite with default handedness. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspective( + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> tweakedInfinitePerspective( + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param ep Epsilon + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL mat<4, 4, T, defaultp> tweakedInfinitePerspective( + T fovy, T aspect, T near, T ep); + + /// @} +}//namespace glm + +#include "matrix_clip_space.inl" diff --git a/glm/ext/matrix_clip_space.inl b/glm/ext/matrix_clip_space.inl new file mode 100644 index 00000000..9b870dc7 --- /dev/null +++ b/glm/ext/matrix_clip_space.inl @@ -0,0 +1,534 @@ +namespace glm +{ + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top) + { + mat<4, 4, T, defaultp> Result(static_cast(1)); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = - static_cast(1); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) + { + mat<4, 4, T, defaultp> Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = static_cast(1) / (zFar - zNear); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + Result[3][2] = - zNear / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_NO(T left, T right, T bottom, T top, T zNear, T zFar) + { + mat<4, 4, T, defaultp> Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = static_cast(2) / (zFar - zNear); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) + { + mat<4, 4, T, defaultp> Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = - static_cast(1) / (zFar - zNear); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + Result[3][2] = - zNear / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar) + { + mat<4, 4, T, defaultp> Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = - static_cast(2) / (zFar - zNear); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoZO(T left, T right, T bottom, T top, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return orthoLH_ZO(left, right, bottom, top, zNear, zFar); + else + return orthoRH_ZO(left, right, bottom, top, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoNO(T left, T right, T bottom, T top, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return orthoLH_NO(left, right, bottom, top, zNear, zFar); + else + return orthoRH_NO(left, right, bottom, top, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH(T left, T right, T bottom, T top, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return orthoLH_ZO(left, right, bottom, top, zNear, zFar); + else + return orthoLH_NO(left, right, bottom, top, zNear, zFar); + + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH(T left, T right, T bottom, T top, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return orthoRH_ZO(left, right, bottom, top, zNear, zFar); + else + return orthoRH_NO(left, right, bottom, top, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) + return orthoLH_ZO(left, right, bottom, top, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) + return orthoLH_NO(left, right, bottom, top, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) + return orthoRH_ZO(left, right, bottom, top, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) + return orthoRH_NO(left, right, bottom, top, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + mat<4, 4, T, defaultp> Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][2] = farVal / (farVal - nearVal); + Result[2][3] = static_cast(1); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_NO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + mat<4, 4, T, defaultp> Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][2] = (farVal + nearVal) / (farVal - nearVal); + Result[2][3] = static_cast(1); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + mat<4, 4, T, defaultp> Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][2] = farVal / (nearVal - farVal); + Result[2][3] = static_cast(-1); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_NO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + mat<4, 4, T, defaultp> Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); + Result[2][3] = static_cast(-1); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumZO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); + else + return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumNO(T left, T right, T bottom, T top, T nearVal, T farVal) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return frustumLH_NO(left, right, bottom, top, nearVal, farVal); + else + return frustumRH_NO(left, right, bottom, top, nearVal, farVal); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH(T left, T right, T bottom, T top, T nearVal, T farVal) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); + else + return frustumLH_NO(left, right, bottom, top, nearVal, farVal); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH(T left, T right, T bottom, T top, T nearVal, T farVal) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); + else + return frustumRH_NO(left, right, bottom, top, nearVal, farVal); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustum(T left, T right, T bottom, T top, T nearVal, T farVal) + { + if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) + return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) + return frustumLH_NO(left, right, bottom, top, nearVal, farVal); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) + return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) + return frustumRH_NO(left, right, bottom, top, nearVal, farVal); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_ZO(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][2] = zFar / (zNear - zFar); + Result[2][3] = - static_cast(1); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_NO(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[2][3] = - static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_ZO(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][2] = zFar / (zFar - zNear); + Result[2][3] = static_cast(1); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_NO(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[2][3] = static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveZO(T fovy, T aspect, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return perspectiveLH_ZO(fovy, aspect, zNear, zFar); + else + return perspectiveRH_ZO(fovy, aspect, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveNO(T fovy, T aspect, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return perspectiveLH_NO(fovy, aspect, zNear, zFar); + else + return perspectiveRH_NO(fovy, aspect, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH(T fovy, T aspect, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return perspectiveLH_ZO(fovy, aspect, zNear, zFar); + else + return perspectiveLH_NO(fovy, aspect, zNear, zFar); + + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH(T fovy, T aspect, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return perspectiveRH_ZO(fovy, aspect, zNear, zFar); + else + return perspectiveRH_NO(fovy, aspect, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspective(T fovy, T aspect, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) + return perspectiveLH_ZO(fovy, aspect, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) + return perspectiveLH_NO(fovy, aspect, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) + return perspectiveRH_ZO(fovy, aspect, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) + return perspectiveRH_NO(fovy, aspect, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_ZO(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][2] = zFar / (zNear - zFar); + Result[2][3] = - static_cast(1); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_NO(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[2][3] = - static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_ZO(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][2] = zFar / (zFar - zNear); + Result[2][3] = static_cast(1); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_NO(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[2][3] = static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovZO(T fov, T width, T height, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); + else + return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovNO(T fov, T width, T height, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return perspectiveFovLH_NO(fov, width, height, zNear, zFar); + else + return perspectiveFovRH_NO(fov, width, height, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH(T fov, T width, T height, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); + else + return perspectiveFovLH_NO(fov, width, height, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH(T fov, T width, T height, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); + else + return perspectiveFovRH_NO(fov, width, height, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFov(T fov, T width, T height, T zNear, T zFar) + { + if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) + return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) + return perspectiveFovLH_NO(fov, width, height, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) + return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); + else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) + return perspectiveFovRH_NO(fov, width, height, zNear, zFar); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH(T fovy, T aspect, T zNear) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = - static_cast(1); + Result[2][3] = - static_cast(1); + Result[3][2] = - static_cast(2) * zNear; + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveLH(T fovy, T aspect, T zNear) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + mat<4, 4, T, defaultp> Result(T(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = static_cast(1); + Result[2][3] = static_cast(1); + Result[3][2] = - static_cast(2) * zNear; + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspective(T fovy, T aspect, T zNear) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) + return infinitePerspectiveLH(fovy, aspect, zNear); + else + return infinitePerspectiveRH(fovy, aspect, zNear); + } + + // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear, T ep) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + mat<4, 4, T, defaultp> Result(static_cast(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = ep - static_cast(1); + Result[2][3] = static_cast(-1); + Result[3][2] = (ep - static_cast(2)) * zNear; + return Result; + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear) + { + return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon()); + } +}//namespace glm diff --git a/glm/ext/matrix_projection.hpp b/glm/ext/matrix_projection.hpp new file mode 100644 index 00000000..bd0ffabf --- /dev/null +++ b/glm/ext/matrix_projection.hpp @@ -0,0 +1,148 @@ +/// @ref ext_matrix_projection +/// @file glm/ext/matrix_projection.hpp +/// +/// @see core (dependence) +/// +/// @defgroup ext_matrix_projection GLM_EXT_matrix_projection +/// @ingroup ext +/// +/// Include to use the features of this extension. +/// +/// Defines functions that generate common transformation matrices. +/// +/// The matrices generated by this extension use standard OpenGL fixed-function +/// conventions. For example, the lookAt function generates a transform from world +/// space into the specific eye space that the projective matrix functions +/// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility +/// specifications defines the particular layout of this eye space. + +#pragma once + +// Dependencies +#include "../gtc/constants.hpp" +#include "../geometric.hpp" +#include "../trigonometric.hpp" +#include "../matrix.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_matrix_projection extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_matrix_projection + /// @{ + + /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param obj Specify the object coordinates. + /// @param model Specifies the current modelview matrix + /// @param proj Specifies the current projection matrix + /// @param viewport Specifies the current viewport + /// @return Return the computed window coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluProject man page + template + GLM_FUNC_DECL vec<3, T, Q> projectZO( + vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param obj Specify the object coordinates. + /// @param model Specifies the current modelview matrix + /// @param proj Specifies the current projection matrix + /// @param viewport Specifies the current viewport + /// @return Return the computed window coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluProject man page + template + GLM_FUNC_DECL vec<3, T, Q> projectNO( + vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates using default near and far clip planes definition. + /// To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @param obj Specify the object coordinates. + /// @param model Specifies the current modelview matrix + /// @param proj Specifies the current projection matrix + /// @param viewport Specifies the current viewport + /// @return Return the computed window coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluProject man page + template + GLM_FUNC_DECL vec<3, T, Q> project( + vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) + /// + /// @param win Specify the window coordinates to be mapped. + /// @param model Specifies the modelview matrix + /// @param proj Specifies the projection matrix + /// @param viewport Specifies the viewport + /// @return Returns the computed object coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluUnProject man page + template + GLM_FUNC_DECL vec<3, T, Q> unProjectZO( + vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. + /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) + /// + /// @param win Specify the window coordinates to be mapped. + /// @param model Specifies the modelview matrix + /// @param proj Specifies the projection matrix + /// @param viewport Specifies the viewport + /// @return Returns the computed object coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluUnProject man page + template + GLM_FUNC_DECL vec<3, T, Q> unProjectNO( + vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using default near and far clip planes definition. + /// To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. + /// + /// @param win Specify the window coordinates to be mapped. + /// @param model Specifies the modelview matrix + /// @param proj Specifies the projection matrix + /// @param viewport Specifies the viewport + /// @return Returns the computed object coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluUnProject man page + template + GLM_FUNC_DECL vec<3, T, Q> unProject( + vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); + + /// Define a picking region + /// + /// @param center Specify the center of a picking region in window coordinates. + /// @param delta Specify the width and height, respectively, of the picking region in window coordinates. + /// @param viewport Rendering viewport + /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + /// @see gluPickMatrix man page + template + GLM_FUNC_DECL mat<4, 4, T, Q> pickMatrix( + vec<2, T, Q> const& center, vec<2, T, Q> const& delta, vec<4, U, Q> const& viewport); + + /// @} +}//namespace glm + +#include "matrix_projection.inl" diff --git a/glm/ext/matrix_projection.inl b/glm/ext/matrix_projection.inl new file mode 100644 index 00000000..8b4eea98 --- /dev/null +++ b/glm/ext/matrix_projection.inl @@ -0,0 +1,104 @@ +namespace glm +{ + template + GLM_FUNC_QUALIFIER vec<3, T, Q> projectZO(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + vec<4, T, Q> tmp = vec<4, T, Q>(obj, static_cast(1)); + tmp = model * tmp; + tmp = proj * tmp; + + tmp /= tmp.w; + tmp.x = tmp.x * static_cast(0.5) + static_cast(0.5); + tmp.y = tmp.y * static_cast(0.5) + static_cast(0.5); + + tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); + tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); + + return vec<3, T, Q>(tmp); + } + + template + GLM_FUNC_QUALIFIER vec<3, T, Q> projectNO(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + vec<4, T, Q> tmp = vec<4, T, Q>(obj, static_cast(1)); + tmp = model * tmp; + tmp = proj * tmp; + + tmp /= tmp.w; + tmp = tmp * static_cast(0.5) + static_cast(0.5); + tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); + tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); + + return vec<3, T, Q>(tmp); + } + + template + GLM_FUNC_QUALIFIER vec<3, T, Q> project(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return projectZO(obj, model, proj, viewport); + else + return projectNO(obj, model, proj, viewport); + } + + template + GLM_FUNC_QUALIFIER vec<3, T, Q> unProjectZO(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + mat<4, 4, T, Q> Inverse = inverse(proj * model); + + vec<4, T, Q> tmp = vec<4, T, Q>(win, T(1)); + tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); + tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); + tmp.x = tmp.x * static_cast(2) - static_cast(1); + tmp.y = tmp.y * static_cast(2) - static_cast(1); + + vec<4, T, Q> obj = Inverse * tmp; + obj /= obj.w; + + return vec<3, T, Q>(obj); + } + + template + GLM_FUNC_QUALIFIER vec<3, T, Q> unProjectNO(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + mat<4, 4, T, Q> Inverse = inverse(proj * model); + + vec<4, T, Q> tmp = vec<4, T, Q>(win, T(1)); + tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); + tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); + tmp = tmp * static_cast(2) - static_cast(1); + + vec<4, T, Q> obj = Inverse * tmp; + obj /= obj.w; + + return vec<3, T, Q>(obj); + } + + template + GLM_FUNC_QUALIFIER vec<3, T, Q> unProject(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) + { + if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) + return unProjectZO(win, model, proj, viewport); + else + return unProjectNO(win, model, proj, viewport); + } + + template + GLM_FUNC_QUALIFIER mat<4, 4, T, Q> pickMatrix(vec<2, T, Q> const& center, vec<2, T, Q> const& delta, vec<4, U, Q> const& viewport) + { + assert(delta.x > static_cast(0) && delta.y > static_cast(0)); + mat<4, 4, T, Q> Result(static_cast(1)); + + if(!(delta.x > static_cast(0) && delta.y > static_cast(0))) + return Result; // Error + + vec<3, T, Q> Temp( + (static_cast(viewport[2]) - static_cast(2) * (center.x - static_cast(viewport[0]))) / delta.x, + (static_cast(viewport[3]) - static_cast(2) * (center.y - static_cast(viewport[1]))) / delta.y, + static_cast(0)); + + // Translate and scale the picked region to the entire window + Result = translate(Result, Temp); + return scale(Result, vec<3, T, Q>(static_cast(viewport[2]) / delta.x, static_cast(viewport[3]) / delta.y, static_cast(1))); + } +}//namespace glm diff --git a/glm/ext/matrix_transform.hpp b/glm/ext/matrix_transform.hpp index 3e1aaadc..75f573f9 100644 --- a/glm/ext/matrix_transform.hpp +++ b/glm/ext/matrix_transform.hpp @@ -87,607 +87,6 @@ namespace glm GLM_FUNC_DECL mat<4, 4, T, Q> scale( mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v); - /// Creates a matrix for projecting two-dimensional coordinates onto the screen. - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top, T const& zNear, T const& zFar) - /// @see gluOrtho2D man page - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> ortho( - T left, T right, T bottom, T top); - - /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH_ZO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume using right-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH_NO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH_ZO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH_NO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoZO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoNO( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using left-handed coordinates. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoLH( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using right-handed coordinates. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> orthoRH( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a matrix for an orthographic parallel viewing volume, using the default handedness and default near and far clip planes definition. - /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see - glm::ortho(T const& left, T const& right, T const& bottom, T const& top) - /// @see glOrtho man page - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> ortho( - T left, T right, T bottom, T top, T zNear, T zFar); - - /// Creates a left handed frustum matrix. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH_ZO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a left handed frustum matrix. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH_NO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a right handed frustum matrix. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH_ZO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a right handed frustum matrix. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH_NO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a frustum matrix using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumZO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a frustum matrix using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumNO( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a left handed frustum matrix. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumLH( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a right handed frustum matrix. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustumRH( - T left, T right, T bottom, T top, T near, T far); - - /// Creates a frustum matrix with default handedness, using the default handedness and default near and far clip planes definition. - /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see glFrustum man page - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> frustum( - T left, T right, T bottom, T top, T near, T far); - - - /// Creates a matrix for a right handed, symetric perspective-view frustum. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH_ZO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a right handed, symetric perspective-view frustum. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH_NO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a left handed, symetric perspective-view frustum. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH_ZO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a left handed, symetric perspective-view frustum. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH_NO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a symetric perspective-view frustum using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveZO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a symetric perspective-view frustum using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveNO( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a right handed, symetric perspective-view frustum. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveRH( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a left handed, symetric perspective-view frustum. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveLH( - T fovy, T aspect, T near, T far); - - /// Creates a matrix for a symetric perspective-view frustum based on the default handedness and default near and far clip planes definition. - /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @param fovy Specifies the field of view angle in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - /// @see gluPerspective man page - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspective( - T fovy, T aspect, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using right-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH_ZO( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using right-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH_NO( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using left-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH_ZO( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using left-handed coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH_NO( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovZO( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view using left-handed coordinates if GLM_FORCE_LEFT_HANDED if defined or right-handed coordinates otherwise. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovNO( - T fov, T width, T height, T near, T far); - - /// Builds a right handed perspective projection matrix based on a field of view. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovRH( - T fov, T width, T height, T near, T far); - - /// Builds a left handed perspective projection matrix based on a field of view. - /// If GLM_FORCE_DEPTH_ZERO_TO_ONE is defined, the near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// Otherwise, the near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFovLH( - T fov, T width, T height, T near, T far); - - /// Builds a perspective projection matrix based on a field of view and the default handedness and default near and far clip planes definition. - /// To change default handedness use GLM_FORCE_LEFT_HANDED. To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @param fov Expressed in radians. - /// @param width Width of the viewport - /// @param height Height of the viewport - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> perspectiveFov( - T fov, T width, T height, T near, T far); - - /// Creates a matrix for a left handed, symmetric perspective-view frustum with far plane at infinite. - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspectiveLH( - T fovy, T aspect, T near); - - /// Creates a matrix for a right handed, symmetric perspective-view frustum with far plane at infinite. - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspectiveRH( - T fovy, T aspect, T near); - - /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite with default handedness. - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> infinitePerspective( - T fovy, T aspect, T near); - - /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> tweakedInfinitePerspective( - T fovy, T aspect, T near); - - /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. - /// - /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. - /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). - /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). - /// @param ep Epsilon - /// @tparam T Value type used to build the matrix. Currently supported: half (not recommended), float or double. - /// @see gtc_matrix_transform - template - GLM_FUNC_DECL mat<4, 4, T, defaultp> tweakedInfinitePerspective( - T fovy, T aspect, T near, T ep); - - /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param obj Specify the object coordinates. - /// @param model Specifies the current modelview matrix - /// @param proj Specifies the current projection matrix - /// @param viewport Specifies the current viewport - /// @return Return the computed window coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluProject man page - template - GLM_FUNC_DECL vec<3, T, Q> projectZO( - vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param obj Specify the object coordinates. - /// @param model Specifies the current modelview matrix - /// @param proj Specifies the current projection matrix - /// @param viewport Specifies the current viewport - /// @return Return the computed window coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluProject man page - template - GLM_FUNC_DECL vec<3, T, Q> projectNO( - vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates using default near and far clip planes definition. - /// To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @param obj Specify the object coordinates. - /// @param model Specifies the current modelview matrix - /// @param proj Specifies the current projection matrix - /// @param viewport Specifies the current viewport - /// @return Return the computed window coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluProject man page - template - GLM_FUNC_DECL vec<3, T, Q> project( - vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of 0 and +1 respectively. (Direct3D clip volume definition) - /// - /// @param win Specify the window coordinates to be mapped. - /// @param model Specifies the modelview matrix - /// @param proj Specifies the projection matrix - /// @param viewport Specifies the viewport - /// @return Returns the computed object coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluUnProject man page - template - GLM_FUNC_DECL vec<3, T, Q> unProjectZO( - vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. - /// The near and far clip planes correspond to z normalized device coordinates of -1 and +1 respectively. (OpenGL clip volume definition) - /// - /// @param win Specify the window coordinates to be mapped. - /// @param model Specifies the modelview matrix - /// @param proj Specifies the projection matrix - /// @param viewport Specifies the viewport - /// @return Returns the computed object coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluUnProject man page - template - GLM_FUNC_DECL vec<3, T, Q> unProjectNO( - vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using default near and far clip planes definition. - /// To change default near and far clip planes definition use GLM_FORCE_DEPTH_ZERO_TO_ONE. - /// - /// @param win Specify the window coordinates to be mapped. - /// @param model Specifies the modelview matrix - /// @param proj Specifies the projection matrix - /// @param viewport Specifies the viewport - /// @return Returns the computed object coordinates. - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluUnProject man page - template - GLM_FUNC_DECL vec<3, T, Q> unProject( - vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport); - - /// Define a picking region - /// - /// @param center Specify the center of a picking region in window coordinates. - /// @param delta Specify the width and height, respectively, of the picking region in window coordinates. - /// @param viewport Rendering viewport - /// @tparam T Native type used for the computation. Currently supported: half (not recommended), float or double. - /// @tparam U Currently supported: Floating-point types and integer types. - /// @see gtc_matrix_transform - /// @see gluPickMatrix man page - template - GLM_FUNC_DECL mat<4, 4, T, Q> pickMatrix( - vec<2, T, Q> const& center, vec<2, T, Q> const& delta, vec<4, U, Q> const& viewport); - /// Build a right handed look at view matrix. /// /// @param eye Position of the camera diff --git a/glm/ext/matrix_transform.inl b/glm/ext/matrix_transform.inl index 85c1eda3..5037ec1b 100644 --- a/glm/ext/matrix_transform.inl +++ b/glm/ext/matrix_transform.inl @@ -95,640 +95,6 @@ namespace glm return m * Result; } - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top) - { - mat<4, 4, T, defaultp> Result(static_cast(1)); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - static_cast(1); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) - { - mat<4, 4, T, defaultp> Result(1); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = static_cast(1) / (zFar - zNear); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - Result[3][2] = - zNear / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_NO(T left, T right, T bottom, T top, T zNear, T zFar) - { - mat<4, 4, T, defaultp> Result(1); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = static_cast(2) / (zFar - zNear); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - Result[3][2] = - (zFar + zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) - { - mat<4, 4, T, defaultp> Result(1); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - static_cast(1) / (zFar - zNear); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - Result[3][2] = - zNear / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar) - { - mat<4, 4, T, defaultp> Result(1); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - static_cast(2) / (zFar - zNear); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - Result[3][2] = - (zFar + zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoZO(T left, T right, T bottom, T top, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return orthoLH_ZO(left, right, bottom, top, zNear, zFar); - else - return orthoRH_ZO(left, right, bottom, top, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoNO(T left, T right, T bottom, T top, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return orthoLH_NO(left, right, bottom, top, zNear, zFar); - else - return orthoRH_NO(left, right, bottom, top, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH(T left, T right, T bottom, T top, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return orthoLH_ZO(left, right, bottom, top, zNear, zFar); - else - return orthoLH_NO(left, right, bottom, top, zNear, zFar); - - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH(T left, T right, T bottom, T top, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return orthoRH_ZO(left, right, bottom, top, zNear, zFar); - else - return orthoRH_NO(left, right, bottom, top, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) - return orthoLH_ZO(left, right, bottom, top, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) - return orthoLH_NO(left, right, bottom, top, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) - return orthoRH_ZO(left, right, bottom, top, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) - return orthoRH_NO(left, right, bottom, top, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - mat<4, 4, T, defaultp> Result(0); - Result[0][0] = (static_cast(2) * nearVal) / (right - left); - Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); - Result[2][0] = (right + left) / (right - left); - Result[2][1] = (top + bottom) / (top - bottom); - Result[2][2] = farVal / (farVal - nearVal); - Result[2][3] = static_cast(1); - Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_NO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - mat<4, 4, T, defaultp> Result(0); - Result[0][0] = (static_cast(2) * nearVal) / (right - left); - Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); - Result[2][0] = (right + left) / (right - left); - Result[2][1] = (top + bottom) / (top - bottom); - Result[2][2] = (farVal + nearVal) / (farVal - nearVal); - Result[2][3] = static_cast(1); - Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - mat<4, 4, T, defaultp> Result(0); - Result[0][0] = (static_cast(2) * nearVal) / (right - left); - Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); - Result[2][0] = (right + left) / (right - left); - Result[2][1] = (top + bottom) / (top - bottom); - Result[2][2] = farVal / (nearVal - farVal); - Result[2][3] = static_cast(-1); - Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_NO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - mat<4, 4, T, defaultp> Result(0); - Result[0][0] = (static_cast(2) * nearVal) / (right - left); - Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); - Result[2][0] = (right + left) / (right - left); - Result[2][1] = (top + bottom) / (top - bottom); - Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); - Result[2][3] = static_cast(-1); - Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumZO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); - else - return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumNO(T left, T right, T bottom, T top, T nearVal, T farVal) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return frustumLH_NO(left, right, bottom, top, nearVal, farVal); - else - return frustumRH_NO(left, right, bottom, top, nearVal, farVal); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH(T left, T right, T bottom, T top, T nearVal, T farVal) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); - else - return frustumLH_NO(left, right, bottom, top, nearVal, farVal); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH(T left, T right, T bottom, T top, T nearVal, T farVal) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); - else - return frustumRH_NO(left, right, bottom, top, nearVal, farVal); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustum(T left, T right, T bottom, T top, T nearVal, T farVal) - { - if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) - return frustumLH_ZO(left, right, bottom, top, nearVal, farVal); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) - return frustumLH_NO(left, right, bottom, top, nearVal, farVal); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) - return frustumRH_ZO(left, right, bottom, top, nearVal, farVal); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) - return frustumRH_NO(left, right, bottom, top, nearVal, farVal); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_ZO(T fovy, T aspect, T zNear, T zFar) - { - assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); - - T const tanHalfFovy = tan(fovy / static_cast(2)); - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); - Result[1][1] = static_cast(1) / (tanHalfFovy); - Result[2][2] = zFar / (zNear - zFar); - Result[2][3] = - static_cast(1); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_NO(T fovy, T aspect, T zNear, T zFar) - { - assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); - - T const tanHalfFovy = tan(fovy / static_cast(2)); - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); - Result[1][1] = static_cast(1) / (tanHalfFovy); - Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[2][3] = - static_cast(1); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_ZO(T fovy, T aspect, T zNear, T zFar) - { - assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); - - T const tanHalfFovy = tan(fovy / static_cast(2)); - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); - Result[1][1] = static_cast(1) / (tanHalfFovy); - Result[2][2] = zFar / (zFar - zNear); - Result[2][3] = static_cast(1); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_NO(T fovy, T aspect, T zNear, T zFar) - { - assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); - - T const tanHalfFovy = tan(fovy / static_cast(2)); - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); - Result[1][1] = static_cast(1) / (tanHalfFovy); - Result[2][2] = (zFar + zNear) / (zFar - zNear); - Result[2][3] = static_cast(1); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveZO(T fovy, T aspect, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return perspectiveLH_ZO(fovy, aspect, zNear, zFar); - else - return perspectiveRH_ZO(fovy, aspect, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveNO(T fovy, T aspect, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return perspectiveLH_NO(fovy, aspect, zNear, zFar); - else - return perspectiveRH_NO(fovy, aspect, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH(T fovy, T aspect, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return perspectiveLH_ZO(fovy, aspect, zNear, zFar); - else - return perspectiveLH_NO(fovy, aspect, zNear, zFar); - - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH(T fovy, T aspect, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return perspectiveRH_ZO(fovy, aspect, zNear, zFar); - else - return perspectiveRH_NO(fovy, aspect, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspective(T fovy, T aspect, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) - return perspectiveLH_ZO(fovy, aspect, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) - return perspectiveLH_NO(fovy, aspect, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) - return perspectiveRH_ZO(fovy, aspect, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) - return perspectiveRH_NO(fovy, aspect, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_ZO(T fov, T width, T height, T zNear, T zFar) - { - assert(width > static_cast(0)); - assert(height > static_cast(0)); - assert(fov > static_cast(0)); - - T const rad = fov; - T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); - T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = w; - Result[1][1] = h; - Result[2][2] = zFar / (zNear - zFar); - Result[2][3] = - static_cast(1); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_NO(T fov, T width, T height, T zNear, T zFar) - { - assert(width > static_cast(0)); - assert(height > static_cast(0)); - assert(fov > static_cast(0)); - - T const rad = fov; - T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); - T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = w; - Result[1][1] = h; - Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[2][3] = - static_cast(1); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_ZO(T fov, T width, T height, T zNear, T zFar) - { - assert(width > static_cast(0)); - assert(height > static_cast(0)); - assert(fov > static_cast(0)); - - T const rad = fov; - T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); - T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = w; - Result[1][1] = h; - Result[2][2] = zFar / (zFar - zNear); - Result[2][3] = static_cast(1); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_NO(T fov, T width, T height, T zNear, T zFar) - { - assert(width > static_cast(0)); - assert(height > static_cast(0)); - assert(fov > static_cast(0)); - - T const rad = fov; - T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); - T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = w; - Result[1][1] = h; - Result[2][2] = (zFar + zNear) / (zFar - zNear); - Result[2][3] = static_cast(1); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovZO(T fov, T width, T height, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); - else - return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovNO(T fov, T width, T height, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return perspectiveFovLH_NO(fov, width, height, zNear, zFar); - else - return perspectiveFovRH_NO(fov, width, height, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH(T fov, T width, T height, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); - else - return perspectiveFovLH_NO(fov, width, height, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH(T fov, T width, T height, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); - else - return perspectiveFovRH_NO(fov, width, height, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFov(T fov, T width, T height, T zNear, T zFar) - { - if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO) - return perspectiveFovLH_ZO(fov, width, height, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO) - return perspectiveFovLH_NO(fov, width, height, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO) - return perspectiveFovRH_ZO(fov, width, height, zNear, zFar); - else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO) - return perspectiveFovRH_NO(fov, width, height, zNear, zFar); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH(T fovy, T aspect, T zNear) - { - T const range = tan(fovy / static_cast(2)) * zNear; - T const left = -range * aspect; - T const right = range * aspect; - T const bottom = -range; - T const top = range; - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = (static_cast(2) * zNear) / (right - left); - Result[1][1] = (static_cast(2) * zNear) / (top - bottom); - Result[2][2] = - static_cast(1); - Result[2][3] = - static_cast(1); - Result[3][2] = - static_cast(2) * zNear; - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveLH(T fovy, T aspect, T zNear) - { - T const range = tan(fovy / static_cast(2)) * zNear; - T const left = -range * aspect; - T const right = range * aspect; - T const bottom = -range; - T const top = range; - - mat<4, 4, T, defaultp> Result(T(0)); - Result[0][0] = (static_cast(2) * zNear) / (right - left); - Result[1][1] = (static_cast(2) * zNear) / (top - bottom); - Result[2][2] = static_cast(1); - Result[2][3] = static_cast(1); - Result[3][2] = - static_cast(2) * zNear; - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspective(T fovy, T aspect, T zNear) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT) - return infinitePerspectiveLH(fovy, aspect, zNear); - else - return infinitePerspectiveRH(fovy, aspect, zNear); - } - - // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear, T ep) - { - T const range = tan(fovy / static_cast(2)) * zNear; - T const left = -range * aspect; - T const right = range * aspect; - T const bottom = -range; - T const top = range; - - mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = (static_cast(2) * zNear) / (right - left); - Result[1][1] = (static_cast(2) * zNear) / (top - bottom); - Result[2][2] = ep - static_cast(1); - Result[2][3] = static_cast(-1); - Result[3][2] = (ep - static_cast(2)) * zNear; - return Result; - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear) - { - return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon()); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> projectZO(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - vec<4, T, Q> tmp = vec<4, T, Q>(obj, static_cast(1)); - tmp = model * tmp; - tmp = proj * tmp; - - tmp /= tmp.w; - tmp.x = tmp.x * static_cast(0.5) + static_cast(0.5); - tmp.y = tmp.y * static_cast(0.5) + static_cast(0.5); - - tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); - tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); - - return vec<3, T, Q>(tmp); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> projectNO(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - vec<4, T, Q> tmp = vec<4, T, Q>(obj, static_cast(1)); - tmp = model * tmp; - tmp = proj * tmp; - - tmp /= tmp.w; - tmp = tmp * static_cast(0.5) + static_cast(0.5); - tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); - tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); - - return vec<3, T, Q>(tmp); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> project(vec<3, T, Q> const& obj, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return projectZO(obj, model, proj, viewport); - else - return projectNO(obj, model, proj, viewport); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> unProjectZO(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - mat<4, 4, T, Q> Inverse = inverse(proj * model); - - vec<4, T, Q> tmp = vec<4, T, Q>(win, T(1)); - tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); - tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); - tmp.x = tmp.x * static_cast(2) - static_cast(1); - tmp.y = tmp.y * static_cast(2) - static_cast(1); - - vec<4, T, Q> obj = Inverse * tmp; - obj /= obj.w; - - return vec<3, T, Q>(obj); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> unProjectNO(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - mat<4, 4, T, Q> Inverse = inverse(proj * model); - - vec<4, T, Q> tmp = vec<4, T, Q>(win, T(1)); - tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); - tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); - tmp = tmp * static_cast(2) - static_cast(1); - - vec<4, T, Q> obj = Inverse * tmp; - obj /= obj.w; - - return vec<3, T, Q>(obj); - } - - template - GLM_FUNC_QUALIFIER vec<3, T, Q> unProject(vec<3, T, Q> const& win, mat<4, 4, T, Q> const& model, mat<4, 4, T, Q> const& proj, vec<4, U, Q> const& viewport) - { - if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT) - return unProjectZO(win, model, proj, viewport); - else - return unProjectNO(win, model, proj, viewport); - } - - template - GLM_FUNC_QUALIFIER mat<4, 4, T, Q> pickMatrix(vec<2, T, Q> const& center, vec<2, T, Q> const& delta, vec<4, U, Q> const& viewport) - { - assert(delta.x > static_cast(0) && delta.y > static_cast(0)); - mat<4, 4, T, Q> Result(static_cast(1)); - - if(!(delta.x > static_cast(0) && delta.y > static_cast(0))) - return Result; // Error - - vec<3, T, Q> Temp( - (static_cast(viewport[2]) - static_cast(2) * (center.x - static_cast(viewport[0]))) / delta.x, - (static_cast(viewport[3]) - static_cast(2) * (center.y - static_cast(viewport[1]))) / delta.y, - static_cast(0)); - - // Translate and scale the picked region to the entire window - Result = translate(Result, Temp); - return scale(Result, vec<3, T, Q>(static_cast(viewport[2]) / delta.x, static_cast(viewport[3]) / delta.y, static_cast(1))); - } - template GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtRH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up) { diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 791120c3..612418fa 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -25,6 +25,8 @@ #include "../vec2.hpp" #include "../vec3.hpp" #include "../vec4.hpp" +#include "../ext/matrix_projection.hpp" +#include "../ext/matrix_clip_space.hpp" #include "../ext/matrix_transform.hpp" #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index 541bbb03..7b5bc14e 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -13,8 +13,6 @@ glmCreateTestGTC(ext_scalar_uint_sized) glmCreateTestGTC(ext_scalar_relational) glmCreateTestGTC(ext_vec1) glmCreateTestGTC(ext_vector_bool1) -glmCreateTestGTC(ext_vector_float1) -glmCreateTestGTC(ext_vector_double1) -glmCreateTestGTC(ext_vector_int1) -glmCreateTestGTC(ext_vector_uint1) +glmCreateTestGTC(ext_vector_iec559) +glmCreateTestGTC(ext_vector_integer) glmCreateTestGTC(ext_vector_relational) diff --git a/test/ext/ext_matrix_clip_space.cpp b/test/ext/ext_matrix_clip_space.cpp new file mode 100644 index 00000000..ca84c19b --- /dev/null +++ b/test/ext/ext_matrix_clip_space.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + int Error = 0; + + return Error; +} diff --git a/test/ext/ext_matrix_projection.cpp b/test/ext/ext_matrix_projection.cpp new file mode 100644 index 00000000..88f6ae9c --- /dev/null +++ b/test/ext/ext_matrix_projection.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + int Error = 0; + + return Error; +} diff --git a/test/ext/ext_matrix_transform.cpp b/test/ext/ext_matrix_transform.cpp index 19eca356..4158dcda 100644 --- a/test/ext/ext_matrix_transform.cpp +++ b/test/ext/ext_matrix_transform.cpp @@ -18,12 +18,30 @@ static int test_translate() return Error; } +static int test_scale() +{ + int Error = 0; + + glm::mat4 const M(1.0f); + glm::vec3 const V(2.0f); + + glm::mat4 const S = glm::scale(M, V); + glm::mat4 const R = glm::mat4( + glm::vec4(2, 0, 0, 0), + glm::vec4(0, 2, 0, 0), + glm::vec4(0, 0, 2, 0), + glm::vec4(0, 0, 0, 1)); + Error += glm::all(glm::equal(S, R, glm::epsilon())) ? 0 : 1; + + return Error; +} int main() { int Error = 0; Error += test_translate(); + Error += test_scale(); return Error; } diff --git a/test/ext/ext_vector_double1.cpp b/test/ext/ext_vector_double1.cpp deleted file mode 100644 index 8ddd1a25..00000000 --- a/test/ext/ext_vector_double1.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -template -static int test_operators() -{ - int Error = 0; - - { - genType const A(1); - genType const B(1); - - genType const C = A + B; - Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; - - genType const D = A - B; - Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; - - genType const E = A * B; - Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; - - genType const F = A / B; - Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; - } - - return Error; -} - -template -static int test_ctor() -{ - int Error = 0; - - glm::dvec1 const A = genType(1); - - glm::dvec1 const E(genType(1)); - Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; - - glm::dvec1 const F(E); - Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; - - genType const B = genType(1); - genType const G(glm::dvec2(1)); - Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; - - genType const H(glm::dvec3(1)); - Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; - - genType const I(glm::dvec4(1)); - Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; - - return Error; -} - -template -static int test_size() -{ - int Error = 0; - - Error += sizeof(glm::dvec1) == sizeof(genType) ? 0 : 1; - Error += genType().length() == 1 ? 0 : 1; - Error += genType::length() == 1 ? 0 : 1; - - return Error; -} - -template -static int test_relational() -{ - int Error = 0; - - genType const A(1); - genType const B(1); - genType const C(0); - - Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; - Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; - - return Error; -} - -template -static int test_constexpr() -{ -# if GLM_CONFIG_CONSTEXP == GLM_ENABLE - static_assert(genType::length() == 1, "GLM: Failed constexpr"); -# endif - - return 0; -} - -int main() -{ - int Error = 0; - - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - - Error += test_size(); - Error += test_size(); - Error += test_size(); - Error += test_size(); - - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - - return Error; -} diff --git a/test/ext/ext_vector_float1.cpp b/test/ext/ext_vector_float1.cpp deleted file mode 100644 index 7d7fae14..00000000 --- a/test/ext/ext_vector_float1.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -template -static int test_operators() -{ - int Error = 0; - - { - genType const A(1); - genType const B(1); - - genType const C = A + B; - Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; - - genType const D = A - B; - Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; - - genType const E = A * B; - Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; - - genType const F = A / B; - Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; - } - - return Error; -} - -template -static int test_ctor() -{ - int Error = 0; - - glm::vec1 const A = genType(1); - - glm::vec1 const E(genType(1)); - Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; - - glm::vec1 const F(E); - Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; - - genType const B = genType(1); - genType const G(glm::vec2(1)); - Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; - - genType const H(glm::vec3(1)); - Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; - - genType const I(glm::vec4(1)); - Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; - - return Error; -} - -template -static int test_size() -{ - int Error = 0; - - Error += sizeof(glm::vec1) == sizeof(genType) ? 0 : 1; - Error += genType().length() == 1 ? 0 : 1; - Error += genType::length() == 1 ? 0 : 1; - - return Error; -} - -template -static int test_relational() -{ - int Error = 0; - - genType const A(1); - genType const B(1); - genType const C(0); - - Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; - Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; - - return Error; -} - -template -static int test_constexpr() -{ -# if GLM_CONFIG_CONSTEXP == GLM_ENABLE - static_assert(genType::length() == 1, "GLM: Failed constexpr"); -# endif - - return 0; -} - -int main() -{ - int Error = 0; - - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - - Error += test_size(); - Error += test_size(); - Error += test_size(); - Error += test_size(); - - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - - return Error; -} diff --git a/test/ext/ext_vector_iec559.cpp b/test/ext/ext_vector_iec559.cpp new file mode 100644 index 00000000..5a9da506 --- /dev/null +++ b/test/ext/ext_vector_iec559.cpp @@ -0,0 +1,166 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +static int test_operators() +{ + typedef typename genType::value_type valType; + + int Error = 0; + + { + genType const A(1); + genType const B(1); + + genType const C = A + B; + Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; + + genType const D = A - B; + Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; + + genType const E = A * B; + Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; + + genType const F = A / B; + Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; + } + + return Error; +} + +template +static int test_ctor() +{ + typedef typename genType::value_type T; + + int Error = 0; + + glm::vec<1, T> const A = genType(1); + + glm::vec<1, T> const E(genType(1)); + Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; + + glm::vec<1, T> const F(E); + Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; + + genType const B = genType(1); + genType const G(glm::vec<2, T>(1)); + Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; + + genType const H(glm::vec<3, T>(1)); + Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; + + genType const I(glm::vec<4, T>(1)); + Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_size() +{ + typedef typename genType::value_type T; + + int Error = 0; + + Error += sizeof(glm::vec<1, T>) == sizeof(genType) ? 0 : 1; + Error += genType().length() == 1 ? 0 : 1; + Error += genType::length() == 1 ? 0 : 1; + + return Error; +} + +template +static int test_relational() +{ + typedef typename genType::value_type valType; + + int Error = 0; + + genType const A(1); + genType const B(1); + genType const C(0); + + Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; + Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_constexpr() +{ +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + static_assert(genType::length() == 1, "GLM: Failed constexpr"); +# endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + return Error; +} diff --git a/test/ext/ext_vector_int1.cpp b/test/ext/ext_vector_integer.cpp similarity index 70% rename from test/ext/ext_vector_int1.cpp rename to test/ext/ext_vector_integer.cpp index b0d8f422..39f11086 100644 --- a/test/ext/ext_vector_int1.cpp +++ b/test/ext/ext_vector_integer.cpp @@ -3,6 +3,11 @@ #include #include #include +#include +#include +#include +#include +#include #include template @@ -82,24 +87,26 @@ static int test_operators() template static int test_ctor() { + typedef typename genType::value_type T; + int Error = 0; - glm::ivec1 const A = genType(1); + genType const A = genType(1); - glm::ivec1 const E(genType(1)); + genType const E(genType(1)); Error += A == E ? 0 : 1; - glm::ivec1 const F(E); + genType const F(E); Error += A == F ? 0 : 1; genType const B = genType(1); - genType const G(glm::ivec2(1)); + genType const G(glm::vec<2, T>(1)); Error += B == G ? 0 : 1; - genType const H(glm::ivec3(1)); + genType const H(glm::vec<3, T>(1)); Error += B == H ? 0 : 1; - genType const I(glm::ivec4(1)); + genType const I(glm::vec<4, T>(1)); Error += B == I ? 0 : 1; return Error; @@ -110,7 +117,7 @@ static int test_size() { int Error = 0; - Error += sizeof(glm::ivec1) == sizeof(genType) ? 0 : 1; + Error += sizeof(typename genType::value_type) == sizeof(genType) ? 0 : 1; Error += genType().length() == 1 ? 0 : 1; Error += genType::length() == 1 ? 0 : 1; @@ -140,7 +147,7 @@ static int test_constexpr() # if GLM_CONFIG_CONSTEXP == GLM_ENABLE static_assert(genType::length() == 1, "GLM: Failed constexpr"); static_assert(genType(1)[0] == 1, "GLM: Failed constexpr"); - static_assert(genType(1) == genType(glm::ivec1(1)), "GLM: Failed constexpr"); + static_assert(genType(1) == genType(1), "GLM: Failed constexpr"); static_assert(genType(1) != genType(0), "GLM: Failed constexpr"); # endif @@ -176,5 +183,30 @@ int main() Error += test_constexpr(); Error += test_constexpr(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + return Error; } diff --git a/test/ext/ext_vector_uint1.cpp b/test/ext/ext_vector_uint1.cpp deleted file mode 100644 index bd8e87f5..00000000 --- a/test/ext/ext_vector_uint1.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include -#include -#include -#include -#include - -template -static int test_operators() -{ - int Error = 0; - - { - genType const A(1); - genType const B(1); - - bool const R = A != B; - bool const S = A == B; - Error += (S && !R) ? 0 : 1; - } - - { - genType const A(1); - genType const B(1); - - genType const C = A + B; - Error += C == genType(2) ? 0 : 1; - - genType const D = A - B; - Error += D == genType(0) ? 0 : 1; - - genType const E = A * B; - Error += E == genType(1) ? 0 : 1; - - genType const F = A / B; - Error += F == genType(1) ? 0 : 1; - } - - { - genType const A(3); - genType const B(2); - - genType const C = A % B; - Error += C == genType(1) ? 0 : 1; - } - - { - genType const A(1); - genType const B(1); - genType const C(0); - - genType const I = A & B; - Error += I == genType(1) ? 0 : 1; - genType const D = A & C; - Error += D == genType(0) ? 0 : 1; - - genType const E = A | B; - Error += E == genType(1) ? 0 : 1; - genType const F = A | C; - Error += F == genType(1) ? 0 : 1; - - genType const G = A ^ B; - Error += G == genType(0) ? 0 : 1; - genType const H = A ^ C; - Error += H == genType(1) ? 0 : 1; - } - - { - genType const A(0); - genType const B(1); - genType const C(2); - - genType const D = B << B; - Error += D == genType(2) ? 0 : 1; - genType const E = C >> B; - Error += E == genType(1) ? 0 : 1; - } - - return Error; -} - -template -static int test_ctor() -{ - int Error = 0; - - glm::uvec1 const A = genType(1); - - glm::uvec1 const E(genType(1)); - Error += A == E ? 0 : 1; - - glm::uvec1 const F(E); - Error += A == F ? 0 : 1; - - genType const B = genType(1); - genType const G(glm::uvec2(1)); - Error += B == G ? 0 : 1; - - genType const H(glm::uvec3(1)); - Error += B == H ? 0 : 1; - - genType const I(glm::uvec4(1)); - Error += B == I ? 0 : 1; - - return Error; -} - -template -static int test_size() -{ - int Error = 0; - - Error += sizeof(glm::uvec1) == sizeof(genType) ? 0 : 1; - Error += genType().length() == 1 ? 0 : 1; - Error += genType::length() == 1 ? 0 : 1; - - return Error; -} - -template -static int test_relational() -{ - int Error = 0; - - genType const A(1); - genType const B(1); - genType const C(0); - - Error += A == B ? 0 : 1; - Error += A != C ? 0 : 1; - Error += all(equal(A, B)) ? 0 : 1; - Error += any(notEqual(A, C)) ? 0 : 1; - - return Error; -} - -template -static int test_constexpr() -{ -# if GLM_CONFIG_CONSTEXP == GLM_ENABLE - static_assert(genType::length() == 1, "GLM: Failed constexpr"); - static_assert(genType(1)[0] == 1, "GLM: Failed constexpr"); - static_assert(genType(1) == genType(glm::uvec1(1)), "GLM: Failed constexpr"); - static_assert(genType(1) != genType(0), "GLM: Failed constexpr"); -# endif - - return 0; -} - -int main() -{ - int Error = 0; - - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - Error += test_operators(); - - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - Error += test_ctor(); - - Error += test_size(); - Error += test_size(); - Error += test_size(); - Error += test_size(); - - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - Error += test_relational(); - - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - Error += test_constexpr(); - - return Error; -}