From 6789d897d2ff0152f91df4623791016f3117e6cc Mon Sep 17 00:00:00 2001 From: Sebastian Rettenberger Date: Wed, 23 Sep 2015 12:03:15 +0200 Subject: [PATCH 1/9] Fix floorMultiple/ceilMultiple for float --- glm/gtc/round.inl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index 255dec66..94fdd54b 100644 --- a/glm/gtc/round.inl +++ b/glm/gtc/round.inl @@ -104,10 +104,7 @@ namespace detail GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple) { if(Source > genType(0)) - { - genType Tmp = Source - genType(1); - return Tmp + (Multiple - std::fmod(Tmp, Multiple)); - } + return Source + (Multiple - std::fmod(Source, Multiple)); else return Source + std::fmod(-Source, Multiple); } @@ -152,10 +149,7 @@ namespace detail if(Source >= genType(0)) return Source - std::fmod(Source, Multiple); else - { - genType Tmp = Source + genType(1); - return Tmp - std::fmod(Tmp, Multiple) - Multiple; - } + return Source - std::fmod(Source, Multiple) - Multiple; } }; From 8af1d0ce2d289b0727841be1631122d3135c98cd Mon Sep 17 00:00:00 2001 From: Sebastian Rettenberger Date: Wed, 23 Sep 2015 12:03:44 +0200 Subject: [PATCH 2/9] Add test for floorMultiple/ceilMultiple (float only) --- test/gtc/gtc_round.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index 1162d00f..aa6cf1a1 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -293,6 +294,86 @@ namespace ceilPowerOfTwo } }//namespace ceilPowerOfTwo +namespace floorMultiple +{ + template + struct type + { + genType Source; + genType Multiple; + genType Return; + genType Epsilon; + }; + + int test_float() + { + type const Data[] = + { + {3.4, 0.3, 3.3, 0.0001}, + {-1.4, 0.3, -1.5, 0.0001}, + }; + + int Error(0); + + for(std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) + { + glm::float64 Result = glm::floorMultiple(Data[i].Source, Data[i].Multiple); + Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1; + } + + return Error; + } + + int test() + { + int Error(0); + + Error += test_float(); + + return Error; + } +}//namespace floorMultiple + +namespace ceilMultiple +{ + template + struct type + { + genType Source; + genType Multiple; + genType Return; + genType Epsilon; + }; + + int test_float() + { + type const Data[] = + { + {3.4, 0.3, 3.6, 0.0001}, + {-1.4, 0.3, -1.2, 0.0001}, + }; + + int Error(0); + + for(std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) + { + glm::float64 Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple); + Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1; + } + + return Error; + } + + int test() + { + int Error(0); + + Error += test_float(); + + return Error; + } +}//namespace ceilMultiple + int main() { int Error(0); @@ -304,5 +385,8 @@ int main() Error += ceilPowerOfTwo::perf(); # endif//NDEBUG + Error += floorMultiple::test(); + Error += ceilMultiple::test(); + return Error; } From 11bfa1eff7cd0a2ca118f3894c40c602395dee75 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 28 Sep 2015 11:19:38 +0200 Subject: [PATCH 3/9] Fixed GTC_round --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 500016a5..999cedf8 100644 --- a/readme.md +++ b/readme.md @@ -51,6 +51,10 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) ## Release notes +#### [GLM 0.9.7.2](https://github.com/g-truc/glm/tree/0.9.7) - 2015-XX-XX +##### Fixes: +- Fixed GTC_round floorMultiple/ceilMultiple #412 + #### [GLM 0.9.7.1](https://github.com/g-truc/glm/releases/tag/0.9.7.1) - 2015-09-07 ##### Improvements: - Improved constexpr for constant functions coverage #198 From 06ad5a2cd405af66a275ce8323e16c7bbd9ecd08 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 28 Sep 2015 23:47:40 +0200 Subject: [PATCH 4/9] Fixed GTC_packing unpackUnorm3x10_1x2 #414 --- glm/gtc/packing.inl | 23 +++++++++++------------ readme.md | 1 + test/gtc/gtc_packing.cpp | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 58b1d59b..3a59e9b9 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -451,24 +451,23 @@ namespace detail GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v) { - detail::i10i10i10i2 Result; - Result.data.x = int(round(clamp(v.x, 0.0f, 1.0f) * 1023.f)); - Result.data.y = int(round(clamp(v.y, 0.0f, 1.0f) * 1023.f)); - Result.data.z = int(round(clamp(v.z, 0.0f, 1.0f) * 1023.f)); - Result.data.w = int(round(clamp(v.w, 0.0f, 1.0f) * 3.f)); + uvec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 3.f))); + + detail::u10u10u10u2 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + Result.data.w = Unpack.w; return Result.pack; } GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 v) { - detail::i10i10i10i2 Unpack; + vec4 const ScaleFactors(1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 3.f); + + detail::u10u10u10u2 Unpack; Unpack.pack = v; - vec4 Result; - Result.x = float(Unpack.data.x) / 1023.f; - Result.y = float(Unpack.data.y) / 1023.f; - Result.z = float(Unpack.data.z) / 1023.f; - Result.w = float(Unpack.data.w) / 3.f; - return Result; + return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactors; } GLM_FUNC_QUALIFIER uint32 packF2x11_1x10(vec3 const & v) diff --git a/readme.md b/readme.md index 999cedf8..8265447a 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.7.2](https://github.com/g-truc/glm/tree/0.9.7) - 2015-XX-XX ##### Fixes: - Fixed GTC_round floorMultiple/ceilMultiple #412 +- Fixed GTC_packing unpackUnorm3x10_1x2 #414 #### [GLM 0.9.7.1](https://github.com/g-truc/glm/releases/tag/0.9.7.1) - 2015-09-07 ##### Improvements: diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index fc6f57c2..45a67f3f 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -220,10 +220,10 @@ int test_Unorm3x10_1x2() for(std::size_t i = 0; i < Tests.size(); ++i) { - glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); - glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); - glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); - glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1); + glm::uint32 p0 = glm::packUnorm3x10_1x2(Tests[i]); + glm::vec4 v0 = glm::unpackUnorm3x10_1x2(p0); + glm::uint32 p1 = glm::packUnorm3x10_1x2(v0); + glm::vec4 v1 = glm::unpackUnorm3x10_1x2(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -394,7 +394,7 @@ int test_packUnorm1x8() for(std::size_t i = 0; i < A.size(); ++i) { glm::vec1 B(A[i]); - glm::uint16 C = glm::packUnorm1x8(B.x); + glm::uint8 C = glm::packUnorm1x8(B.x); glm::vec1 D(glm::unpackUnorm1x8(C)); Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1; assert(!Error); @@ -414,7 +414,7 @@ int test_packSnorm1x8() for(std::size_t i = 0; i < A.size(); ++i) { glm::vec1 B(A[i]); - glm::uint16 C = glm::packSnorm1x8(B.x); + glm::uint8 C = glm::packSnorm1x8(B.x); glm::vec1 D(glm::unpackSnorm1x8(C)); Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1; } From e37fe66d5e2916c68666446b6b20a2ea75768692 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 29 Sep 2015 01:25:02 +0200 Subject: [PATCH 5/9] Fixed GTC_packing unpackUnorm3x10_1x2 #414 --- glm/gtc/packing.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 3a59e9b9..6f351a8f 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -451,7 +451,7 @@ namespace detail GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v) { - uvec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 3.f))); + uvec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(1023.f, 1023.f, 1023.f, 3.f))); detail::u10u10u10u2 Result; Result.data.x = Unpack.x; From f384e18a78d764d7caf59938be11d6842e9f8e74 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 1 Oct 2015 01:30:13 +0200 Subject: [PATCH 6/9] Added tests for affineInverse #192 --- test/gtc/gtc_matrix_inverse.cpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/gtc/gtc_matrix_inverse.cpp b/test/gtc/gtc_matrix_inverse.cpp index d9615d5b..88225a26 100644 --- a/test/gtc/gtc_matrix_inverse.cpp +++ b/test/gtc/gtc_matrix_inverse.cpp @@ -30,10 +30,53 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include + +int test_affine() +{ + int Error = 0; + + { + glm::mat3 const M( + 2.f, 0.f, 0.f, + 0.f, 2.f, 0.f, + 0.f, 0.f, 1.f); + + glm::mat3 const A = glm::affineInverse(M); + glm::mat3 const I = glm::inverse(M); + + glm::mat3 const R = glm::affineInverse(A); + + Error += M != A; + Error += M == R; + Error += A == I; + } + + { + glm::mat4 const M( + 2.f, 0.f, 0.f, 0.f, + 0.f, 2.f, 0.f, 0.f, + 0.f, 0.f, 2.f, 0.f, + 0.f, 0.f, 0.f, 1.f); + + glm::mat4 const A = glm::affineInverse(M); + glm::mat4 const I = glm::inverse(M); + + glm::mat4 const R = glm::affineInverse(A); + + Error += M != A; + Error += M == R; + Error += A == I; + } + + return Error; +} int main() { int Error = 0; + Error += test_affine(); + return Error; } From a4ed6568be3cb522023952ba3dff17792ad9d570 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 1 Oct 2015 22:20:30 +0200 Subject: [PATCH 7/9] Fixed GTC_matrix_inverse affineInverse #192 --- glm/gtc/matrix_inverse.inl | 25 +++++++++++++------------ readme.md | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/glm/gtc/matrix_inverse.inl b/glm/gtc/matrix_inverse.inl index d88a3319..d2437d5d 100644 --- a/glm/gtc/matrix_inverse.inl +++ b/glm/gtc/matrix_inverse.inl @@ -35,23 +35,24 @@ namespace glm template GLM_FUNC_QUALIFIER tmat3x3 affineInverse(tmat3x3 const & m) { - tmat3x3 Result(m); - Result[2] = tvec3(0, 0, 1); - Result = transpose(Result); - tvec3 Translation = Result * tvec3(-tvec2(m[2]), m[2][2]); - Result[2] = Translation; - return Result; + tmat2x2 const Inv(inverse(tmat2x2(m))); + + return tmat3x3( + tvec3(Inv[0], static_cast(0)), + tvec3(Inv[1], static_cast(0)), + tvec3(-Inv * tvec2(m[2]), static_cast(1))); } template GLM_FUNC_QUALIFIER tmat4x4 affineInverse(tmat4x4 const & m) { - tmat4x4 Result(m); - Result[3] = tvec4(0, 0, 0, 1); - Result = transpose(Result); - tvec4 Translation = Result * tvec4(-tvec3(m[3]), m[3][3]); - Result[3] = Translation; - return Result; + tmat3x3 const Inv(inverse(tmat3x3(m))); + + return tmat4x4( + tvec4(Inv[0], static_cast(0)), + tvec4(Inv[1], static_cast(0)), + tvec4(Inv[2], static_cast(0)), + tvec4(-Inv * tvec3(m[3]), static_cast(1))); } template diff --git a/readme.md b/readme.md index 8265447a..8d18090f 100644 --- a/readme.md +++ b/readme.md @@ -55,6 +55,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) ##### Fixes: - Fixed GTC_round floorMultiple/ceilMultiple #412 - Fixed GTC_packing unpackUnorm3x10_1x2 #414 +- Fixed GTC_matrix_inverse affineInverse #192 #### [GLM 0.9.7.1](https://github.com/g-truc/glm/releases/tag/0.9.7.1) - 2015-09-07 ##### Improvements: From 11f05cea58bea333d044a6b566ed449db94d2f8a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 1 Oct 2015 23:25:21 +0200 Subject: [PATCH 8/9] Fixed affineInverse test #192 --- test/gtc/gtc_matrix_inverse.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/gtc/gtc_matrix_inverse.cpp b/test/gtc/gtc_matrix_inverse.cpp index 88225a26..0fe9d5c9 100644 --- a/test/gtc/gtc_matrix_inverse.cpp +++ b/test/gtc/gtc_matrix_inverse.cpp @@ -41,15 +41,15 @@ int test_affine() 2.f, 0.f, 0.f, 0.f, 2.f, 0.f, 0.f, 0.f, 1.f); - glm::mat3 const A = glm::affineInverse(M); glm::mat3 const I = glm::inverse(M); - glm::mat3 const R = glm::affineInverse(A); - Error += M != A; - Error += M == R; - Error += A == I; + for(glm::length_t i = 0; i < A.length(); ++i) + { + Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1; + Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1; + } } { @@ -58,15 +58,15 @@ int test_affine() 0.f, 2.f, 0.f, 0.f, 0.f, 0.f, 2.f, 0.f, 0.f, 0.f, 0.f, 1.f); - glm::mat4 const A = glm::affineInverse(M); glm::mat4 const I = glm::inverse(M); - glm::mat4 const R = glm::affineInverse(A); - Error += M != A; - Error += M == R; - Error += A == I; + for(glm::length_t i = 0; i < A.length(); ++i) + { + Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1; + Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1; + } } return Error; From 5e994bcf394115d692bf38444a88ea3d264e4605 Mon Sep 17 00:00:00 2001 From: lucasb-eyer Date: Mon, 5 Oct 2015 23:16:38 +0200 Subject: [PATCH 9/9] dummy.cpp CRLF->LF --- glm/detail/dummy.cpp | 464 +++++++++++++++++++++---------------------- 1 file changed, 232 insertions(+), 232 deletions(-) diff --git a/glm/detail/dummy.cpp b/glm/detail/dummy.cpp index 50342809..09a2ae59 100644 --- a/glm/detail/dummy.cpp +++ b/glm/detail/dummy.cpp @@ -1,232 +1,232 @@ -/////////////////////////////////////////////////////////////////////////////////// -/// OpenGL Mathematics (glm.g-truc.net) -/// -/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) -/// Permission is hereby granted, free of charge, to any person obtaining a copy -/// of this software and associated documentation files (the "Software"), to deal -/// in the Software without restriction, including without limitation the rights -/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -/// copies of the Software, and to permit persons to whom the Software is -/// furnished to do so, subject to the following conditions: -/// -/// The above copyright notice and this permission notice shall be included in -/// all copies or substantial portions of the Software. -/// -/// Restrictions: -/// By making use of the Software for military purposes, you choose to make -/// a Bunny unhappy. -/// -/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -/// THE SOFTWARE. -/// -/// @ref core -/// @file glm/core/dummy.cpp -/// @date 2011-01-19 / 2011-06-15 -/// @author Christophe Riccio -/// -/// GLM is a header only library. There is nothing to compile. -/// dummy.cpp exist only a wordaround for CMake file. -/////////////////////////////////////////////////////////////////////////////////// - -#define GLM_MESSAGES -#include -#include -#include - -struct material -{ - glm::vec4 emission; // Ecm - glm::vec4 ambient; // Acm - glm::vec4 diffuse; // Dcm - glm::vec4 specular; // Scm - float shininess; // Srm -}; - -struct light -{ - glm::vec4 ambient; // Acli - glm::vec4 diffuse; // Dcli - glm::vec4 specular; // Scli - glm::vec4 position; // Ppli - glm::vec4 halfVector; // Derived: Hi - glm::vec3 spotDirection; // Sdli - float spotExponent; // Srli - float spotCutoff; // Crli - // (range: [0.0,90.0], 180.0) - float spotCosCutoff; // Derived: cos(Crli) - // (range: [1.0,0.0],-1.0) - float constantAttenuation; // K0 - float linearAttenuation; // K1 - float quadraticAttenuation;// K2 -}; - - -// Sample 1 -#include // glm::vec3 -#include // glm::cross, glm::normalize - -glm::vec3 computeNormal -( - glm::vec3 const & a, - glm::vec3 const & b, - glm::vec3 const & c -) -{ - return glm::normalize(glm::cross(c - a, b - a)); -} - -typedef unsigned int GLuint; -#define GL_FALSE 0 -void glUniformMatrix4fv(GLuint, int, int, float*){} - -// Sample 2 -#include // glm::vec3 -#include // glm::vec4, glm::ivec4 -#include // glm::mat4 -#include // glm::translate, glm::rotate, glm::scale, glm::perspective -#include // glm::value_ptr -void func(GLuint LocationMVP, float Translate, glm::vec2 const & Rotate) -{ - glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f); - glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate)); - glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f)); - glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f)); - glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); - glm::mat4 MVP = Projection * View * Model; - glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP)); -} - -// Sample 3 -#include // glm::vec2 -#include // glm::packUnorm2x16 -#include // glm::uint -#include // glm::i8vec2, glm::i32vec2 -std::size_t const VertexCount = 4; -// Float quad geometry -std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2); -glm::vec2 const PositionDataF32[VertexCount] = -{ - glm::vec2(-1.0f,-1.0f), - glm::vec2( 1.0f,-1.0f), - glm::vec2( 1.0f, 1.0f), - glm::vec2(-1.0f, 1.0f) - }; -// Half-float quad geometry -std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::uint); -glm::uint const PositionDataF16[VertexCount] = -{ - glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, -1.0f))), - glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, -1.0f))), - glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, 1.0f))), - glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, 1.0f))) -}; -// 8 bits signed integer quad geometry -std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2); -glm::i8vec2 const PositionDataI8[VertexCount] = -{ - glm::i8vec2(-1,-1), - glm::i8vec2( 1,-1), - glm::i8vec2( 1, 1), - glm::i8vec2(-1, 1) -}; -// 32 bits signed integer quad geometry -std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2); -glm::i32vec2 const PositionDataI32[VertexCount] = -{ - glm::i32vec2 (-1,-1), - glm::i32vec2 ( 1,-1), - glm::i32vec2 ( 1, 1), - glm::i32vec2 (-1, 1) -}; - -struct intersection -{ - glm::vec4 position; - glm::vec3 normal; -}; - -/* -// Sample 4 -#include // glm::vec3 -#include // glm::normalize, glm::dot, glm::reflect -#include // glm::pow -#include // glm::vecRand3 -glm::vec3 lighting -( - intersection const & Intersection, - material const & Material, - light const & Light, - glm::vec3 const & View -) -{ - glm::vec3 Color(0.0f); - glm::vec3 LightVertor(glm::normalize( - Light.position - Intersection.position + - glm::vecRand3(0.0f, Light.inaccuracy)); - - if(!shadow(Intersection.position, Light.position, LightVertor)) - { - float Diffuse = glm::dot(Intersection.normal, LightVector); - if(Diffuse <= 0.0f) - return Color; - if(Material.isDiffuse()) - Color += Light.color() * Material.diffuse * Diffuse; - if(Material.isSpecular()) - { - glm::vec3 Reflect(glm::reflect( - glm::normalize(-LightVector), - glm::normalize(Intersection.normal))); - float Dot = glm::dot(Reflect, View); - float Base = Dot > 0.0f ? Dot : 0.0f; - float Specular = glm::pow(Base, Material.exponent); - Color += Material.specular * Specular; - } - } - return Color; -} -*/ - - -template class vecType> -T normalizeDotA(vecType const & x, vecType const & y) -{ - return glm::dot(x, y) * glm::inversesqrt(glm::dot(x, x) * glm::dot(y, y)); -} - -#define GLM_TEMPLATE_GENTYPE typename T, glm::precision P, template class - -template -T normalizeDotB(vecType const & x, vecType const & y) -{ - return glm::dot(x, y) * glm::inversesqrt(glm::dot(x, x) * glm::dot(y, y)); -} - -template -typename vecType::value_type normalizeDotC(vecType const & a, vecType const & b) -{ - return glm::dot(a, b) * glm::inversesqrt(glm::dot(a, a) * glm::dot(b, b)); -} - -int main() -{ - glm::vec1 o(1); - glm::vec2 a(1); - glm::vec3 b(1); - glm::vec4 c(1); - - glm::quat q; - glm::dualquat p; - - glm::mat4 m(1); - - float a0 = normalizeDotA(a, a); - float b0 = normalizeDotB(b, b); - float c0 = normalizeDotC(c, c); - - return 0; -} +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// Restrictions: +/// By making use of the Software for military purposes, you choose to make +/// a Bunny unhappy. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref core +/// @file glm/core/dummy.cpp +/// @date 2011-01-19 / 2011-06-15 +/// @author Christophe Riccio +/// +/// GLM is a header only library. There is nothing to compile. +/// dummy.cpp exist only a wordaround for CMake file. +/////////////////////////////////////////////////////////////////////////////////// + +#define GLM_MESSAGES +#include +#include +#include + +struct material +{ + glm::vec4 emission; // Ecm + glm::vec4 ambient; // Acm + glm::vec4 diffuse; // Dcm + glm::vec4 specular; // Scm + float shininess; // Srm +}; + +struct light +{ + glm::vec4 ambient; // Acli + glm::vec4 diffuse; // Dcli + glm::vec4 specular; // Scli + glm::vec4 position; // Ppli + glm::vec4 halfVector; // Derived: Hi + glm::vec3 spotDirection; // Sdli + float spotExponent; // Srli + float spotCutoff; // Crli + // (range: [0.0,90.0], 180.0) + float spotCosCutoff; // Derived: cos(Crli) + // (range: [1.0,0.0],-1.0) + float constantAttenuation; // K0 + float linearAttenuation; // K1 + float quadraticAttenuation;// K2 +}; + + +// Sample 1 +#include // glm::vec3 +#include // glm::cross, glm::normalize + +glm::vec3 computeNormal +( + glm::vec3 const & a, + glm::vec3 const & b, + glm::vec3 const & c +) +{ + return glm::normalize(glm::cross(c - a, b - a)); +} + +typedef unsigned int GLuint; +#define GL_FALSE 0 +void glUniformMatrix4fv(GLuint, int, int, float*){} + +// Sample 2 +#include // glm::vec3 +#include // glm::vec4, glm::ivec4 +#include // glm::mat4 +#include // glm::translate, glm::rotate, glm::scale, glm::perspective +#include // glm::value_ptr +void func(GLuint LocationMVP, float Translate, glm::vec2 const & Rotate) +{ + glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f); + glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate)); + glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f)); + glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f)); + glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); + glm::mat4 MVP = Projection * View * Model; + glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP)); +} + +// Sample 3 +#include // glm::vec2 +#include // glm::packUnorm2x16 +#include // glm::uint +#include // glm::i8vec2, glm::i32vec2 +std::size_t const VertexCount = 4; +// Float quad geometry +std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2); +glm::vec2 const PositionDataF32[VertexCount] = +{ + glm::vec2(-1.0f,-1.0f), + glm::vec2( 1.0f,-1.0f), + glm::vec2( 1.0f, 1.0f), + glm::vec2(-1.0f, 1.0f) + }; +// Half-float quad geometry +std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::uint); +glm::uint const PositionDataF16[VertexCount] = +{ + glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, -1.0f))), + glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, -1.0f))), + glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, 1.0f))), + glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, 1.0f))) +}; +// 8 bits signed integer quad geometry +std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2); +glm::i8vec2 const PositionDataI8[VertexCount] = +{ + glm::i8vec2(-1,-1), + glm::i8vec2( 1,-1), + glm::i8vec2( 1, 1), + glm::i8vec2(-1, 1) +}; +// 32 bits signed integer quad geometry +std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2); +glm::i32vec2 const PositionDataI32[VertexCount] = +{ + glm::i32vec2 (-1,-1), + glm::i32vec2 ( 1,-1), + glm::i32vec2 ( 1, 1), + glm::i32vec2 (-1, 1) +}; + +struct intersection +{ + glm::vec4 position; + glm::vec3 normal; +}; + +/* +// Sample 4 +#include // glm::vec3 +#include // glm::normalize, glm::dot, glm::reflect +#include // glm::pow +#include // glm::vecRand3 +glm::vec3 lighting +( + intersection const & Intersection, + material const & Material, + light const & Light, + glm::vec3 const & View +) +{ + glm::vec3 Color(0.0f); + glm::vec3 LightVertor(glm::normalize( + Light.position - Intersection.position + + glm::vecRand3(0.0f, Light.inaccuracy)); + + if(!shadow(Intersection.position, Light.position, LightVertor)) + { + float Diffuse = glm::dot(Intersection.normal, LightVector); + if(Diffuse <= 0.0f) + return Color; + if(Material.isDiffuse()) + Color += Light.color() * Material.diffuse * Diffuse; + if(Material.isSpecular()) + { + glm::vec3 Reflect(glm::reflect( + glm::normalize(-LightVector), + glm::normalize(Intersection.normal))); + float Dot = glm::dot(Reflect, View); + float Base = Dot > 0.0f ? Dot : 0.0f; + float Specular = glm::pow(Base, Material.exponent); + Color += Material.specular * Specular; + } + } + return Color; +} +*/ + + +template class vecType> +T normalizeDotA(vecType const & x, vecType const & y) +{ + return glm::dot(x, y) * glm::inversesqrt(glm::dot(x, x) * glm::dot(y, y)); +} + +#define GLM_TEMPLATE_GENTYPE typename T, glm::precision P, template class + +template +T normalizeDotB(vecType const & x, vecType const & y) +{ + return glm::dot(x, y) * glm::inversesqrt(glm::dot(x, x) * glm::dot(y, y)); +} + +template +typename vecType::value_type normalizeDotC(vecType const & a, vecType const & b) +{ + return glm::dot(a, b) * glm::inversesqrt(glm::dot(a, a) * glm::dot(b, b)); +} + +int main() +{ + glm::vec1 o(1); + glm::vec2 a(1); + glm::vec3 b(1); + glm::vec4 c(1); + + glm::quat q; + glm::dualquat p; + + glm::mat4 m(1); + + float a0 = normalizeDotA(a, a); + float b0 = normalizeDotB(b, b); + float c0 = normalizeDotC(c, c); + + return 0; +}