Merge swizzle changes

This commit is contained in:
Ben 2011-10-05 09:46:28 -07:00
commit 5f287430f4
39 changed files with 4497 additions and 1850 deletions

View file

@ -12,6 +12,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
#add_definitions(-S)
#add_definitions(-s)
add_definitions(-msse2)
add_definitions(-std=c++0x )
#add_definitions(-m32)
#add_definitions(-mfpmath=387)
#add_definitions(-ffast-math)

View file

@ -11,8 +11,8 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">
Download GLM 0.9.2.3</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title-date"> </div><div class="title4"> </div><div><p>
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">
Download GLM 0.9.2.6</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title-date"> </div><div class="title4"> </div><div><p>
OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software
based on the <a href="http://www.opengl.org/documentation/glsl/">OpenGL Shading Language (GLSL)</a> specification.
</p><p>

View file

@ -11,8 +11,8 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">
Download GLM 0.9.2.3</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><span xmlns="http://www.w3.org/1999/xhtml" class="code-title">Compute a triangle normal:</span><ul xmlns="http://www.w3.org/1999/xhtml" class="code-list"><li class="code-line"><span class="code-line-content"><span class="keyword">#include </span><span class="string">&lt;glm/glm.hpp&gt;</span></span></li><li class="code-line"><span class="code-line-content" /></li><li class="code-line"><span class="code-line-content"><span class="keyword">void </span> computeNormal(triangle &amp; Triangle)
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">
Download GLM 0.9.2.6</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><span xmlns="http://www.w3.org/1999/xhtml" class="code-title">Compute a triangle normal:</span><ul xmlns="http://www.w3.org/1999/xhtml" class="code-list"><li class="code-line"><span class="code-line-content"><span class="keyword">#include </span><span class="string">&lt;glm/glm.hpp&gt;</span></span></li><li class="code-line"><span class="code-line-content" /></li><li class="code-line"><span class="code-line-content"><span class="keyword">void </span> computeNormal(triangle &amp; Triangle)
</span></li><li class="code-line"><span class="code-line-content">
{
</span></li><li class="code-line"><span class="code-line-content" style="padding-left:32px">

View file

@ -11,11 +11,14 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">
Download GLM 0.9.2.3</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title4">Current release</div></div><div class="issue-content">08/06/2011:
<a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">GLM 0.9.2.3</a>
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">
Download GLM 0.9.2.6</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title4">Current release</div></div><div class="issue-content">01/10/2011:
<a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">GLM 0.9.2.6</a>
(3.4 MB)
</div><div class="news-separator">_________________</div><br /><div><div class="title4">GLM - zip files</div><div class="issue-content">08/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">GLM 0.9.2.3</a> (3.4 MB)
</div><div class="news-separator">_________________</div><br /><div><div class="title4">GLM - zip files</div><div class="issue-content">01/10/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">GLM 0.9.2.6</a> (3.4 MB)
</div><div class="issue-content">20/09/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.zip/download">GLM 0.9.2.5</a> (3.4 MB)
</div><div class="issue-content">03/09/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.zip/download">GLM 0.9.2.4</a> (3.4 MB)
</div><div class="issue-content">08/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">GLM 0.9.2.3</a> (3.4 MB)
</div><div class="issue-content">02/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.2/glm-0.9.2.2.zip/download">GLM 0.9.2.2</a> (3.4 MB)
</div><div class="issue-content">24/05/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.1/glm-0.9.2.1.zip/download">GLM 0.9.2.1</a> (3.4 MB)
</div><div class="issue-content">08/05/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.0/glm-0.9.2.0.zip/download">GLM 0.9.2.0</a> (3.4 MB)
@ -76,7 +79,10 @@
</div><div class="issue-content">02/19/2006: <a href="http://prdownloads.sourceforge.net/glf/glm-0.3.zip?download">GLM 0.3.0.0</a> (945 KB)
</div><div class="issue-content">05/05/2005: <a href="http://prdownloads.sourceforge.net/glf/glm-0.2.zip?download">GLM 0.2.0.0</a> (194 KB)
</div><div class="issue-content">02/21/2005: <a href="http://prdownloads.sourceforge.net/glf/glm-0.1-ur.zip?download">GLM 0.1.0.0</a> (29.2 KB)
</div></div><div class="news-separator">_________________</div><br /><div><div class="title4">GLM - 7z files</div><div class="issue-content">08/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.7z/download">GLM 0.9.2.3</a> (2.1 MB)
</div></div><div class="news-separator">_________________</div><br /><div><div class="title4">GLM - 7z files</div><div class="issue-content">01/10/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.7z/download">GLM 0.9.2.6</a> (2.1 MB)
</div><div class="issue-content">20/09/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.7z/download">GLM 0.9.2.5</a> (2.1 MB)
</div><div class="issue-content">03/09/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.7z/download">GLM 0.9.2.4</a> (2.1 MB)
</div><div class="issue-content">08/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.7z/download">GLM 0.9.2.3</a> (2.1 MB)
</div><div class="issue-content">02/06/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.2/glm-0.9.2.2.7z/download">GLM 0.9.2.2</a> (2.1 MB)
</div><div class="issue-content">24/05/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.1/glm-0.9.2.1.7z/download">GLM 0.9.2.1</a> (2.1 MB)
</div><div class="issue-content">08/05/2011: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.0/glm-0.9.2.0.7z/download">GLM 0.9.2.0</a> (2.1 MB)

View file

@ -11,5 +11,5 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">
Download GLM 0.9.2.3</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title-date">16/10/2008</div><div class="title4">GLM Logo</div><div><table style="width:100%;"><tr style="width:100%;"><td><p />Download: <a href="./goodies/logo2560x1600.png">2560x1600</a><br />Download: <a href="./goodies/logo1920x1200.png">1920x1200</a><br />Download: <a href="./goodies/logo1600x1000.png">1600x1000</a><br />Download: <a href="./goodies/logo1280x0800.png">1280x0800</a><br />Download: <a href="./goodies/logo1024x0640.png">1024x0640</a><br /></td><td style="text-align:right;"><a ref="goodies/logo.png"><img src="image/logo-mini.png" alt=" " /></a></td></tr></table></div><div class="news-separator">_________________</div><br /></div><div><div class="title-date">16/10/2008</div><div class="title4">GLM Font</div><div><table style="width:100%;"><tr style="width:100%;"><td><p />Download: <a href="./goodies/tenby-five.otf">Font (.otf)</a><br /></td><td style="text-align:right;"><a ref="goodies/font.png"><img src="image/font-mini.png" alt=" " /></a></td></tr></table></div><div class="news-separator">_________________</div><br /></div><div class="email"><img src="./common/email.png" alt="email not available as text" /></div><div class="news-separator">_________________</div><br /><div class="title3">Copyright Š 2005 - 2011<a href="http://www.g-truc.net">G-Truc Creation</a></div></td></tr></table></body></html>
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">
Download GLM 0.9.2.6</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><div><div class="title-date">16/10/2008</div><div class="title4">GLM Logo</div><div><table style="width:100%;"><tr style="width:100%;"><td><p />Download: <a href="./goodies/logo2560x1600.png">2560x1600</a><br />Download: <a href="./goodies/logo1920x1200.png">1920x1200</a><br />Download: <a href="./goodies/logo1600x1000.png">1600x1000</a><br />Download: <a href="./goodies/logo1280x0800.png">1280x0800</a><br />Download: <a href="./goodies/logo1024x0640.png">1024x0640</a><br /></td><td style="text-align:right;"><a ref="goodies/logo.png"><img src="image/logo-mini.png" alt=" " /></a></td></tr></table></div><div class="news-separator">_________________</div><br /></div><div><div class="title-date">16/10/2008</div><div class="title4">GLM Font</div><div><table style="width:100%;"><tr style="width:100%;"><td><p />Download: <a href="./goodies/tenby-five.otf">Font (.otf)</a><br /></td><td style="text-align:right;"><a ref="goodies/font.png"><img src="image/font-mini.png" alt=" " /></a></td></tr></table></div><div class="news-separator">_________________</div><br /></div><div class="email"><img src="./common/email.png" alt="email not available as text" /></div><div class="news-separator">_________________</div><br /><div class="title3">Copyright Š 2005 - 2011<a href="http://www.g-truc.net">G-Truc Creation</a></div></td></tr></table></body></html>

View file

@ -11,8 +11,8 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">
Download GLM 0.9.2.3</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><p>
</script></head><body><table><tr><td class="menu"><div class="menu1"><br /><div><a href="./goodies/logo1920x1200.png"><img class="menu-img" src="./common/logo.png" alt="GLM Logo" /></a></div><br /><div><a class="menu" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">
Download GLM 0.9.2.6</a></div></div><br /><div class="menu2"><a href="./index.html">Front page</a></div><div class="menu2"><a href="./download.html">Downloads</a></div><div class="menu2"><a href="http://www.opengl.org/sdk/libs/GLM/">OpenGL SDK page</a></div><br /><div class="menu2"><a href="./glm-0.9.2.pdf">GLM Manual</a></div><div class="menu2"><a href="./api-0.9.2/index.html">GLM API</a></div><div class="menu2"><a href="./code.html">Code samples</a></div><div class="menu2"><a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf">GLSL Specification</a></div><div class="menu2"><a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&amp;Board=10&amp;page=1">OpenGL.org Toolkits forum</a></div><br /><div class="menu2"><a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Report a bug</a></div><div class="menu2"><a href="https://sourceforge.net/projects/ogl-math/">SourceForge page</a></div><div class="menu2"><a href="http://www.g-truc.net/project-0016.html#menu">G-Truc Creation page</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=summary">Browse Git repository</a></div><div class="menu2"><a href="http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz">Source snapshot</a></div><br /><br /><div class="menu2"><a href="http://www.g-truc.net"><img class="menu-img" src="./common/g-truc.png" alt="G-Truc" /></a></div><br /></td><td class="page"><div class="title1"><img src="./common/title.png" alt="OpenGL Mathematics" /></div><div class="title3">GLSL + Optional features = OpenGL Mathematics (GLM)<br />A C++ mathematics library for graphics programming<br /></div><br /><br /><p>
OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software
based on the <a href="http://www.opengl.org/documentation/glsl/">OpenGL Shading Language (GLSL)</a> specification.
</p><p>
@ -33,8 +33,16 @@
</p><p>
Thanks for contributing to the project by <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">submitting tickets</a> for bug reports and feature requests. (SF.net account required).
Any feedback is welcome at glm@g-truc.net.
</p><br /><div><h3>08/06/2011 - GLM 0.9.2.3 released</h3><div><p>
This version only fixes a couple a major bugs introduced in GLM 0.9.2.2.
</p><br /><div><h3>01/10/2011 - GLM 0.9.2.6 released</h3><div><p>
Half based vector types have been fixed on GCC 4.4 and below, missing l-value swizzle operations added and a couple of other bugs squeezed down.
</p><p>
Finally, all the Visual C++ /W4 warnings should have been removed. However, for this to happen, it is required to build with the Visual C++ language extension disabled (/Za).
</p>Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">GLM 0.9.2.6 (zip)</a><br />Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.7z/download">GLM 0.9.2.6 (7z)</a><br />Link: <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Submit a bug report</a><br /></div><br /></div><div><h3>20/09/2011 - GLM 0.9.2.5 released</h3><div><p>
This update fixes some major core issues including the implementation of round, floatBitToXint, pack and unpack functions.
</p>Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.zip/download">GLM 0.9.2.5 (zip)</a><br />Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.7z/download">GLM 0.9.2.5 (7z)</a><br />Link: <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Submit a bug report</a><br /></div><br /></div><div><h3>03/09/2011 - GLM 0.9.2.4 released</h3><div><p>
Fixed bugs and warnings reported by GLM users. Thanks!
</p>Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.zip/download">GLM 0.9.2.4 (zip)</a><br />Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.7z/download">GLM 0.9.2.4 (7z)</a><br />Link: <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Submit a bug report</a><br /></div><br /></div><div><h3>08/06/2011 - GLM 0.9.2.3 released</h3><div><p>
This version only fixes a couple of major bugs introduced in GLM 0.9.2.2.
</p>Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download">GLM 0.9.2.3 (zip)</a><br />Download: <a href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.7z/download">GLM 0.9.2.3 (7z)</a><br />Link: <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">Submit a bug report</a><br /></div><br /></div><div><h3>02/06/2011 - GLM 0.9.2.2 released</h3><div><p>
The main improvement of this version comes from the extended number of matrix constructors so that a programmer can used different scalar types for each parameter.
</p><ul xmlns="http://www.w3.org/1999/xhtml" class="code-list"><li class="code-line"><span class="code-line-content"><span class="keyword">#include </span><span class="string">&lt;glm/glm.hpp&gt;</span></span></li><li class="code-line"><span class="code-line-content" /></li><li class="code-line"><span class="code-line-content"><span class="comment">// Create an identity matrix</span></span></li><li class="code-line"><span class="code-line-content">

View file

@ -265,7 +265,7 @@ void foo()
\section advanced_inline Force Inline
GLM's functions are defined in headers, so they are defined with C++'s "inline" delcaration.
GLM's functions are defined in headers, so they are defined with C++'s "inline" declaration.
This does not require the compiler to inline them, however.
To force the compiler to inline the function, using whatever capabilities that the compiler provides to do so,
GLM_FORCE_INLINE can be defined before any inclusion of <glm/glm.hpp>.

View file

@ -3,6 +3,7 @@
<glm copyright="Copyright © 2005 - 2011">
<downloads>
<section name="GLM - zip files">
<download name="GLM 0.9.2.6" date="01/10/2011" size="3.4 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download"/>
<download name="GLM 0.9.2.5" date="20/09/2011" size="3.4 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.zip/download"/>
<download name="GLM 0.9.2.4" date="03/09/2011" size="3.4 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.zip/download"/>
<download name="GLM 0.9.2.3" date="08/06/2011" size="3.4 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.zip/download"/>
@ -68,6 +69,7 @@
<download name="GLM 0.1.0.0" date="02/21/2005" size="29.2 KB" link="http://prdownloads.sourceforge.net/glf/glm-0.1-ur.zip?download"/>
</section>
<section name="GLM - 7z files">
<download name="GLM 0.9.2.6" date="01/10/2011" size="2.1 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.7z/download"/>
<download name="GLM 0.9.2.5" date="20/09/2011" size="2.1 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.5/glm-0.9.2.5.7z/download"/>
<download name="GLM 0.9.2.4" date="03/09/2011" size="2.1 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.4/glm-0.9.2.4.7z/download"/>
<download name="GLM 0.9.2.3" date="08/06/2011" size="2.1 MB" link="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.3/glm-0.9.2.3.7z/download"/>
@ -160,6 +162,19 @@
</todo>
<page_news>
<news index="0071" date="01/10/2011" title="GLM 0.9.2.6 released" image="goodies/logo.png" image-mini="image/logo-mini.png">
<paragraph>
Half based vector types have been fixed on GCC 4.4 and below, missing l-value swizzle operations added and a couple of other bugs squeezed down.
</paragraph>
<paragraph>
Finally, all the Visual C++ /W4 warnings should have been removed. However, for this to happen, it is required to build with the Visual C++ language extension disabled (/Za).
</paragraph>
<source type="Download" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.zip/download">GLM 0.9.2.6 (zip)</source>
<source type="Download" href="https://sourceforge.net/projects/ogl-math/files/glm-0.9.2.6/glm-0.9.2.6.7z/download">GLM 0.9.2.6 (7z)</source>
<source type="Link" href="https://sourceforge.net/apps/trac/ogl-math/newticket">Submit a bug report</source>
</news>
<news index="0070" date="20/09/2011" title="GLM 0.9.2.5 released" image="goodies/logo.png" image-mini="image/logo-mini.png">
<paragraph>
This update fixes some major core issues including the implementation of round, floatBitToXint, pack and unpack functions.

File diff suppressed because it is too large Load diff

View file

@ -156,13 +156,13 @@ namespace detail
// floor
template <>
GLM_FUNC_QUALIFIER detail::thalf floor<detail::thalf>(detail::thalf const& x)
GLM_FUNC_QUALIFIER detail::thalf floor<detail::thalf>(detail::thalf const & x)
{
return detail::thalf(::std::floor(x.toFloat()));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType floor(genType const& x)
GLM_FUNC_QUALIFIER genType floor(genType const & x)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'floor' only accept floating-point inputs");

View file

@ -22,11 +22,343 @@
///
/// @ref core
/// @file glm/core/func_noise.inl
/// @date 2008-08-01 / 2011-06-15
/// @date 2008-08-01 / 2011-09-27
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
{
template <typename T>
GLM_FUNC_QUALIFIER T noise1(T const & x)
{
return noise1(glm::detail::tvec2<T>(x, T(0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec2<T> noise2(T const & x)
{
return glm::detail::tvec2<T>(
noise1(x + T(0.0)),
noise1(x + T(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec3<T> noise3(T const & x)
{
return glm::detail::tvec3<T>(
noise1(x - T(1.0)),
noise1(x + T(0.0)),
noise1(x + T(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec4<T> noise4(T const & x)
{
return glm::detail::tvec4<T>(
noise1(x - T(1.0)),
noise1(x + T(0.0)),
noise1(x + T(1.0)),
noise1(x + T(2.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER T noise1(glm::detail::tvec2<T> const & v)
{
detail::tvec4<T> const C = detail::tvec4<T>(
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0)
T(-0.577350269189626), // -1.0 + 2.0 * C.x
T( 0.024390243902439)); // 1.0 / 41.0
// First corner
detail::tvec2<T> i = floor(v + dot(v, detail::tvec2<T>(C[1])));
detail::tvec2<T> x0 = v - i + dot(i, detail::tvec2<T>(C[0]));
// Other corners
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
detail::tvec2<T> i1 = (x0.x > x0.y) ? detail::tvec2<T>(1, 0) : detail::tvec2<T>(0, 1);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
detail::tvec4<T> x12 = detail::tvec4<T>(x0.x, x0.y, x0.x, x0.y) + detail::tvec4<T>(C.x, C.x, C.z, C.z);
x12 = detail::tvec4<T>(detail::tvec2<T>(x12) - i1, x12.z, x12.w);
// Permutations
i = mod(i, T(289)); // Avoid truncation effects in permutation
detail::tvec3<T> p = permute(
permute(i.y + detail::tvec3<T>(T(0), i1.y, T(1)))
+ i.x + detail::tvec3<T>(T(0), i1.x, T(1)));
detail::tvec3<T> m = max(T(0.5) - detail::tvec3<T>(
dot(x0, x0),
dot(detail::tvec2<T>(x12.x, x12.y), detail::tvec2<T>(x12.x, x12.y)),
dot(detail::tvec2<T>(x12.z, x12.w), detail::tvec2<T>(x12.z, x12.w))), T(0));
m = m * m ;
m = m * m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
detail::tvec3<T> x = T(2) * fract(p * C.w) - T(1);
detail::tvec3<T> h = abs(x) - T(0.5);
detail::tvec3<T> ox = floor(x + T(0.5));
detail::tvec3<T> a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
m *= T(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
// Compute final noise value at P
detail::tvec3<T> g;
g.x = a0.x * x0.x + h.x * x0.y;
//g.yz = a0.yz * x12.xz + h.yz * x12.yw;
g.y = a0.y * x12.x + h.y * x12.y;
g.z = a0.z * x12.z + h.z * x12.w;
return T(130) * dot(m, g);
}
template <typename T>
GLM_FUNC_QUALIFIER T noise1(detail::tvec3<T> const & v)
{
detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0);
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
// First corner
detail::tvec3<T> i(floor(v + dot(v, detail::tvec3<T>(C.y))));
detail::tvec3<T> x0(v - i + dot(i, detail::tvec3<T>(C.x)));
// Other corners
detail::tvec3<T> g(step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0));
detail::tvec3<T> l(T(1) - g);
detail::tvec3<T> i1(min(g, detail::tvec3<T>(l.z, l.x, l.y)));
detail::tvec3<T> i2(max(g, detail::tvec3<T>(l.z, l.x, l.y)));
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
detail::tvec3<T> x1(x0 - i1 + C.x);
detail::tvec3<T> x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y
detail::tvec3<T> x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
detail::tvec4<T> p(permute(permute(permute(
i.z + detail::tvec4<T>(T(0), i1.z, i2.z, T(1))) +
i.y + detail::tvec4<T>(T(0), i1.y, i2.y, T(1))) +
i.x + detail::tvec4<T>(T(0), i1.x, i2.x, T(1))));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
T n_ = T(0.142857142857); // 1.0/7.0
detail::tvec3<T> ns(n_ * detail::tvec3<T>(D.w, D.y, D.z) - detail::tvec3<T>(D.x, D.z, D.x));
detail::tvec4<T> j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7)
detail::tvec4<T> x_(floor(j * ns.z));
detail::tvec4<T> y_(floor(j - T(7) * x_)); // mod(j,N)
detail::tvec4<T> x(x_ * ns.x + ns.y);
detail::tvec4<T> y(y_ * ns.x + ns.y);
detail::tvec4<T> h(T(1) - abs(x) - abs(y));
detail::tvec4<T> b0(x.x, x.y, y.x, y.y);
detail::tvec4<T> b1(x.z, x.w, y.z, y.w);
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
detail::tvec4<T> s0(floor(b0) * T(2) + T(1));
detail::tvec4<T> s1(floor(b1) * T(2) + T(1));
detail::tvec4<T> sh(-step(h, detail::tvec4<T>(0.0)));
detail::tvec4<T> a0 = detail::tvec4<T>(b0.x, b0.z, b0.y, b0.w) + detail::tvec4<T>(s0.x, s0.z, s0.y, s0.w) * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
detail::tvec4<T> a1 = detail::tvec4<T>(b1.x, b1.z, b1.y, b1.w) + detail::tvec4<T>(s1.x, s1.z, s1.y, s1.w) * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
detail::tvec3<T> p0(a0.x, a0.y, h.x);
detail::tvec3<T> p1(a0.z, a0.w, h.y);
detail::tvec3<T> p2(a1.x, a1.y, h.z);
detail::tvec3<T> p3(a1.z, a1.w, h.w);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0));
m = m * m;
return T(42) * dot(m * m, detail::tvec4<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
template <typename T>
GLM_FUNC_QUALIFIER T noise1(detail::tvec4<T> const & v)
{
detail::tvec4<T> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4 = T(0.309016994374947451);
// First corner
detail::tvec4<T> i = floor(v + dot(v, vec4(F4)));
detail::tvec4<T> x0 = v - i + dot(i, vec4(C.x));
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
detail::tvec4<T> i0;
detail::tvec3<T> isX = step(detail::tvec3<T>(x0.y, x0.z, x0.w), detail::tvec3<T>(x0.x));
detail::tvec3<T> isYZ = step(detail::tvec3<T>(x0.z, x0.w, x0.w), detail::tvec3<T>(x0.y, x0.y, x0.z));
// i0.x = dot(isX, vec3(1.0));
//i0.x = isX.x + isX.y + isX.z;
//i0.yzw = T(1) - isX;
i0 = detail::tvec4<T>(isX.x + isX.y + isX.z, T(1) - isX);
// i0.y += dot(isYZ.xy, vec2(1.0));
i0.y += isYZ.x + isYZ.y;
//i0.zw += 1.0 - detail::tvec2<T>(isYZ.x, isYZ.y);
i0.z += T(1) - isYZ.x;
i0.w += T(1) - isYZ.y;
i0.z += isYZ.z;
i0.w += T(1) - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
detail::tvec4<T> i3 = clamp(i0, 0.0, 1.0);
detail::tvec4<T> i2 = clamp(i0 - 1.0, 0.0, 1.0);
detail::tvec4<T> i1 = clamp(i0 - 2.0, 0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 0.0 * C.xxxx
// x2 = x0 - i2 + 0.0 * C.xxxx
// x3 = x0 - i3 + 0.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
detail::tvec4<T> x1 = x0 - i1 + C.x;
detail::tvec4<T> x2 = x0 - i2 + C.y;
detail::tvec4<T> x3 = x0 - i3 + C.z;
detail::tvec4<T> x4 = x0 + C.w;
// Permutations
i = mod(i, T(289));
T j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);
detail::tvec4<T> j1 = permute(permute(permute(permute(
i.w + detail::tvec4<T>(i1.w, i2.w, i3.w, T(1)))
+ i.z + detail::tvec4<T>(i1.z, i2.z, i3.z, T(1)))
+ i.y + detail::tvec4<T>(i1.y, i2.y, i3.y, T(1)))
+ i.x + detail::tvec4<T>(i1.x, i2.x, i3.x, T(1)));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
detail::tvec4<T> ip = detail::tvec4<T>(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0));
detail::tvec4<T> p0 = grad4(j0, ip);
detail::tvec4<T> p1 = grad4(j1.x, ip);
detail::tvec4<T> p2 = grad4(j1.y, ip);
detail::tvec4<T> p3 = grad4(j1.z, ip);
detail::tvec4<T> p4 = grad4(j1.w, ip);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4, p4));
// Mix contributions from the five corners
detail::tvec3<T> m0 = max(T(0.6) - detail::tvec3<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2)), T(0));
detail::tvec2<T> m1 = max(T(0.6) - detail::tvec2<T>(dot(x3, x3), dot(x4, x4) ), T(0));
m0 = m0 * m0;
m1 = m1 * m1;
return T(49) *
(dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) +
dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4))));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec2<T> noise2(glm::detail::tvec2<T> const & x)
{
return glm::detail::tvec2<T>(
noise1(x + glm::detail::tvec2<T>(0.0)),
noise1(glm::detail::tvec2<T>(0.0) - x));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec2<T> noise2(glm::detail::tvec3<T> const & x)
{
return glm::detail::tvec2<T>(
noise1(x + glm::detail::tvec3<T>(0.0)),
noise1(glm::detail::tvec3<T>(0.0) - x));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec2<T> noise2(glm::detail::tvec4<T> const & x)
{
return glm::detail::tvec2<T>(
noise1(x + glm::detail::tvec4<T>(0.0)),
noise1(glm::detail::tvec4<T>(0.0) - x));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec3<T> noise3(glm::detail::tvec2<T> const & x)
{
return glm::detail::tvec3<T>(
noise1(x - glm::detail::tvec2<T>(1.0)),
noise1(x + glm::detail::tvec2<T>(0.0)),
noise1(x + glm::detail::tvec2<T>(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec3<T> noise3(glm::detail::tvec3<T> const & x)
{
return glm::detail::tvec3<T>(
noise1(x - glm::detail::tvec3<T>(1.0)),
noise1(x + glm::detail::tvec3<T>(0.0)),
noise1(x + glm::detail::tvec3<T>(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec3<T> noise3(glm::detail::tvec4<T> const & x)
{
return glm::detail::tvec3<T>(
noise1(x - glm::detail::tvec4<T>(1.0)),
noise1(x + glm::detail::tvec4<T>(0.0)),
noise1(x + glm::detail::tvec4<T>(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec4<T> noise4(glm::detail::tvec2<T> const & x)
{
return glm::detail::tvec4<T>(
noise1(x - glm::detail::tvec2<T>(1.0)),
noise1(x + glm::detail::tvec2<T>(0.0)),
noise1(x + glm::detail::tvec2<T>(1.0)),
noise1(x + glm::detail::tvec2<T>(2.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec4<T> noise4(glm::detail::tvec3<T> const & x)
{
return glm::detail::tvec4<T>(
noise1(x - glm::detail::tvec3<T>(1.0)),
noise1(x + glm::detail::tvec3<T>(0.0)),
noise1(x + glm::detail::tvec3<T>(1.0)),
noise1(x + glm::detail::tvec3<T>(2.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER glm::detail::tvec4<T> noise4(glm::detail::tvec4<T> const & x)
{
return glm::detail::tvec4<T>(
noise1(x - glm::detail::tvec4<T>(1.0)),
noise1(x + glm::detail::tvec4<T>(0.0)),
noise1(x + glm::detail::tvec4<T>(1.0)),
noise1(x + glm::detail::tvec4<T>(2.0)));
}
}//namespace glm

View file

@ -144,7 +144,7 @@ GLM_FUNC_QUALIFIER detail::tvec2<uint> unpackDouble2x32(double const & v)
return *(detail::tvec2<uint>*)&v;
}
GLM_FUNC_QUALIFIER uint packHalf2x16(vec2 const & v)
GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2<float> const & v)
{
detail::tvec2<detail::hdata> Pack(detail::toFloat16(v.x), detail::toFloat16(v.y));
return *(uint*)&Pack;

View file

@ -29,6 +29,9 @@
namespace glm{
namespace detail{
#pragma warning(push)
#pragma warning(disable : 4510 4512 4610)
union ieee754_QNAN
{
const float f;
@ -40,6 +43,8 @@ namespace detail{
ieee754_QNAN() : f(0.0)/*, mantissa(0x7FFFFF), exp(0xFF), sign(0x0)*/ {}
};
#pragma warning(pop)
static const __m128 GLM_VAR_USED zero = _mm_setzero_ps();
static const __m128 GLM_VAR_USED one = _mm_set_ps1(1.0f);
static const __m128 GLM_VAR_USED minus_one = _mm_set_ps1(-1.0f);
@ -224,11 +229,13 @@ GLM_FUNC_QUALIFIER __m128 sse_mod_ps(__m128 x, __m128 y)
}
/// TODO
/*
GLM_FUNC_QUALIFIER __m128 sse_modf_ps(__m128 x, __m128i & i)
{
__m128 empty;
return empty;
}
*/
//GLM_FUNC_QUALIFIER __m128 _mm_min_ps(__m128 x, __m128 y)
@ -273,18 +280,18 @@ GLM_FUNC_QUALIFIER __m128 sse_ssp_ps(__m128 edge0, __m128 edge1, __m128 x)
}
/// \todo
GLM_FUNC_QUALIFIER __m128 sse_nan_ps(__m128 x)
{
__m128 empty;
return empty;
}
//GLM_FUNC_QUALIFIER __m128 sse_nan_ps(__m128 x)
//{
// __m128 empty;
// return empty;
//}
/// \todo
GLM_FUNC_QUALIFIER __m128 sse_inf_ps(__m128 x)
{
__m128 empty;
return empty;
}
//GLM_FUNC_QUALIFIER __m128 sse_inf_ps(__m128 x)
//{
// __m128 empty;
// return empty;
//}
// SSE scalar reciprocal sqrt using rsqrt op, plus one Newton-Rhaphson iteration
// By Elan Ruskin, http://assemblyrequired.crashworks.org/

View file

@ -60,7 +60,7 @@ namespace detail
//
detail::uif result;
result.i = s << 31;
result.i = (unsigned int)(s << 31);
return result.f;
}
else
@ -88,7 +88,7 @@ namespace detail
//
uif result;
result.i = (s << 31) | 0x7f800000;
result.i = (unsigned int)((s << 31) | 0x7f800000);
return result.f;
}
else
@ -98,7 +98,7 @@ namespace detail
//
uif result;
result.i = (s << 31) | 0x7f800000 | (m << 13);
result.i = (unsigned int)((s << 31) | 0x7f800000 | (m << 13));
return result.f;
}
}
@ -115,7 +115,7 @@ namespace detail
//
uif Result;
Result.i = (s << 31) | (e << 23) | m;
Result.i = (unsigned int)((s << 31) | (e << 23) | m);
return Result.f;
}
@ -123,7 +123,7 @@ namespace detail
{
uif Entry;
Entry.f = f;
int i = Entry.i;
int i = (int)Entry.i;
//
// Our floating point number, f, is represented by the bit

View file

@ -220,8 +220,10 @@ namespace detail
GLM_FUNC_DECL tref2<T> & operator= (tref2<T> const & r);
GLM_FUNC_DECL tref2<T> & operator= (tvec2<T> const & v);
T& x;
T& y;
GLM_FUNC_DECL tvec2<T> operator() ();
T & x;
T & y;
};
GLM_DETAIL_IS_VECTOR(tvec2);

View file

@ -1025,5 +1025,11 @@ namespace detail
return *this;
}
template <typename T>
GLM_FUNC_QUALIFIER tvec2<T> tref2<T>::operator() ()
{
return tvec2<T>(this->x, this->y);
}
}//namespace detail
}//namespace glm

View file

@ -64,7 +64,7 @@ namespace detail
# if(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
value_type x, y, z;
# elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT)
# elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT || GLM_LANG == GLM_LANG_CXX0X)
union
{
_GLM_SWIZZLE3_2_MEMBERS(value_type,glm::detail::tvec2<value_type>,x,y,z)
@ -111,17 +111,6 @@ namespace detail
value_type const & s2,
value_type const & s3);
//////////////////////////////////////
// Swizzle constructors
GLM_FUNC_DECL tvec3(tref3<T> const & r);
template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec3(const glm::detail::swizzle<3,T,tvec3<T>,E0,E1,E2,-1>& that)
{
*this = that();
}
//////////////////////////////////////
// Convertion scalar constructors
@ -152,6 +141,23 @@ namespace detail
template <typename U>
GLM_FUNC_DECL explicit tvec3(tvec4<U> const & v);
//////////////////////////////////////
// Swizzle constructors
GLM_FUNC_DECL tvec3(tref3<T> const & r);
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec3(tref2<A> const & v, B const & s);
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec3(A const & s, tref2<B> const & v);
template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec3(glm::detail::swizzle<3, T, tvec3<T>, E0, E1, E2, -1> const & that)
{
*this = that();
}
//////////////////////////////////////
// Unary arithmetic operators
@ -213,6 +219,7 @@ namespace detail
GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
GLM_FUNC_DECL tref2<T> swizzle(comp X, comp Y);
GLM_FUNC_DECL tref3<T> swizzle(comp X, comp Y, comp Z);
};
@ -226,6 +233,8 @@ namespace detail
GLM_FUNC_DECL tref3<T> & operator= (tref3<T> const & r);
GLM_FUNC_DECL tref3<T> & operator= (tvec3<T> const & v);
GLM_FUNC_DECL tvec3<T> operator() ();
T & x;
T & y;
T & z;

View file

@ -131,6 +131,30 @@ namespace detail
z(r.z)
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec3<T>::tvec3
(
tref2<A> const & v,
B const & s
) :
x(value_type(v.x)),
y(value_type(v.y)),
z(value_type(s))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec3<T>::tvec3
(
A const & s,
tref2<B> const & v
) :
x(value_type(s)),
y(value_type(v.x)),
z(value_type(v.y))
{}
//////////////////////////////////////
// Convertion scalar constructors
@ -594,6 +618,18 @@ namespace detail
(*this)[w]);
}
template <typename T>
GLM_FUNC_QUALIFIER tref2<T> tvec3<T>::swizzle
(
comp x,
comp y
)
{
return tref2<T>(
(*this)[x],
(*this)[y]);
}
template <typename T>
GLM_FUNC_QUALIFIER tref3<T> tvec3<T>::swizzle
(
@ -1112,5 +1148,11 @@ namespace detail
return *this;
}
template <typename T>
GLM_FUNC_QUALIFIER tvec3<T> tref3<T>::operator() ()
{
return tvec3<T>(this->x, this->y, this->z);
}
}//namespace detail
}//namespace glm

View file

@ -113,17 +113,6 @@ namespace detail
value_type const & s2,
value_type const & s3);
//////////////////////////////////////
// Swizzle constructors
GLM_FUNC_DECL tvec4(tref4<T> const & r);
template <int E0, int E1, int E2, int E3>
GLM_FUNC_DECL tvec4(const glm::detail::swizzle<4,T,tvec4<T>,E0,E1,E2,E3>& that)
{
*this = that();
}
//////////////////////////////////////
// Convertion scalar constructors
@ -164,6 +153,42 @@ namespace detail
template <typename U>
GLM_FUNC_DECL explicit tvec4(tvec4<U> const & v);
template <int E0, int E1, int E2, int E3>
GLM_FUNC_DECL tvec4(glm::detail::swizzle<4, T, tvec4<T>, E0, E1, E2, E3> const & that)
{
*this = that();
}
//////////////////////////////////////
// Swizzle constructors
GLM_FUNC_DECL tvec4(tref4<T> const & r);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B, typename C>
GLM_FUNC_DECL explicit tvec4(tref2<A> const & v, B const & s1, C const & s2);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B, typename C>
GLM_FUNC_DECL explicit tvec4(A const & s1, tref2<B> const & v, C const & s2);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B, typename C>
GLM_FUNC_DECL explicit tvec4(A const & s1, B const & s2, tref2<C> const & v);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec4(tref3<A> const & v, B const & s);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec4(A const & s, tref3<B> const & v);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec4(tref2<A> const & v1, tref2<B> const & v2);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec4(tvec2<A> const & v1, tref2<B> const & v2);
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename A, typename B>
GLM_FUNC_DECL explicit tvec4(tref2<A> const & v1, tvec2<B> const & v2);
//////////////////////////////////////
// Unary arithmetic operators
@ -225,6 +250,8 @@ namespace detail
GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
GLM_FUNC_DECL tref2<T> swizzle(comp X, comp Y);
GLM_FUNC_DECL tref3<T> swizzle(comp X, comp Y, comp Z);
GLM_FUNC_DECL tref4<T> swizzle(comp X, comp Y, comp Z, comp W);
};
@ -238,6 +265,8 @@ namespace detail
GLM_FUNC_DECL tref4<T> & operator= (tref4<T> const & r);
GLM_FUNC_DECL tref4<T> & operator= (tvec4<T> const & v);
GLM_FUNC_DECL tvec4<T> operator() ();
T & x;
T & y;
T & z;

View file

@ -137,6 +137,113 @@ namespace detail
w(r.w)
{}
template <typename T>
template <typename A, typename B, typename C>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
tref2<A> const & v,
B const & s1,
C const & s2
) :
x(value_type(v.x)),
y(value_type(v.y)),
z(value_type(s1)),
w(value_type(s2))
{}
template <typename T>
template <typename A, typename B, typename C>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
A const & s1,
tref2<B> const & v,
C const & s2
) :
x(value_type(s1)),
y(value_type(v.x)),
z(value_type(v.y)),
w(value_type(s2))
{}
template <typename T>
template <typename A, typename B, typename C>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
A const & s1,
B const & s2,
tref2<C> const & v
) :
x(value_type(s1)),
y(value_type(s2)),
z(value_type(v.x)),
w(value_type(v.y))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
tref3<A> const & v,
B const & s
) :
x(value_type(v.x)),
y(value_type(v.y)),
z(value_type(v.z)),
w(value_type(s))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
A const & s,
tref3<B> const & v
) :
x(value_type(s)),
y(value_type(v.x)),
z(value_type(v.y)),
w(value_type(v.z))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
tref2<A> const & v1,
tref2<B> const & v2
) :
x(value_type(v1.x)),
y(value_type(v1.y)),
z(value_type(v2.x)),
w(value_type(v2.y))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
tvec2<A> const & v1,
tref2<B> const & v2
) :
x(value_type(v1.x)),
y(value_type(v1.y)),
z(value_type(v2.x)),
w(value_type(v2.y))
{}
template <typename T>
template <typename A, typename B>
GLM_FUNC_QUALIFIER tvec4<T>::tvec4
(
tref2<A> const & v1,
tvec2<B> const & v2
) :
x(value_type(v1.x)),
y(value_type(v1.y)),
z(value_type(v2.x)),
w(value_type(v2.y))
{}
//////////////////////////////////////
// Convertion scalar constructors
@ -651,6 +758,32 @@ namespace detail
(*this)[w]);
}
template <typename T>
GLM_FUNC_QUALIFIER tref2<T> tvec4<T>::swizzle
(
comp x,
comp y
)
{
return tref2<T>(
(*this)[x],
(*this)[y]);
}
template <typename T>
GLM_FUNC_QUALIFIER tref3<T> tvec4<T>::swizzle
(
comp x,
comp y,
comp z
)
{
return tref3<T>(
(*this)[x],
(*this)[y],
(*this)[z]);
}
template <typename T>
GLM_FUNC_QUALIFIER tref4<T> tvec4<T>::swizzle
(
@ -1241,5 +1374,11 @@ namespace detail
return *this;
}
template <typename T>
GLM_FUNC_QUALIFIER tvec4<T> tref4<T>::operator() ()
{
return tvec4<T>(this->x, this->y, this->z, this->w);
}
}//namespace detail
}//namespace glm

81
glm/gtc/noise.hpp Normal file
View file

@ -0,0 +1,81 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 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.
///
/// 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 gtc_noise
/// @file glm/gtc/noise.hpp
/// @date 2011-04-21 / 2011-09-27
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_noise GLM_GTX_noise: Procedural noise functions
/// @ingroup gtx
///
/// Defines 2D, 3D and 4D procedural noise functions
/// Based on the work of Stefan Gustavson and Ashima Arts on "webgl-noise":
/// https://github.com/ashima/webgl-noise
/// Following Stefan Gustavson's paper "Simplex noise demystified":
/// http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
/// Defines the half-precision floating-point type, along with various typedefs for vectors and matrices.
/// <glm/gtx/noise.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#ifndef GLM_GTC_noise
#define GLM_GTC_noise GLM_VERSION
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
# pragma message("GLM: GLM_GTC_noise extension included")
#endif
namespace glm
{
/// @addtogroup gtx_noise
/// @{
/// Classic perlin noise.
/// From GLM_GTC_noise extension.
template <typename T, template<typename> class vecType>
T perlin(
vecType<T> const & p);
/// Periodic perlin noise.
/// From GLM_GTC_noise extension.
template <typename T, template<typename> class vecType>
T perlin(
vecType<T> const & p,
vecType<T> const & rep);
/// Simplex noise.
/// From GLM_GTC_noise extension.
template <typename T, template<typename> class vecType>
T simplex(
vecType<T> const & p);
/// @}
}//namespace glm
#include "noise.inl"
#endif//GLM_GTC_noise

852
glm/gtc/noise.inl Normal file
View file

@ -0,0 +1,852 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Based on the work of Stefan Gustavson and Ashima Arts on "webgl-noise":
// https://github.com/ashima/webgl-noise
// Following Stefan Gustavson's paper "Simplex noise demystified":
// http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-21
// Updated : 2011-09-27
// Licence : This source is under MIT License
// File : glm/gtc/noise.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
// Dependency:
// - GLM core
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm{
template <typename T>
GLM_FUNC_QUALIFIER T mod289(T const & x)
{
return x - floor(x * T(1.0 / 289.0)) * T(289.0);
}
template <typename T>
GLM_FUNC_QUALIFIER T permute(T const & x)
{
return mod289(((x * T(34)) + T(1)) * x);
}
template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x)
{
return mod289(((x * T(34)) + T(1)) * x);
}
template <typename T>
GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r)
{
return T(1.79284291400159) - T(0.85373472095314) * r;
}
template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r)
{
return T(1.79284291400159) - T(0.85373472095314) * r;
}
template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t)
{
return t * t * t * (t * (t * T(6) - T(15)) + T(10));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip)
{
detail::tvec3<T> pXYZ = floor(fract(detail::tvec3<T>(j) * detail::tvec3<T>(ip)) * T(7)) * ip[2] - T(1);
T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T>(1));
detail::tvec4<T> s = detail::tvec4<T>(lessThan(detail::tvec4<T>(pXYZ, pW), detail::tvec4<T>(0.0)));
pXYZ = pXYZ + (detail::tvec3<T>(s) * T(2) - T(1)) * s.w;
return detail::tvec4<T>(pXYZ, pW);
}
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
{
detail::tvec4<T> Pi = glm::floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = glm::fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix(Pi.x, Pi.z, Pi.x, Pi.z);
detail::tvec4<T> iy(Pi.y, Pi.y, Pi.w, Pi.w);
detail::tvec4<T> fx(Pf.x, Pf.z, Pf.x, Pf.z);
detail::tvec4<T> fy(Pf.y, Pf.y, Pf.w, Pf.w);
detail::tvec4<T> i = glm::permute(glm::permute(ix) + iy);
detail::tvec4<T> gx = T(2) * glm::fract(i / T(41)) - T(1);
detail::tvec4<T> gy = glm::abs(gx) - T(0.5);
detail::tvec4<T> tx = glm::floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00(gx.x, gy.x);
detail::tvec2<T> g10(gx.y, gy.y);
detail::tvec2<T> g01(gx.z, gy.z);
detail::tvec2<T> g11(gx.w, gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(detail::tvec2<T>(Pf.x, Pf.y));
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy;
}
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod289(Pi0);
Pi1 = mod289(Pi1);
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(detail::tvec2<T>(Pi0.y), detail::tvec2<T>(Pi1.y));
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 * T(1.0 / 7.0);
detail::tvec4<T> gy0 = fract(floor(gx0) * T(1.0 / 7.0)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0.0));
gx0 -= sz0 * (step(T(0), gx0) - T(0.5));
gy0 -= sz0 * (step(T(0), gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 * T(1.0 / 7.0);
detail::tvec4<T> gy1 = fract(floor(gx1) * T(1.0 / 7.0)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(T(0), gx1) - T(0.5));
gy1 -= sz1 * (step(T(0), gy1) - T(0.5));
detail::tvec3<T> g000(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
/*
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 / T(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0.0));
gx0 -= sz0 * (step(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(T(0), gx1) - T(0.5));
gy1 -= sz1 * (step(T(0), gy1) - T(0.5));
detail::tvec3<T> g000(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(
detail::tvec2<T>(n_z.x, n_z.y),
detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
*/
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P)
{
detail::tvec4<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec4<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec4<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = detail::tvec4<T>(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, detail::tvec4<T>(0.0));
gx00 -= sw00 * (step(T(0), gx00) - T(0.5));
gy00 -= sw00 * (step(T(0), gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = detail::tvec4<T>(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, detail::tvec4<T>(0.0));
gx01 -= sw01 * (step(T(0), gx01) - T(0.5));
gy01 -= sw01 * (step(T(0), gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0));
gx10 -= sw10 * (step(T(0), gx10) - T(0.5));
gy10 -= sw10 * (step(T(0), gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, detail::tvec4<T>(0.0));
gx11 -= sw11 * (step(T(0), gx11) - T(0.5));
gy11 -= sw11 * (step(T(0), gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf0.w));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf0.w));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf0.w));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.x, Pf1.y, Pf1.z, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.x, Pf0.y, Pf0.z, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf1.w));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf1.w));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf1.w));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw;
}
// Classic Perlin noise, periodic variant
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
{
detail::tvec4<T> Pi = floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, detail::tvec4<T>(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix(Pi.x, Pi.z, Pi.x, Pi.z);
detail::tvec4<T> iy(Pi.y, Pi.y, Pi.w, Pi.w);
detail::tvec4<T> fx(Pf.x, Pf.z, Pf.x, Pf.z);
detail::tvec4<T> fy(Pf.y, Pf.y, Pf.w, Pf.w);
detail::tvec4<T> i = permute(permute(ix) + iy);
detail::tvec4<T> gx = T(2) * fract(i / T(41)) - T(1);
detail::tvec4<T> gy = abs(gx) - T(0.5);
detail::tvec4<T> tx = floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00(gx.x, gy.x);
detail::tvec2<T> g10(gx.y, gy.y);
detail::tvec2<T> g01(gx.z, gy.z);
detail::tvec2<T> g11(gx.w, gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(detail::tvec2<T>(Pf.x, Pf.y));
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy;
}
// Classic Perlin noise, periodic variant
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep)
{
detail::tvec3<T> Pi0 = mod(floor(P), rep); // Integer part, modulo period
detail::tvec3<T> Pi1 = mod(Pi0 + detail::tvec3<T>(1.0), rep); // Integer part + 1, mod period
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - detail::tvec3<T>(1.0); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 / T(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0));
gx0 -= sz0 * (step(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(0.0, gx1) - T(0.5));
gy1 -= sz1 * (step(0.0, gy1) - T(0.5));
detail::tvec3<T> g000 = detail::tvec3<T>(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100 = detail::tvec3<T>(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010 = detail::tvec3<T>(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110 = detail::tvec3<T>(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001 = detail::tvec3<T>(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101 = detail::tvec3<T>(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011 = detail::tvec3<T>(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111 = detail::tvec3<T>(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
// Classic Perlin noise, periodic version
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep)
{
detail::tvec4<T> Pi0 = mod(floor(P), rep); // Integer part modulo rep
detail::tvec4<T> Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec4<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = detail::tvec4<T>(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, detail::tvec4<T>(0));
gx00 -= sw00 * (step(0.0, gx00) - T(0.5));
gy00 -= sw00 * (step(0.0, gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = detail::tvec4<T>(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, detail::tvec4<T>(0.0));
gx01 -= sw01 * (step(0.0, gx01) - T(0.5));
gy01 -= sw01 * (step(0.0, gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0.0));
gx10 -= sw10 * (step(0.0, gx10) - T(0.5));
gy10 -= sw10 * (step(0.0, gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, detail::tvec4<T>(0.0));
gx11 -= sw11 * (step(0.0, gx11) - T(0.5));
gy11 -= sw11 * (step(0.0, gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf0.w));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf0.w));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf0.w));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.x, Pf1.y, Pf1.z, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.x, Pf0.y, Pf0.z, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf1.w));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf1.w));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf1.w));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw;
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v)
{
detail::tvec4<T> const C = detail::tvec4<T>(
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0)
T(-0.577350269189626), // -1.0 + 2.0 * C.x
T( 0.024390243902439)); // 1.0 / 41.0
// First corner
detail::tvec2<T> i = floor(v + dot(v, detail::tvec2<T>(C[1])));
detail::tvec2<T> x0 = v - i + dot(i, detail::tvec2<T>(C[0]));
// Other corners
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
detail::tvec2<T> i1 = (x0.x > x0.y) ? detail::tvec2<T>(1, 0) : detail::tvec2<T>(0, 1);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
detail::tvec4<T> x12 = detail::tvec4<T>(x0.x, x0.y, x0.x, x0.y) + detail::tvec4<T>(C.x, C.x, C.z, C.z);
x12 = detail::tvec4<T>(detail::tvec2<T>(x12) - i1, x12.z, x12.w);
// Permutations
i = mod(i, T(289)); // Avoid truncation effects in permutation
detail::tvec3<T> p = permute(
permute(i.y + detail::tvec3<T>(T(0), i1.y, T(1)))
+ i.x + detail::tvec3<T>(T(0), i1.x, T(1)));
detail::tvec3<T> m = max(T(0.5) - detail::tvec3<T>(
dot(x0, x0),
dot(detail::tvec2<T>(x12.x, x12.y), detail::tvec2<T>(x12.x, x12.y)),
dot(detail::tvec2<T>(x12.z, x12.w), detail::tvec2<T>(x12.z, x12.w))), T(0));
m = m * m ;
m = m * m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
detail::tvec3<T> x = T(2) * fract(p * C.w) - T(1);
detail::tvec3<T> h = abs(x) - T(0.5);
detail::tvec3<T> ox = floor(x + T(0.5));
detail::tvec3<T> a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
m *= T(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
// Compute final noise value at P
detail::tvec3<T> g;
g.x = a0.x * x0.x + h.x * x0.y;
//g.yz = a0.yz * x12.xz + h.yz * x12.yw;
g.y = a0.y * x12.x + h.y * x12.y;
g.z = a0.z * x12.z + h.z * x12.w;
return T(130) * dot(m, g);
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
{
detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0);
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
// First corner
detail::tvec3<T> i(floor(v + dot(v, detail::tvec3<T>(C.y))));
detail::tvec3<T> x0(v - i + dot(i, detail::tvec3<T>(C.x)));
// Other corners
detail::tvec3<T> g(step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0));
detail::tvec3<T> l(T(1) - g);
detail::tvec3<T> i1(min(g, detail::tvec3<T>(l.z, l.x, l.y)));
detail::tvec3<T> i2(max(g, detail::tvec3<T>(l.z, l.x, l.y)));
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
detail::tvec3<T> x1(x0 - i1 + C.x);
detail::tvec3<T> x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y
detail::tvec3<T> x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
detail::tvec4<T> p(permute(permute(permute(
i.z + detail::tvec4<T>(T(0), i1.z, i2.z, T(1))) +
i.y + detail::tvec4<T>(T(0), i1.y, i2.y, T(1))) +
i.x + detail::tvec4<T>(T(0), i1.x, i2.x, T(1))));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
T n_ = T(0.142857142857); // 1.0/7.0
detail::tvec3<T> ns(n_ * detail::tvec3<T>(D.w, D.y, D.z) - detail::tvec3<T>(D.x, D.z, D.x));
detail::tvec4<T> j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7)
detail::tvec4<T> x_(floor(j * ns.z));
detail::tvec4<T> y_(floor(j - T(7) * x_)); // mod(j,N)
detail::tvec4<T> x(x_ * ns.x + ns.y);
detail::tvec4<T> y(y_ * ns.x + ns.y);
detail::tvec4<T> h(T(1) - abs(x) - abs(y));
detail::tvec4<T> b0(x.x, x.y, y.x, y.y);
detail::tvec4<T> b1(x.z, x.w, y.z, y.w);
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
detail::tvec4<T> s0(floor(b0) * T(2) + T(1));
detail::tvec4<T> s1(floor(b1) * T(2) + T(1));
detail::tvec4<T> sh(-step(h, detail::tvec4<T>(0.0)));
detail::tvec4<T> a0 = detail::tvec4<T>(b0.x, b0.z, b0.y, b0.w) + detail::tvec4<T>(s0.x, s0.z, s0.y, s0.w) * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
detail::tvec4<T> a1 = detail::tvec4<T>(b1.x, b1.z, b1.y, b1.w) + detail::tvec4<T>(s1.x, s1.z, s1.y, s1.w) * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
detail::tvec3<T> p0(a0.x, a0.y, h.x);
detail::tvec3<T> p1(a0.z, a0.w, h.y);
detail::tvec3<T> p2(a1.x, a1.y, h.z);
detail::tvec3<T> p3(a1.z, a1.w, h.w);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0));
m = m * m;
return T(42) * dot(m * m, detail::tvec4<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v)
{
detail::tvec4<T> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4 = T(0.309016994374947451);
// First corner
detail::tvec4<T> i = floor(v + dot(v, vec4(F4)));
detail::tvec4<T> x0 = v - i + dot(i, vec4(C.x));
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
detail::tvec4<T> i0;
detail::tvec3<T> isX = step(detail::tvec3<T>(x0.y, x0.z, x0.w), detail::tvec3<T>(x0.x));
detail::tvec3<T> isYZ = step(detail::tvec3<T>(x0.z, x0.w, x0.w), detail::tvec3<T>(x0.y, x0.y, x0.z));
// i0.x = dot(isX, vec3(1.0));
//i0.x = isX.x + isX.y + isX.z;
//i0.yzw = T(1) - isX;
i0 = detail::tvec4<T>(isX.x + isX.y + isX.z, T(1) - isX);
// i0.y += dot(isYZ.xy, vec2(1.0));
i0.y += isYZ.x + isYZ.y;
//i0.zw += 1.0 - detail::tvec2<T>(isYZ.x, isYZ.y);
i0.z += T(1) - isYZ.x;
i0.w += T(1) - isYZ.y;
i0.z += isYZ.z;
i0.w += T(1) - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
detail::tvec4<T> i3 = clamp(i0, 0.0, 1.0);
detail::tvec4<T> i2 = clamp(i0 - 1.0, 0.0, 1.0);
detail::tvec4<T> i1 = clamp(i0 - 2.0, 0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 0.0 * C.xxxx
// x2 = x0 - i2 + 0.0 * C.xxxx
// x3 = x0 - i3 + 0.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
detail::tvec4<T> x1 = x0 - i1 + C.x;
detail::tvec4<T> x2 = x0 - i2 + C.y;
detail::tvec4<T> x3 = x0 - i3 + C.z;
detail::tvec4<T> x4 = x0 + C.w;
// Permutations
i = mod(i, T(289));
T j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);
detail::tvec4<T> j1 = permute(permute(permute(permute(
i.w + detail::tvec4<T>(i1.w, i2.w, i3.w, T(1)))
+ i.z + detail::tvec4<T>(i1.z, i2.z, i3.z, T(1)))
+ i.y + detail::tvec4<T>(i1.y, i2.y, i3.y, T(1)))
+ i.x + detail::tvec4<T>(i1.x, i2.x, i3.x, T(1)));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
detail::tvec4<T> ip = detail::tvec4<T>(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0));
detail::tvec4<T> p0 = grad4(j0, ip);
detail::tvec4<T> p1 = grad4(j1.x, ip);
detail::tvec4<T> p2 = grad4(j1.y, ip);
detail::tvec4<T> p3 = grad4(j1.z, ip);
detail::tvec4<T> p4 = grad4(j1.w, ip);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4, p4));
// Mix contributions from the five corners
detail::tvec3<T> m0 = max(T(0.6) - detail::tvec3<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2)), T(0));
detail::tvec2<T> m1 = max(T(0.6) - detail::tvec2<T>(dot(x3, x3), dot(x4, x4) ), T(0));
m0 = m0 * m0;
m1 = m1 * m1;
return T(49) *
(dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) +
dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4))));
}
}//namespace glm

View file

@ -65,21 +65,46 @@ namespace glm
genType const & Max);
/// Generate random numbers in the interval [Min, Max], according a gaussian distribution
/// (From GLM_GTX_random extension)
template <typename T, template <typename> class vecType>
vecType<T> gaussRand(
vecType<T> const & Mean,
vecType<T> const & Deviation);
///
/// @param Mean
/// @param Deviation
/// @see gtc_random
template <typename genType>
genType gaussRand(
genType const & Mean,
genType const & Deviation);
/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
/// (From GLM_GTX_random extension)
///
/// @param Radius
/// @see gtc_random
template <typename T>
detail::tvec2<T> circularRand(T const & Radius);
detail::tvec2<T> circularRand(
T const & Radius);
/// Generate a random 3D vector which coordinates are regulary distributed on a sphere of a given radius
/// (From GLM_GTX_random extension)
///
/// @param Radius
/// @see gtc_random
template <typename T>
detail::tvec3<T> sphericalRand(T const & Radius);
detail::tvec3<T> sphericalRand(
T const & Radius);
/// Generate a random 2D vector which coordinates are regulary distributed within the area of a disk of a given radius
///
/// @param Radius
/// @see gtc_random
template <typename T>
detail::tvec2<T> diskRand(
T const & Radius);
/// Generate a random 3D vector which coordinates are regulary distributed within the volume of a ball of a given radius
///
/// @param Radius
/// @see gtc_random
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand(
T const & Radius);
/// @}
}//namespace glm

View file

@ -12,5 +12,197 @@
namespace glm{
template <>
GLM_FUNC_QUALIFIER glm::half linearRand
(
glm::half const & Min,
glm::half const & Max
)
{
return glm::half(float(std::rand()) / float(RAND_MAX) * (float(Max) - float(Min)) + float(Min));
}
template <>
GLM_FUNC_QUALIFIER float linearRand
(
float const & Min,
float const & Max
)
{
return float(std::rand()) / float(RAND_MAX) * (Max - Min) + Min;
}
template <>
GLM_FUNC_QUALIFIER double linearRand
(
double const & Min,
double const & Max
)
{
return double(std::rand()) / double(RAND_MAX) * (Max - Min) + Min;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> linearRand
(
detail::tvec2<T> const & Min,
detail::tvec2<T> const & Max
)
{
return detail::tvec2<T>(
linearRand(Min.x, Max.x),
linearRand(Min.y, Max.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> linearRand
(
detail::tvec3<T> const & Min,
detail::tvec3<T> const & Max
)
{
return detail::tvec3<T>(
linearRand(Min.x, Max.x),
linearRand(Min.y, Max.y),
linearRand(Min.z, Max.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> linearRand
(
detail::tvec4<T> const & Min,
detail::tvec4<T> const & Max
)
{
return detail::tvec4<T>(
linearRand(Min.x, Max.x),
linearRand(Min.y, Max.y),
linearRand(Min.z, Max.z),
linearRand(Min.w, Max.w));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType gaussRand
(
genType const & Mean,
genType const & Deviation
)
{
genType w, x1, x2;
do
{
x1 = linearRand(genType(-1), genType(1));
x2 = linearRand(genType(-1), genType(1));
w = x1 * x1 + x2 * x2;
} while(w > genType(1));
return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> gaussRand
(
detail::tvec2<T> const & Mean,
detail::tvec2<T> const & Deviation
)
{
return detail::tvec2<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> gaussRand
(
detail::tvec3<T> const & Mean,
detail::tvec3<T> const & Deviation
)
{
return detail::tvec3<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y),
gaussRand(Mean.z, Deviation.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> gaussRand
(
detail::tvec4<T> const & Mean,
detail::tvec4<T> const & Deviation
)
{
return detail::tvec4<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y),
gaussRand(Mean.z, Deviation.z),
gaussRand(Mean.w, Deviation.w));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
(
T const & Radius
)
{
detail::tvec2<T> Result(T(0));
T LenRadius(T(0));
do
{
Result = linearRand(detail::tvec2<T>(-Radius), detail::tvec2<T>(Radius));
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
(
T const & Radius
)
{
detail::tvec3<T> Result(T(0));
T LenRadius(T(0));
do
{
Result = linearRand(detail::tvec3<T>(-Radius), detail::tvec3<T>(Radius));
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> circularRand
(
T const & Radius
)
{
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
return detail::tvec2<T>(cos(a), sin(a)) * Radius;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
(
T const & Radius
)
{
T z = linearRand(T(-1), T(1));
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
T r = sqrt(T(1) - z * z);
T x = r * cos(a);
T y = r * sin(a);
return detail::tvec3<T>(x, y, z) * Radius;
}
}//namespace glm

177
glm/gtx/constants.hpp Normal file
View file

@ -0,0 +1,177 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 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.
///
/// 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 constants
/// @file glm/gtx/constants.hpp
/// @date 2011-09-30 / 2011-09-30
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
///
/// @defgroup gtx_constants GLM_GTX_constants: Provide build-in constants
/// @ingroup gtx
///
/// @brief Allow to perform bit operations on integer values
///
/// <glm/gtx/constants.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#ifndef GLM_GTX_constants
#define GLM_GTX_constants GLM_VERSION
// Dependency:
#include "../glm.hpp"
#include "../gtc/half_float.hpp"
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
# pragma message("GLM: GLM_GTX_constants extension included")
#endif
namespace glm
{
/// @addtogroup gtx_constants
/// @{
template <typename T>
T pi();
template <typename T>
GLM_FUNC_QUALIFIER T pi()
{
return T(3.14159265358979323846264338327950288);
}
template <typename T>
GLM_FUNC_QUALIFIER T root_pi()
{
return T(1.772453850905516027);
}
template <typename T>
GLM_FUNC_QUALIFIER T half_pi()
{
return T(1.57079632679489661923132169163975144);
}
template <typename T>
GLM_FUNC_QUALIFIER T quarter_pi()
{
return T(0.785398163397448309615660845819875721);
}
template <typename T>
GLM_FUNC_QUALIFIER T one_over_pi()
{
return T(0.318309886183790671537767526745028724);
}
template <typename T>
GLM_FUNC_QUALIFIER T two_over_pi()
{
return T(0.636619772367581343075535053490057448);
}
template <typename T>
GLM_FUNC_QUALIFIER T two_over_root_pi()
{
return T(1.12837916709551257389615890312154517);
}
template <typename T>
GLM_FUNC_QUALIFIER T one_over_root_two()
{
return T(0.707106781186547524400844362104849039);
}
template <typename T>
GLM_FUNC_QUALIFIER T root_half_pi()
{
return T(1.253314137315500251);
}
template <typename T>
GLM_FUNC_QUALIFIER T root_two_pi()
{
return T(2.506628274631000502);
}
template <typename T>
GLM_FUNC_QUALIFIER T root_ln_four()
{
return T(1.17741002251547469);
}
template <typename T>
GLM_FUNC_QUALIFIER T e()
{
return T(2.71828182845904523536);
}
template <typename T>
GLM_FUNC_QUALIFIER T euler()
{
return T(0.577215664901532860606);
}
template <typename T>
GLM_FUNC_QUALIFIER T root_two()
{
return T(1.41421356237309504880168872420969808);
}
template <typename T>
GLM_FUNC_QUALIFIER T ln_two()
{
return T(0.693147180559945309417232121458176568);
}
template <typename T>
GLM_FUNC_QUALIFIER T ln_ten(2.30258509299404568401799145468436421)
{
return T();
}
template <typename T>
GLM_FUNC_QUALIFIER T ln_ln_two()
{
return T(-0.3665129205816643);
}
template <typename T>
GLM_FUNC_QUALIFIER T third()
{
return T(0.333333333333333333);
}
template <typename T>
GLM_FUNC_QUALIFIER T twothirds()
{
return T(0.666666666666666666);
}
/// @}
} //namespace glm
#include "constants.inl"
#endif//GLM_GTX_constants

792
glm/gtx/constants.inl Normal file
View file

@ -0,0 +1,792 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 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.
///
/// 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 gtc_half_float
/// @file glm/gtc/half_float.inl
/// @date 2009-04-29 / 2011-06-05
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "../core/_detail.hpp"
namespace glm{
template <typename genIType>
GLM_FUNC_QUALIFIER genIType mask
(
genIType const & count
)
{
return ((genIType(1) << (count)) - genIType(1));
}
template <typename valIType>
GLM_FUNC_QUALIFIER detail::tvec2<valIType> mask
(
detail::tvec2<valIType> const & count
)
{
return detail::tvec2<valIType>(
mask(count[0]),
mask(count[1]));
}
template <typename valIType>
GLM_FUNC_QUALIFIER detail::tvec3<valIType> mask
(
detail::tvec3<valIType> const & count
)
{
return detail::tvec3<valIType>(
mask(count[0]),
mask(count[1]),
mask(count[2]));
}
template <typename valIType>
GLM_FUNC_QUALIFIER detail::tvec4<valIType> mask
(
detail::tvec4<valIType> const & count
)
{
return detail::tvec4<valIType>(
mask(count[0]),
mask(count[1]),
mask(count[2]),
mask(count[3]));
}
// extractField
template <typename genIType>
GLM_FUNC_QUALIFIER genIType extractField
(
half const & value,
genIType const & first,
genIType const & count
)
{
assert(first + count < sizeof(half));
return (value._data() << first) >> ((sizeof(half) << 3) - count);
}
template <typename genIType>
GLM_FUNC_QUALIFIER genIType extractField
(
float const & value,
genIType const & first,
genIType const & count
)
{
assert(first + count < sizeof(float));
return (detail::uif32(value).i << first) >> ((sizeof(float) << 3) - count);
}
template <typename genIType>
GLM_FUNC_QUALIFIER genIType extractField
(
double const & value,
genIType const & first,
genIType const & count
)
{
assert(first + count < sizeof(double));
return (detail::uif64(value).i << first) >> ((sizeof(double) << genIType(3)) - count);
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER genIUType extractField
(
genIUType const & Value,
sizeType const & First,
sizeType const & Count
)
{
sizeType GenSize = sizeof(genIUType) << 3;
assert(First + Count <= GenSize);
genIUType ShiftLeft = Count ? Value << (GenSize - (Count + First)) : 0;
genIUType ShiftBack = ShiftLeft >> genIUType(GenSize - Count);
return ShiftBack;
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec2<genIUType> extractField
(
detail::tvec2<genIUType> const & value,
sizeType const & first,
sizeType const & count
)
{
return detail::tvec2<genIUType>(
extractField(value[0], first, count),
extractField(value[1], first, count));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec3<genIUType> extractField
(
detail::tvec3<genIUType> const & value,
sizeType const & first,
sizeType const & count
)
{
return detail::tvec3<genIUType>(
extractField(value[0], first, count),
extractField(value[1], first, count),
extractField(value[2], first, count));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec4<genIUType> extractField
(
detail::tvec4<genIUType> const & value,
sizeType const & first,
sizeType const & count
)
{
return detail::tvec4<genIUType>(
extractField(value[0], first, count),
extractField(value[1], first, count),
extractField(value[2], first, count),
extractField(value[3], first, count));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec2<genIUType> extractField
(
detail::tvec2<genIUType> const & value,
detail::tvec2<sizeType> const & first,
detail::tvec2<sizeType> const & count
)
{
return detail::tvec2<genIUType>(
extractField(value[0], first[0], count[0]),
extractField(value[1], first[1], count[1]));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec3<genIUType> extractField
(
detail::tvec3<genIUType> const & value,
detail::tvec3<sizeType> const & first,
detail::tvec3<sizeType> const & count
)
{
return detail::tvec3<genIUType>(
extractField(value[0], first[0], count[0]),
extractField(value[1], first[1], count[1]),
extractField(value[2], first[2], count[2]));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec4<genIUType> extractField
(
detail::tvec4<genIUType> const & value,
detail::tvec4<sizeType> const & first,
detail::tvec4<sizeType> const & count
)
{
return detail::tvec4<genIUType>(
extractField(value[0], first[0], count[0]),
extractField(value[1], first[1], count[1]),
extractField(value[2], first[2], count[2]),
extractField(value[3], first[3], count[3]));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec2<genIUType> extractField
(
genIUType const & value,
detail::tvec2<sizeType> const & first,
detail::tvec2<sizeType> const & count
)
{
return detail::tvec2<genIUType>(
extractField(value, first[0], count[0]),
extractField(value, first[1], count[1]));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec3<genIUType> extractField
(
genIUType const & value,
detail::tvec3<sizeType> const & first,
detail::tvec3<sizeType> const & count
)
{
return detail::tvec3<genIUType>(
extractField(value, first[0], count[0]),
extractField(value, first[1], count[1]),
extractField(value, first[2], count[2]));
}
template <typename genIUType, typename sizeType>
GLM_FUNC_QUALIFIER detail::tvec4<genIUType> extractField
(
genIUType const & value,
detail::tvec4<sizeType> const & first,
detail::tvec4<sizeType> const & count
)
{
return detail::tvec4<genIUType>(
extractField(value, first[0], count[0]),
extractField(value, first[1], count[1]),
extractField(value, first[2], count[2]),
extractField(value, first[3], count[3]));
}
// lowestBit
template <typename genType>
GLM_FUNC_QUALIFIER int lowestBit
(
genType const & Value
)
{
assert(Value != genType(0)); // not valid call
genType Bit;
for(Bit = genType(0); !(Value & (1 << Bit)); ++Bit){}
return Bit;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<int> lowestBit
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<int>(
lowestBit(value[0]),
lowestBit(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<int> lowestBit
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<int>(
lowestBit(value[0]),
lowestBit(value[1]),
lowestBit(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<int> lowestBit
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<int>(
lowestBit(value[0]),
lowestBit(value[1]),
lowestBit(value[2]),
lowestBit(value[3]));
}
// highestBit
template <typename genType>
GLM_FUNC_QUALIFIER int highestBit
(
genType const & value
)
{
assert(value != genType(0)); // not valid call
genType bit = genType(-1);
for(genType tmp = value; tmp; tmp >>= 1, ++bit){}
return bit;
}
//template <>
//GLM_FUNC_QUALIFIER int highestBit<int>
//(
// int value
//)
//{
// int bit = -1;
// for(int tmp = value; tmp; tmp >>= 1, ++bit);
// return bit;
//}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<int> highestBit
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<int>(
highestBit(value[0]),
highestBit(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<int> highestBit
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<int>(
highestBit(value[0]),
highestBit(value[1]),
highestBit(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<int> highestBit
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<int>(
highestBit(value[0]),
highestBit(value[1]),
highestBit(value[2]),
highestBit(value[3]));
}
// highestBitValue
template <typename genType>
GLM_FUNC_QUALIFIER genType highestBitValue
(
genType const & value
)
{
genType tmp = value;
genType result = genType(0);
while(tmp)
{
result = (tmp & (~tmp + 1)); // grab lowest bit
tmp &= ~result; // clear lowest bit
}
return result;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<int> highestBitValue
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<int>(
highestBitValue(value[0]),
highestBitValue(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<int> highestBitValue
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<int>(
highestBitValue(value[0]),
highestBitValue(value[1]),
highestBitValue(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<int> highestBitValue
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<int>(
highestBitValue(value[0]),
highestBitValue(value[1]),
highestBitValue(value[2]),
highestBitValue(value[3]));
}
// isPowerOfTwo
template <typename genType>
GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType const & Value)
{
//detail::If<std::numeric_limits<genType>::is_signed>::apply(abs, Value);
//return !(Value & (Value - 1));
// For old complier?
genType Result = Value;
if(std::numeric_limits<genType>::is_signed)
Result = abs(Result);
return !(Result & (Result - 1));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<bool> isPowerOfTwo
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<bool>(
isPowerOfTwo(value[0]),
isPowerOfTwo(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> isPowerOfTwo
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<bool>(
isPowerOfTwo(value[0]),
isPowerOfTwo(value[1]),
isPowerOfTwo(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> isPowerOfTwo
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<bool>(
isPowerOfTwo(value[0]),
isPowerOfTwo(value[1]),
isPowerOfTwo(value[2]),
isPowerOfTwo(value[3]));
}
// powerOfTwoAbove
template <typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType const & value)
{
return isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> powerOfTwoAbove
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<valType>(
powerOfTwoAbove(value[0]),
powerOfTwoAbove(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> powerOfTwoAbove
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<valType>(
powerOfTwoAbove(value[0]),
powerOfTwoAbove(value[1]),
powerOfTwoAbove(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> powerOfTwoAbove
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<valType>(
powerOfTwoAbove(value[0]),
powerOfTwoAbove(value[1]),
powerOfTwoAbove(value[2]),
powerOfTwoAbove(value[3]));
}
// powerOfTwoBelow
template <typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoBelow
(
genType const & value
)
{
return isPowerOfTwo(value) ? value : highestBitValue(value);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> powerOfTwoBelow
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<valType>(
powerOfTwoBelow(value[0]),
powerOfTwoBelow(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> powerOfTwoBelow
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<valType>(
powerOfTwoBelow(value[0]),
powerOfTwoBelow(value[1]),
powerOfTwoBelow(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> powerOfTwoBelow
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<valType>(
powerOfTwoBelow(value[0]),
powerOfTwoBelow(value[1]),
powerOfTwoBelow(value[2]),
powerOfTwoBelow(value[3]));
}
// powerOfTwoNearest
template <typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoNearest
(
genType const & value
)
{
if(isPowerOfTwo(value))
return value;
genType prev = highestBitValue(value);
genType next = prev << 1;
return (next - value) < (value - prev) ? next : prev;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> powerOfTwoNearest
(
detail::tvec2<valType> const & value
)
{
return detail::tvec2<valType>(
powerOfTwoNearest(value[0]),
powerOfTwoNearest(value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> powerOfTwoNearest
(
detail::tvec3<valType> const & value
)
{
return detail::tvec3<valType>(
powerOfTwoNearest(value[0]),
powerOfTwoNearest(value[1]),
powerOfTwoNearest(value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> powerOfTwoNearest
(
detail::tvec4<valType> const & value
)
{
return detail::tvec4<valType>(
powerOfTwoNearest(value[0]),
powerOfTwoNearest(value[1]),
powerOfTwoNearest(value[2]),
powerOfTwoNearest(value[3]));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType bitRevert(genType const & In)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_integer, "'bitRevert' only accept integer values");
genType Out = 0;
std::size_t BitSize = sizeof(genType) * 8;
for(std::size_t i = 0; i < BitSize; ++i)
if(In & (genType(1) << i))
Out |= genType(1) << (BitSize - 1 - i);
return Out;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> bitRevert
(
detail::tvec2<valType> const & Value
)
{
return detail::tvec2<valType>(
bitRevert(Value[0]),
bitRevert(Value[1]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> bitRevert
(
detail::tvec3<valType> const & Value
)
{
return detail::tvec3<valType>(
bitRevert(Value[0]),
bitRevert(Value[1]),
bitRevert(Value[2]));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> bitRevert
(
detail::tvec4<valType> const & Value
)
{
return detail::tvec4<valType>(
bitRevert(Value[0]),
bitRevert(Value[1]),
bitRevert(Value[2]),
bitRevert(Value[3]));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType bitRotateRight(genType const & In, std::size_t Shift)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_integer, "'bitRotateRight' only accept integer values");
std::size_t BitSize = sizeof(genType) * 8;
return (In << Shift) | (In >> (BitSize - Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> bitRotateRight
(
detail::tvec2<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec2<valType>(
bitRotateRight(Value[0], Shift),
bitRotateRight(Value[1], Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> bitRotateRight
(
detail::tvec3<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec3<valType>(
bitRotateRight(Value[0], Shift),
bitRotateRight(Value[1], Shift),
bitRotateRight(Value[2], Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> bitRotateRight
(
detail::tvec4<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec4<valType>(
bitRotateRight(Value[0], Shift),
bitRotateRight(Value[1], Shift),
bitRotateRight(Value[2], Shift),
bitRotateRight(Value[3], Shift));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType bitRotateLeft(genType const & In, std::size_t Shift)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_integer, "'bitRotateLeft' only accept integer values");
std::size_t BitSize = sizeof(genType) * 8;
return (In >> Shift) | (In << (BitSize - Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> bitRotateLeft
(
detail::tvec2<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec2<valType>(
bitRotateLeft(Value[0], Shift),
bitRotateLeft(Value[1], Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> bitRotateLeft
(
detail::tvec3<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec3<valType>(
bitRotateLeft(Value[0], Shift),
bitRotateLeft(Value[1], Shift),
bitRotateLeft(Value[2], Shift));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> bitRotateLeft
(
detail::tvec4<valType> const & Value,
std::size_t Shift
)
{
return detail::tvec4<valType>(
bitRotateLeft(Value[0], Shift),
bitRotateLeft(Value[1], Shift),
bitRotateLeft(Value[2], Shift),
bitRotateLeft(Value[3], Shift));
}
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne
(
genIUType const & Value,
int const & FromBit,
int const & ToBit
)
{
assert(FromBit <= ToBit);
assert(ToBit <= sizeof(genIUType) * std::size_t(8));
genIUType Result = Value;
for(std::size_t i = 0; i <= ToBit; ++i)
Result |= (1 << i);
return Result;
}
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero
(
genIUType const & Value,
int const & FromBit,
int const & ToBit
)
{
assert(FromBit <= ToBit);
assert(ToBit <= sizeof(genIUType) * std::size_t(8));
genIUType Result = Value;
for(std::size_t i = 0; i <= ToBit; ++i)
Result &= ~(1 << i);
return Result;
}
}//namespace glm

View file

@ -44,6 +44,7 @@
// Dependency:
#include "../glm.hpp"
#include "../gtc/noise.hpp"
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
# pragma message("GLM: GLM_GTX_noise extension included")
@ -54,25 +55,6 @@ namespace glm
/// @addtogroup gtx_noise
/// @{
//! Classic perlin noise.
//! From GLM_GTX_noise extension.
template <typename T, template<typename> class vecType>
T perlin(
vecType<T> const & p);
//! Periodic perlin noise.
//! From GLM_GTX_noise extension.
template <typename T, template<typename> class vecType>
T perlin(
vecType<T> const & p,
vecType<T> const & rep);
//! Simplex noise.
//! From GLM_GTX_noise extension.
template <typename T, template<typename> class vecType>
T simplex(
vecType<T> const & p);
/// @}
}//namespace glm

View file

@ -17,836 +17,4 @@
namespace glm{
template <typename T>
GLM_FUNC_QUALIFIER T mod289(T const & x)
{
return x - floor(x * T(1.0 / 289.0)) * T(289.0);
}
template <typename T>
GLM_FUNC_QUALIFIER T permute(T const & x)
{
return mod289(((x * T(34)) + T(1)) * x);
}
template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x)
{
return mod289(((x * T(34)) + T(1)) * x);
}
template <typename T>
GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r)
{
return T(1.79284291400159) - T(0.85373472095314) * r;
}
template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r)
{
return T(1.79284291400159) - T(0.85373472095314) * r;
}
template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t)
{
return t * t * t * (t * (t * T(6) - T(15)) + T(10));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip)
{
detail::tvec3<T> pXYZ = floor(fract(detail::tvec3<T>(j) * detail::tvec3<T>(ip)) * T(7)) * ip[2] - T(1);
T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T>(1));
detail::tvec4<T> s = detail::tvec4<T>(lessThan(detail::tvec4<T>(pXYZ, pW), detail::tvec4<T>(0.0)));
pXYZ = pXYZ + (detail::tvec3<T>(s) * T(2) - T(1)) * s.w;
return detail::tvec4<T>(pXYZ, pW);
}
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
{
detail::tvec4<T> Pi = glm::floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = glm::fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix(Pi.x, Pi.z, Pi.x, Pi.z);
detail::tvec4<T> iy(Pi.y, Pi.y, Pi.w, Pi.w);
detail::tvec4<T> fx(Pf.x, Pf.z, Pf.x, Pf.z);
detail::tvec4<T> fy(Pf.y, Pf.y, Pf.w, Pf.w);
detail::tvec4<T> i = glm::permute(glm::permute(ix) + iy);
detail::tvec4<T> gx = T(2) * glm::fract(i / T(41)) - T(1);
detail::tvec4<T> gy = glm::abs(gx) - T(0.5);
detail::tvec4<T> tx = glm::floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00(gx.x, gy.x);
detail::tvec2<T> g10(gx.y, gy.y);
detail::tvec2<T> g01(gx.z, gy.z);
detail::tvec2<T> g11(gx.w, gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(detail::tvec2<T>(Pf.x, Pf.y));
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy;
}
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod289(Pi0);
Pi1 = mod289(Pi1);
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(detail::tvec2<T>(Pi0.y), detail::tvec2<T>(Pi1.y));
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 * T(1.0 / 7.0);
detail::tvec4<T> gy0 = fract(floor(gx0) * T(1.0 / 7.0)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0.0));
gx0 -= sz0 * (step(T(0), gx0) - T(0.5));
gy0 -= sz0 * (step(T(0), gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 * T(1.0 / 7.0);
detail::tvec4<T> gy1 = fract(floor(gx1) * T(1.0 / 7.0)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(T(0), gx1) - T(0.5));
gy1 -= sz1 * (step(T(0), gy1) - T(0.5));
detail::tvec3<T> g000(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
/*
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 / T(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0.0));
gx0 -= sz0 * (step(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(T(0), gx1) - T(0.5));
gy1 -= sz1 * (step(T(0), gy1) - T(0.5));
detail::tvec3<T> g000(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(
detail::tvec2<T>(n_z.x, n_z.y),
detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
*/
// Classic Perlin noise
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P)
{
detail::tvec4<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec4<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec4<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = detail::tvec4<T>(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, detail::tvec4<T>(0.0));
gx00 -= sw00 * (step(T(0), gx00) - T(0.5));
gy00 -= sw00 * (step(T(0), gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = detail::tvec4<T>(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, detail::tvec4<T>(0.0));
gx01 -= sw01 * (step(T(0), gx01) - T(0.5));
gy01 -= sw01 * (step(T(0), gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0));
gx10 -= sw10 * (step(T(0), gx10) - T(0.5));
gy10 -= sw10 * (step(T(0), gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, detail::tvec4<T>(0.0));
gx11 -= sw11 * (step(T(0), gx11) - T(0.5));
gy11 -= sw11 * (step(T(0), gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf0.w));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf0.w));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf0.w));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.x, Pf1.y, Pf1.z, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.x, Pf0.y, Pf0.z, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf1.w));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf1.w));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf1.w));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw;
}
// Classic Perlin noise, periodic variant
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
{
detail::tvec4<T> Pi = floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, detail::tvec4<T>(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix(Pi.x, Pi.z, Pi.x, Pi.z);
detail::tvec4<T> iy(Pi.y, Pi.y, Pi.w, Pi.w);
detail::tvec4<T> fx(Pf.x, Pf.z, Pf.x, Pf.z);
detail::tvec4<T> fy(Pf.y, Pf.y, Pf.w, Pf.w);
detail::tvec4<T> i = permute(permute(ix) + iy);
detail::tvec4<T> gx = T(2) * fract(i / T(41)) - T(1);
detail::tvec4<T> gy = abs(gx) - T(0.5);
detail::tvec4<T> tx = floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00(gx.x, gy.x);
detail::tvec2<T> g10(gx.y, gy.y);
detail::tvec2<T> g01(gx.z, gy.z);
detail::tvec2<T> g11(gx.w, gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(detail::tvec2<T>(Pf.x, Pf.y));
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy;
}
// Classic Perlin noise, periodic variant
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep)
{
detail::tvec3<T> Pi0 = mod(floor(P), rep); // Integer part, modulo period
detail::tvec3<T> Pi1 = mod(Pi0 + detail::tvec3<T>(1.0), rep); // Integer part + 1, mod period
Pi0 = mod(Pi0, T(289));
Pi1 = mod(Pi1, T(289));
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - detail::tvec3<T>(1.0); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 / T(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0));
gx0 -= sz0 * (step(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(0.0, gx1) - T(0.5));
gy1 -= sz1 * (step(0.0, gy1) - T(0.5));
detail::tvec3<T> g000 = detail::tvec3<T>(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100 = detail::tvec3<T>(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010 = detail::tvec3<T>(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110 = detail::tvec3<T>(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001 = detail::tvec3<T>(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101 = detail::tvec3<T>(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011 = detail::tvec3<T>(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111 = detail::tvec3<T>(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
detail::tvec4<T> norm1 = taylorInvSqrt(detail::tvec4<T>(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
T n000 = dot(g000, Pf0);
T n100 = dot(g100, detail::tvec3<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz;
}
// Classic Perlin noise, periodic version
template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep)
{
detail::tvec4<T> Pi0 = mod(floor(P), rep); // Integer part modulo rep
detail::tvec4<T> Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec4<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = detail::tvec4<T>(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, detail::tvec4<T>(0));
gx00 -= sw00 * (step(0.0, gx00) - T(0.5));
gy00 -= sw00 * (step(0.0, gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = detail::tvec4<T>(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, detail::tvec4<T>(0.0));
gx01 -= sw01 * (step(0.0, gx01) - T(0.5));
gy01 -= sw01 * (step(0.0, gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0.0));
gx10 -= sw10 * (step(0.0, gx10) - T(0.5));
gy10 -= sw10 * (step(0.0, gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, detail::tvec4<T>(0.0));
gx11 -= sw11 * (step(0.0, gx11) - T(0.5));
gy11 -= sw11 * (step(0.0, gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf0.w));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf0.w));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf0.w));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.x, Pf1.y, Pf1.z, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.x, Pf0.y, Pf0.z, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.y, Pf0.z, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.x, Pf1.y, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.x, Pf0.y, Pf1.z, Pf1.w));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf1.w));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.y, Pf1.z, Pf1.w));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw;
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v)
{
detail::tvec4<T> const C = detail::tvec4<T>(
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0)
T(-0.577350269189626), // -1.0 + 2.0 * C.x
T( 0.024390243902439)); // 1.0 / 41.0
// First corner
detail::tvec2<T> i = floor(v + dot(v, detail::tvec2<T>(C[1])));
detail::tvec2<T> x0 = v - i + dot(i, detail::tvec2<T>(C[0]));
// Other corners
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
detail::tvec2<T> i1 = (x0.x > x0.y) ? detail::tvec2<T>(1, 0) : detail::tvec2<T>(0, 1);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
detail::tvec4<T> x12 = detail::tvec4<T>(x0.x, x0.y, x0.x, x0.y) + detail::tvec4<T>(C.x, C.x, C.z, C.z);
x12 = detail::tvec4<T>(detail::tvec2<T>(x12) - i1, x12.z, x12.w);
// Permutations
i = mod(i, T(289)); // Avoid truncation effects in permutation
detail::tvec3<T> p = permute(
permute(i.y + detail::tvec3<T>(T(0), i1.y, T(1)))
+ i.x + detail::tvec3<T>(T(0), i1.x, T(1)));
detail::tvec3<T> m = max(T(0.5) - detail::tvec3<T>(
dot(x0, x0),
dot(detail::tvec2<T>(x12.x, x12.y), detail::tvec2<T>(x12.x, x12.y)),
dot(detail::tvec2<T>(x12.z, x12.w), detail::tvec2<T>(x12.z, x12.w))), T(0));
m = m * m ;
m = m * m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
detail::tvec3<T> x = T(2) * fract(p * C.w) - T(1);
detail::tvec3<T> h = abs(x) - T(0.5);
detail::tvec3<T> ox = floor(x + T(0.5));
detail::tvec3<T> a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
m *= T(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
// Compute final noise value at P
detail::tvec3<T> g;
g.x = a0.x * x0.x + h.x * x0.y;
//g.yz = a0.yz * x12.xz + h.yz * x12.yw;
g.y = a0.y * x12.x + h.y * x12.y;
g.z = a0.z * x12.z + h.z * x12.w;
return T(130) * dot(m, g);
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
{
detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0);
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
// First corner
detail::tvec3<T> i = floor(v + dot(v, detail::tvec3<T>(C.y)));
detail::tvec3<T> x0 = v - i + dot(i, detail::tvec3<T>(C.x));
// Other corners
detail::tvec3<T> g = step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0);
detail::tvec3<T> l = T(1) - g;
detail::tvec3<T> i1 = min(g, detail::tvec3<T>(l.z, l.x, l.y));
detail::tvec3<T> i2 = max(g, detail::tvec3<T>(l.z, l.x, l.y));
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
detail::tvec3<T> x1 = x0 - i1 + C.x;
detail::tvec3<T> x2 = x0 - i2 + C.y; // 2.0*C.x = 1/3 = C.y
detail::tvec3<T> x3 = x0 - D.y; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
detail::tvec4<T> p = permute(permute(permute(
i.z + detail::tvec4<T>(T(0), i1.z, i2.z, T(1))) +
i.y + detail::tvec4<T>(T(0), i1.y, i2.y, T(1))) +
i.x + detail::tvec4<T>(T(0), i1.x, i2.x, T(1)));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
T n_ = T(0.142857142857); // 1.0/7.0
detail::tvec3<T> ns = n_ * detail::tvec3<T>(D.w, D.y, D.z) - detail::tvec3<T>(D.x, D.z, D.x);
detail::tvec4<T> j = p - T(49) * floor(p * ns.z * ns.z); // mod(p,7*7)
detail::tvec4<T> x_ = floor(j * ns.z);
detail::tvec4<T> y_ = floor(j - T(7) * x_); // mod(j,N)
detail::tvec4<T> x = x_ * ns.x + ns.y;
detail::tvec4<T> y = y_ * ns.x + ns.y;
detail::tvec4<T> h = T(1) - abs(x) - abs(y);
detail::tvec4<T> b0(x.x, x.y, y.x, y.y);
detail::tvec4<T> b1(x.z, x.w, y.z, y.w);
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
detail::tvec4<T> s0 = floor(b0) * T(2) + T(1);
detail::tvec4<T> s1 = floor(b1) * T(2) + T(1);
detail::tvec4<T> sh = -step(h, detail::tvec4<T>(0.0));
detail::tvec4<T> a0 = detail::tvec4<T>(b0.x, b0.z, b0.y, b0.w) + detail::tvec4<T>(s0.x, s0.z, s0.y, s0.w) * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
detail::tvec4<T> a1 = detail::tvec4<T>(b1.x, b1.z, b1.y, b1.w) + detail::tvec4<T>(s1.x, s1.z, s1.y, s1.w) * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
detail::tvec3<T> p0(a0.x, a0.y, h.x);
detail::tvec3<T> p1(a0.z, a0.w, h.y);
detail::tvec3<T> p2(a1.x, a1.y, h.z);
detail::tvec3<T> p3(a1.z, a1.w, h.w);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0));
m = m * m;
return T(42) * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v)
{
detail::tvec4<T> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4 = T(0.309016994374947451);
// First corner
detail::tvec4<T> i = floor(v + dot(v, vec4(F4)));
detail::tvec4<T> x0 = v - i + dot(i, vec4(C.x));
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
detail::tvec4<T> i0;
detail::tvec3<T> isX = step(detail::tvec3<T>(x0.y, x0.z, x0.w), detail::tvec3<T>(x0.x));
detail::tvec3<T> isYZ = step(detail::tvec3<T>(x0.z, x0.w, x0.w), detail::tvec3<T>(x0.y, x0.y, x0.z));
// i0.x = dot(isX, vec3(1.0));
//i0.x = isX.x + isX.y + isX.z;
//i0.yzw = T(1) - isX;
i0 = detail::tvec4<T>(isX.x + isX.y + isX.z, T(1) - isX);
// i0.y += dot(isYZ.xy, vec2(1.0));
i0.y += isYZ.x + isYZ.y;
//i0.zw += 1.0 - detail::tvec2<T>(isYZ.x, isYZ.y);
i0.z += T(1) - isYZ.x;
i0.w += T(1) - isYZ.y;
i0.z += isYZ.z;
i0.w += T(1) - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
detail::tvec4<T> i3 = clamp(i0, 0.0, 1.0);
detail::tvec4<T> i2 = clamp(i0 - 1.0, 0.0, 1.0);
detail::tvec4<T> i1 = clamp(i0 - 2.0, 0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 0.0 * C.xxxx
// x2 = x0 - i2 + 0.0 * C.xxxx
// x3 = x0 - i3 + 0.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
detail::tvec4<T> x1 = x0 - i1 + C.x;
detail::tvec4<T> x2 = x0 - i2 + C.y;
detail::tvec4<T> x3 = x0 - i3 + C.z;
detail::tvec4<T> x4 = x0 + C.w;
// Permutations
i = mod(i, T(289));
T j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);
detail::tvec4<T> j1 = permute(permute(permute(permute(
i.w + detail::tvec4<T>(i1.w, i2.w, i3.w, T(1)))
+ i.z + detail::tvec4<T>(i1.z, i2.z, i3.z, T(1)))
+ i.y + detail::tvec4<T>(i1.y, i2.y, i3.y, T(1)))
+ i.x + detail::tvec4<T>(i1.x, i2.x, i3.x, T(1)));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
detail::tvec4<T> ip = detail::tvec4<T>(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0));
detail::tvec4<T> p0 = grad4(j0, ip);
detail::tvec4<T> p1 = grad4(j1.x, ip);
detail::tvec4<T> p2 = grad4(j1.y, ip);
detail::tvec4<T> p3 = grad4(j1.z, ip);
detail::tvec4<T> p4 = grad4(j1.w, ip);
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4, p4));
// Mix contributions from the five corners
detail::tvec3<T> m0 = max(T(0.6) - detail::tvec3<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2)), T(0));
detail::tvec2<T> m1 = max(T(0.6) - detail::tvec2<T>(dot(x3, x3), dot(x4, x4) ), T(0));
m0 = m0 * m0;
m1 = m1 * m1;
return T(49) *
(dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) +
dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4))));
}
}//namespace glm

View file

@ -21,6 +21,9 @@
* ====================================================
*/
#pragma warning(push)
#pragma warning(disable : 4127)
typedef union
{
float value;
@ -76,8 +79,8 @@ namespace detail
volatile float t;
glm::detail::int32 hx, hy, ix, iy;
GLM_GET_FLOAT_WORD(hx,x);
GLM_GET_FLOAT_WORD(hy,y);
GLM_GET_FLOAT_WORD(hx, x);
GLM_GET_FLOAT_WORD(hy, y);
ix = hx&0x7fffffff; // |x|
iy = hy&0x7fffffff; // |y|
@ -168,6 +171,8 @@ namespace detail
}//namespace detail
}//namespace glm
#pragma warning(pop)
#if(GLM_COMPILER & GLM_COMPILER_VC)
# define GLM_NEXT_AFTER_FLT(x, toward) glm::detail::nextafterf((x), (toward))
# define GLM_NEXT_AFTER_DBL(x, toward) _nextafter((x), (toward))

View file

@ -40,10 +40,26 @@ http://glm.g-truc.net/glm-0.9.3.pdf
GLM 0.9.3.0: 2011-XX-XX
--------------------------------------------------------------------------------
- Improved doxygen documentation
- Promoted GLM_GTC_noise extension: simplex, perlin, periodic noise functions
- Promoted GLM_GTC_random extension: linear, gaussian and various random number
generation distribution.
- Added GLM_GTX_constants: provides usefull constants
- Added extension versioning
- Removed many unused namespaces
- Fixed half based type contructors
================================================================================
GLM 0.9.2.7: 2011-1X-XX
--------------------------------------------------------------------------------
- Added more swizzling constructors
================================================================================
GLM 0.9.2.6: 2011-10-01
--------------------------------------------------------------------------------
- Fixed half based type build on old GCC
- Fixed /W4 warnings on Visual C++
- Fixed some missing l-value swizzle operators
================================================================================
GLM 0.9.2.5: 2011-09-20
--------------------------------------------------------------------------------

View file

@ -71,6 +71,118 @@ int test_vec2_operators()
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
glm::vec2 C = A + B;
Error += C == glm::vec2(5, 7) ? 0 : 1;
glm::vec2 D = B - A;
Error += D == glm::vec2(3, 3) ? 0 : 1;
glm::vec2 E = A * B;
Error += E == glm::vec2(4, 10) ? 0 : 1;
glm::vec2 F = B / A;
Error += F == glm::vec2(4, 2.5) ? 0 : 1;
glm::vec2 G = A + 1.0f;
Error += G == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 H = B - 1.0f;
Error += H == glm::vec2(3, 4) ? 0 : 1;
glm::vec2 I = A * 2.0f;
Error += I == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 J = B / 2.0f;
Error += J == glm::vec2(2, 2.5) ? 0 : 1;
glm::vec2 K = 1.0f + A;
Error += K == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 L = 1.0f - B;
Error += L == glm::vec2(-3, -4) ? 0 : 1;
glm::vec2 M = 2.0f * A;
Error += M == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 N = 2.0f / B;
Error += N == glm::vec2(0.5, 2.0 / 5.0) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A += B;
Error += A == glm::vec2(5, 7) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec2(6, 8) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B -= A;
Error += B == glm::vec2(3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec2(2, 2) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A *= B;
Error += A == glm::vec2(4, 10) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec2(8, 20) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B /= A;
Error += B == glm::vec2(4, 2.5) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec2(2, 1.25) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = -A;
Error += B == glm::vec2(-1.0f, -2.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = --A;
Error += B == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A--;
Error += B == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = ++A;
Error += B == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A++;
Error += B == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
return Error;
}

View file

@ -1,255 +1,428 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-08-31
// Updated : 2011-09-19
// Licence : This source is under MIT License
// File : test/core/type_vec3.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/half_float.hpp>
static int test_vec3_operators()
{
glm::vec3 A(1.0f);
glm::vec3 B(1.0f);
bool R = A != B;
bool S = A == B;
return (S && !R) ? 0 : 1;
}
int test_vec3_size()
{
int Error = 0;
Error += sizeof(glm::vec3) == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += 12 == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += sizeof(glm::dvec3) == sizeof(glm::highp_vec3) ? 0 : 1;
Error += 24 == sizeof(glm::highp_vec3) ? 0 : 1;
Error += glm::vec3().length() == 3 ? 0 : 1;
Error += glm::dvec3().length() == 3 ? 0 : 1;
return Error;
}
int test_vec3_swizzle3_2()
{
int Error = 0;
glm::vec3 v(1, 2, 3);
glm::vec2 u;
// Can not assign a vec3 swizzle to a vec2
//u = v.xyz; //Illegal
//u = v.rgb; //Illegal
//u = v.stp; //Illegal
u = v.xx; Error += (u.x == 1.0f && u.y == 1.0f) ? 0 : 1;
u = v.xy; Error += (u.x == 1.0f && u.y == 2.0f) ? 0 : 1;
u = v.xz; Error += (u.x == 1.0f && u.y == 3.0f) ? 0 : 1;
u = v.yx; Error += (u.x == 2.0f && u.y == 1.0f) ? 0 : 1;
u = v.yy; Error += (u.x == 2.0f && u.y == 2.0f) ? 0 : 1;
u = v.yz; Error += (u.x == 2.0f && u.y == 3.0f) ? 0 : 1;
u = v.zx; Error += (u.x == 3.0f && u.y == 1.0f) ? 0 : 1;
u = v.zy; Error += (u.x == 3.0f && u.y == 2.0f) ? 0 : 1;
u = v.zz; Error += (u.x == 3.0f && u.y == 3.0f) ? 0 : 1;
u = v.rr; Error += (u.r == 1.0f && u.g == 1.0f) ? 0 : 1;
u = v.rg; Error += (u.r == 1.0f && u.g == 2.0f) ? 0 : 1;
u = v.rb; Error += (u.r == 1.0f && u.g == 3.0f) ? 0 : 1;
u = v.gr; Error += (u.r == 2.0f && u.g == 1.0f) ? 0 : 1;
u = v.gg; Error += (u.r == 2.0f && u.g == 2.0f) ? 0 : 1;
u = v.gb; Error += (u.r == 2.0f && u.g == 3.0f) ? 0 : 1;
u = v.br; Error += (u.r == 3.0f && u.g == 1.0f) ? 0 : 1;
u = v.bg; Error += (u.r == 3.0f && u.g == 2.0f) ? 0 : 1;
u = v.bb; Error += (u.r == 3.0f && u.g == 3.0f) ? 0 : 1;
u = v.ss; Error += (u.s == 1.0f && u.t == 1.0f) ? 0 : 1;
u = v.st; Error += (u.s == 1.0f && u.t == 2.0f) ? 0 : 1;
u = v.sp; Error += (u.s == 1.0f && u.t == 3.0f) ? 0 : 1;
u = v.ts; Error += (u.s == 2.0f && u.t == 1.0f) ? 0 : 1;
u = v.tt; Error += (u.s == 2.0f && u.t == 2.0f) ? 0 : 1;
u = v.tp; Error += (u.s == 2.0f && u.t == 3.0f) ? 0 : 1;
u = v.ps; Error += (u.s == 3.0f && u.t == 1.0f) ? 0 : 1;
u = v.pt; Error += (u.s == 3.0f && u.t == 2.0f) ? 0 : 1;
u = v.pp; Error += (u.s == 3.0f && u.t == 3.0f) ? 0 : 1;
// Mixed member aliases are not valid
//u = v.rx; //Illegal
//u = v.sy; //Illegal
u = glm::vec2(1, 2);
v = glm::vec3(1, 2, 3);
//v.xx = u; //Illegal
v.xy = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 3.0f) ? 0 : 1;
v.xz = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 2.0f) ? 0 : 1;
v.yx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
//v.yy = u; //Illegal
v.yz = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1;
v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1;
//v.zz = u; //Illegal
return Error;
}
int test_vec3_swizzle3_3()
{
int Error = 0;
glm::vec3 v(1, 2, 3);
glm::vec3 u;
u = v; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.xyz; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.zyx; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.zyx = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.rgb; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.bgr; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.bgr = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
return Error;
}
int test_vec3_swizzle_half()
{
int Error = 0;
glm::half a1(1);
glm::half b1(2);
glm::half c1(3);
glm::hvec3 v(a1, b1, c1);
glm::hvec3 u;
u = v;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.xyz;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.zyx;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.zyx = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u = v.rgb;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.bgr;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.bgr = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u = v.stp;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.pts;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.pts = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
return Error;
}
int test_vec3_swizzle_operators()
{
int Error = 0;
glm::vec3 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
// Swizzle, swizzle binary operators
q = u.xyz + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u.zyx + v.zyx).zyx; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v.xyz); Error += (q == (u - v)) ? 0 : 1;
q = (u.xyz * v.xyz); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v.xxx); Error += (q == glm::vec3(u.x * v.x)) ? 0 : 1;
q = (u.xyz / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// vec, swizzle binary operators
q = u + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u - v.xyz); Error += (q == (u - v)) ? 0 : 1;
q = (u * v.xyz); Error += (q == (u * v)) ? 0 : 1;
q = (u * v.xxx); Error += (q == v.x * u) ? 0 : 1;
q = (u / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// swizzle,vec binary operators
q = u.xyz + v; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v); Error += (q == (u - v)) ? 0 : 1;
q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1;
q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1;
// Compile errors
//q = (u.yz * v.xyz);
//q = (u * v.xy);
return Error;
}
int test_vec3_swizzle_functions()
{
int Error = 0;
//
// NOTE: template functions cannot pick up the implicit conversion from
// a swizzle to the unswizzled type, therefore the operator() must be
// used. E.g.:
//
// glm::dot(u.xy, v.xy); <--- Compile error
// glm::dot(u.xy(), v.xy()); <--- Compiles correctly
//
float r;
// vec2
glm::vec2 a(1, 2);
glm::vec2 b(10, 20);
r = glm::dot(a, b); Error += (int(r) == 50) ? 0 : 1;
r = glm::dot(a.xy(), b.xy()); Error += (int(r) == 50) ? 0 : 1;
r = glm::dot(a.xy(), b.yy()); Error += (int(r) == 60) ? 0 : 1;
// vec3
glm::vec3 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
r = glm::dot(u, v); Error += (int(r) == 140) ? 0 : 1;
r = glm::dot(u.xyz(), v.zyz()); Error += (int(r) == 160) ? 0 : 1;
r = glm::dot(u, v.zyx()); Error += (int(r) == 100) ? 0 : 1;
r = glm::dot(u.xyz(), v); Error += (int(r) == 140) ? 0 : 1;
r = glm::dot(u.xy(), v.xy()); Error += (int(r) == 50) ? 0 : 1;
// vec4
glm::vec4 s, t;
s = glm::vec4(1, 2, 3, 4);
t = glm::vec4(10, 20, 30, 40);
r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_vec3_operators();
Error += test_vec3_size();
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_vec3_swizzle_half();
Error += test_vec3_swizzle_operators();
Error += test_vec3_swizzle_functions();
return Error;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-08-31
// Updated : 2011-09-19
// Licence : This source is under MIT License
// File : test/core/type_vec3.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/half_float.hpp>
#include <vector>
int test_vec3_ctor()
{
int Error = 0;
{
glm::vec3 A(1);
glm::vec3 B(1, 1, 1);
Error += A == B ? 0 : 1;
}
{
std::vector<glm::vec3> Tests;
Tests.push_back(glm::vec3(glm::vec2(1, 2), 3));
Tests.push_back(glm::vec3(1, glm::vec2(2, 3)));
Tests.push_back(glm::vec3(1, 2, 3));
Tests.push_back(glm::vec3(glm::vec4(1, 2, 3, 4)));
for(std::size_t i = 0; i < Tests.size(); ++i)
Error += Tests[i] == glm::vec3(1, 2, 3) ? 0 : 1;
}
return Error;
}
int test_vec3_operators()
{
int Error = 0;
{
glm::vec3 A(1.0f);
glm::vec3 B(1.0f);
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
glm::vec3 C = A + B;
Error += C == glm::vec3(5, 7, 9) ? 0 : 1;
glm::vec3 D = B - A;
Error += D == glm::vec3(3, 3, 3) ? 0 : 1;
glm::vec3 E = A * B;
Error += E == glm::vec3(4, 10, 18) ? 0 : 1;
glm::vec3 F = B / A;
Error += F == glm::vec3(4, 2.5, 2) ? 0 : 1;
glm::vec3 G = A + 1.0f;
Error += G == glm::vec3(2, 3, 4) ? 0 : 1;
glm::vec3 H = B - 1.0f;
Error += H == glm::vec3(3, 4, 5) ? 0 : 1;
glm::vec3 I = A * 2.0f;
Error += I == glm::vec3(2, 4, 6) ? 0 : 1;
glm::vec3 J = B / 2.0f;
Error += J == glm::vec3(2, 2.5, 3) ? 0 : 1;
glm::vec3 K = 1.0f + A;
Error += K == glm::vec3(2, 3, 4) ? 0 : 1;
glm::vec3 L = 1.0f - B;
Error += L == glm::vec3(-3, -4, -5) ? 0 : 1;
glm::vec3 M = 2.0f * A;
Error += M == glm::vec3(2, 4, 6) ? 0 : 1;
glm::vec3 N = 2.0f / B;
Error += N == glm::vec3(0.5, 2.0 / 5.0, 2.0 / 6.0) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
A += B;
Error += A == glm::vec3(5, 7, 9) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec3(6, 8, 10) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
B -= A;
Error += B == glm::vec3(3, 3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec3(2, 2, 2) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
A *= B;
Error += A == glm::vec3(4, 10, 18) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec3(8, 20, 36) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
B /= A;
Error += B == glm::vec3(4, 2.5, 2) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec3(2, 1.25, 1) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = -A;
Error += B == glm::vec3(-1.0f, -2.0f, -3.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = --A;
Error += B == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = A--;
Error += B == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = ++A;
Error += B == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = A++;
Error += B == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
}
return Error;
}
int test_vec3_size()
{
int Error = 0;
Error += sizeof(glm::vec3) == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += 12 == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += sizeof(glm::dvec3) == sizeof(glm::highp_vec3) ? 0 : 1;
Error += 24 == sizeof(glm::highp_vec3) ? 0 : 1;
Error += glm::vec3().length() == 3 ? 0 : 1;
Error += glm::dvec3().length() == 3 ? 0 : 1;
return Error;
}
int test_vec3_swizzle3_2()
{
int Error = 0;
glm::vec3 v(1, 2, 3);
glm::vec2 u;
// Can not assign a vec3 swizzle to a vec2
//u = v.xyz; //Illegal
//u = v.rgb; //Illegal
//u = v.stp; //Illegal
u = v.xx; Error += (u.x == 1.0f && u.y == 1.0f) ? 0 : 1;
u = v.xy; Error += (u.x == 1.0f && u.y == 2.0f) ? 0 : 1;
u = v.xz; Error += (u.x == 1.0f && u.y == 3.0f) ? 0 : 1;
u = v.yx; Error += (u.x == 2.0f && u.y == 1.0f) ? 0 : 1;
u = v.yy; Error += (u.x == 2.0f && u.y == 2.0f) ? 0 : 1;
u = v.yz; Error += (u.x == 2.0f && u.y == 3.0f) ? 0 : 1;
u = v.zx; Error += (u.x == 3.0f && u.y == 1.0f) ? 0 : 1;
u = v.zy; Error += (u.x == 3.0f && u.y == 2.0f) ? 0 : 1;
u = v.zz; Error += (u.x == 3.0f && u.y == 3.0f) ? 0 : 1;
u = v.rr; Error += (u.r == 1.0f && u.g == 1.0f) ? 0 : 1;
u = v.rg; Error += (u.r == 1.0f && u.g == 2.0f) ? 0 : 1;
u = v.rb; Error += (u.r == 1.0f && u.g == 3.0f) ? 0 : 1;
u = v.gr; Error += (u.r == 2.0f && u.g == 1.0f) ? 0 : 1;
u = v.gg; Error += (u.r == 2.0f && u.g == 2.0f) ? 0 : 1;
u = v.gb; Error += (u.r == 2.0f && u.g == 3.0f) ? 0 : 1;
u = v.br; Error += (u.r == 3.0f && u.g == 1.0f) ? 0 : 1;
u = v.bg; Error += (u.r == 3.0f && u.g == 2.0f) ? 0 : 1;
u = v.bb; Error += (u.r == 3.0f && u.g == 3.0f) ? 0 : 1;
u = v.ss; Error += (u.s == 1.0f && u.t == 1.0f) ? 0 : 1;
u = v.st; Error += (u.s == 1.0f && u.t == 2.0f) ? 0 : 1;
u = v.sp; Error += (u.s == 1.0f && u.t == 3.0f) ? 0 : 1;
u = v.ts; Error += (u.s == 2.0f && u.t == 1.0f) ? 0 : 1;
u = v.tt; Error += (u.s == 2.0f && u.t == 2.0f) ? 0 : 1;
u = v.tp; Error += (u.s == 2.0f && u.t == 3.0f) ? 0 : 1;
u = v.ps; Error += (u.s == 3.0f && u.t == 1.0f) ? 0 : 1;
u = v.pt; Error += (u.s == 3.0f && u.t == 2.0f) ? 0 : 1;
u = v.pp; Error += (u.s == 3.0f && u.t == 3.0f) ? 0 : 1;
// Mixed member aliases are not valid
//u = v.rx; //Illegal
//u = v.sy; //Illegal
u = glm::vec2(1, 2);
v = glm::vec3(1, 2, 3);
//v.xx = u; //Illegal
v.xy = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 3.0f) ? 0 : 1;
v.xz = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 2.0f) ? 0 : 1;
v.yx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
//v.yy = u; //Illegal
v.yz = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1;
v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1;
//v.zz = u; //Illegal
return Error;
}
int test_vec3_swizzle3_3()
{
int Error = 0;
glm::vec3 v(1, 2, 3);
glm::vec3 u;
u = v; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.xyz; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.zyx; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.zyx = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.rgb; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.bgr; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.bgr = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
return Error;
}
int test_vec3_swizzle_half()
{
int Error = 0;
glm::half a1(1);
glm::half b1(2);
glm::half c1(3);
glm::hvec3 v(a1, b1, c1);
glm::hvec3 u;
u = v;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.xyz;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.zyx;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.zyx = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u = v.rgb;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.bgr;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.bgr = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u = v.stp;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.pts;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
u.pts = v;
Error += (u.x.toFloat() == 3.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 1.0f) ? 0 : 1;
return Error;
}
int test_vec3_swizzle_operators()
{
int Error = 0;
glm::vec3 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
// Swizzle, swizzle binary operators
q = u.xyz + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u.zyx + v.zyx).zyx; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v.xyz); Error += (q == (u - v)) ? 0 : 1;
q = (u.xyz * v.xyz); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v.xxx); Error += (q == glm::vec3(u.x * v.x)) ? 0 : 1;
q = (u.xyz / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// vec, swizzle binary operators
q = u + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u - v.xyz); Error += (q == (u - v)) ? 0 : 1;
q = (u * v.xyz); Error += (q == (u * v)) ? 0 : 1;
q = (u * v.xxx); Error += (q == v.x * u) ? 0 : 1;
q = (u / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// swizzle,vec binary operators
q = u.xyz + v; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v); Error += (q == (u - v)) ? 0 : 1;
q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1;
q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1;
// Compile errors
//q = (u.yz * v.xyz);
//q = (u * v.xy);
return Error;
}
int test_vec3_swizzle_functions()
{
int Error = 0;
//
// NOTE: template functions cannot pick up the implicit conversion from
// a swizzle to the unswizzled type, therefore the operator() must be
// used. E.g.:
//
// glm::dot(u.xy, v.xy); <--- Compile error
// glm::dot(u.xy(), v.xy()); <--- Compiles correctly
//
float r;
// vec2
glm::vec2 a(1, 2);
glm::vec2 b(10, 20);
r = glm::dot(a, b); Error += (int(r) == 50) ? 0 : 1;
r = glm::dot(a.xy(), b.xy()); Error += (int(r) == 50) ? 0 : 1;
r = glm::dot(a.xy(), b.yy()); Error += (int(r) == 60) ? 0 : 1;
// vec3
glm::vec3 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
r = glm::dot(u, v); Error += (int(r) == 140) ? 0 : 1;
r = glm::dot(u.xyz(), v.zyz()); Error += (int(r) == 160) ? 0 : 1;
r = glm::dot(u, v.zyx()); Error += (int(r) == 100) ? 0 : 1;
r = glm::dot(u.xyz(), v); Error += (int(r) == 140) ? 0 : 1;
r = glm::dot(u.xy(), v.xy()); Error += (int(r) == 50) ? 0 : 1;
// vec4
glm::vec4 s, t;
s = glm::vec4(1, 2, 3, 4);
t = glm::vec4(10, 20, 30, 40);
r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1;
return Error;
}
int test_vec3_swizzle_partial()
{
int Error = 0;
glm::vec3 A(1, 2, 3);
{
glm::vec3 B(A.xy, 3.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(1.0f, A.yz);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(A.xyz);
Error += A == B ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_vec3_ctor();
Error += test_vec3_operators();
Error += test_vec3_size();
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_vec3_swizzle_half();
Error += test_vec3_swizzle_partial();
Error += test_vec3_swizzle_operators();
Error += test_vec3_swizzle_functions();
return Error;
}

View file

@ -9,6 +9,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/half_float.hpp>
#include <vector>
template <int Value>
struct mask
@ -41,14 +42,161 @@ int test_hvec4()
return 0;
}
int test_vec4_ctor()
{
int Error = 0;
{
glm::vec4 A(1);
glm::vec4 B(1, 1, 1, 1);
Error += A == B ? 0 : 1;
}
{
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(glm::vec2(1, 2), 3, 4));
Tests.push_back(glm::vec4(1, glm::vec2(2, 3), 4));
Tests.push_back(glm::vec4(1, 2, glm::vec2(3, 4)));
Tests.push_back(glm::vec4(glm::vec3(1, 2, 3), 4));
Tests.push_back(glm::vec4(1, glm::vec3(2, 3, 4)));
Tests.push_back(glm::vec4(glm::vec2(1, 2), glm::vec2(3, 4)));
Tests.push_back(glm::vec4(1, 2, 3, 4));
Tests.push_back(glm::vec4(glm::vec4(1, 2, 3, 4)));
for(std::size_t i = 0; i < Tests.size(); ++i)
Error += Tests[i] == glm::vec4(1, 2, 3, 4) ? 0 : 1;
}
return Error;
}
int test_vec4_operators()
{
glm::vec4 A(1.0f);
glm::vec4 B(1.0f);
bool R = A != B;
bool S = A == B;
int Error = 0;
{
glm::vec4 A(1.0f);
glm::vec4 B(1.0f);
bool R = A != B;
bool S = A == B;
return (S && !R) ? 0 : 1;
Error += (S && !R) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
glm::vec4 C = A + B;
Error += C == glm::vec4(5, 7, 9, 11) ? 0 : 1;
glm::vec4 D = B - A;
Error += D == glm::vec4(3, 3, 3, 3) ? 0 : 1;
glm::vec4 E = A * B;
Error += E == glm::vec4(4, 10, 18, 28) ? 0 : 1;
glm::vec4 F = B / A;
Error += F == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
glm::vec4 G = A + 1.0f;
Error += G == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 H = B - 1.0f;
Error += H == glm::vec4(3, 4, 5, 6) ? 0 : 1;
glm::vec4 I = A * 2.0f;
Error += I == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 J = B / 2.0f;
Error += J == glm::vec4(2, 2.5, 3, 3.5) ? 0 : 1;
glm::vec4 K = 1.0f + A;
Error += K == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 L = 1.0f - B;
Error += L == glm::vec4(-3, -4, -5, -6) ? 0 : 1;
glm::vec4 M = 2.0f * A;
Error += M == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 N = 2.0f / B;
Error += N == glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A += B;
Error += A == glm::vec4(5, 7, 9, 11) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec4(6, 8, 10, 12) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B -= A;
Error += B == glm::vec4(3, 3, 3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec4(2, 2, 2, 2) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A *= B;
Error += A == glm::vec4(4, 10, 18, 28) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec4(8, 20, 36, 56) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B /= A;
Error += B == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec4(2, 1.25, 1, 7.0f / 4.0f / 2.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = -A;
Error += B == glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = --A;
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A--;
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = ++A;
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A++;
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
return Error;
}
int test_vec4_size()
@ -71,6 +219,7 @@ int main()
//__m128 DataB = swizzle<W, Z, Y, X>(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f));
int Error = 0;
Error += test_vec4_ctor();
Error += test_vec4_size();
Error += test_vec4_operators();
Error += test_hvec4();

10
test/glm.cppcheck Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<root name="glm"/>
<includedir>
<dir name=".."/>
</includedir>
<paths>
<dir name=".."/>
</paths>
</project>

View file

@ -3,6 +3,7 @@ glmCreateTestGTC(gtc_matrix_access)
glmCreateTestGTC(gtc_matrix_integer)
glmCreateTestGTC(gtc_matrix_inverse)
glmCreateTestGTC(gtc_matrix_transform)
glmCreateTestGTC(gtc_noise)
glmCreateTestGTC(gtc_quaternion)
glmCreateTestGTC(gtc_random)
glmCreateTestGTC(gtc_swizzle)

199
test/gtc/gtc_noise.cpp Normal file
View file

@ -0,0 +1,199 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-21
// Updated : 2011-04-26
// Licence : This source is under MIT licence
// File : test/gtx/noise.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtx/noise.hpp>
#include <gli/gli.hpp>
#include <gli/gtx/loader.hpp>
#include <iostream>
int test_simplex()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex4d_256.dds");
}
return 0;
}
int test_perlin()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin4d_256.dds");
}
return 0;
}
int test_perlin_pedioric()
{
std::size_t const Size = 256;
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f), glm::vec2(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f), glm::vec3(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f), glm::vec4(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_4d_256.dds");
}
return 0;
}
int main()
{
int Error = 0;
Error += test_simplex();
Error += test_perlin();
Error += test_perlin_pedioric();
return Error;
}

View file

@ -8,11 +8,11 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtx/random.hpp>
#include <glm/gtc/random.hpp>
#include <glm/gtx/epsilon.hpp>
#include <iostream>
int test_signedRand1()
int test_linearRand()
{
int Error = 0;
@ -21,8 +21,8 @@ int test_signedRand1()
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
{
ResultFloat += glm::signedRand1<float>(/*-1.0f, 1.0f*/);
ResultDouble += glm::signedRand1<double>(/*-1.0, 1.0*/);
ResultFloat += glm::linearRand(-1.0f, 1.0f);
ResultDouble += glm::linearRand(-1.0, 1.0);
}
Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f);
@ -33,7 +33,7 @@ int test_signedRand1()
return Error;
}
int test_normalizedRand2()
int test_circularRand()
{
int Error = 0;
@ -41,21 +41,23 @@ int test_normalizedRand2()
std::size_t Max = 100000;
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
double Radius = 2.0f;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloat += glm::length(glm::normalizedRand2(1.0f, 1.0f));
ResultDouble += glm::length(glm::normalizedRand2(1.0f, 1.0f));
ResultFloat += glm::length(glm::circularRand(1.0f));
ResultDouble += glm::length(glm::circularRand(Radius));
}
Error += glm::equalEpsilon(ResultFloat, float(Max), 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.01) ? 0 : 1;
Error += glm::equalEpsilon(ResultDouble, double(Max) * double(Radius), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_normalizedRand3()
int test_sphericalRand()
{
int Error = 0;
@ -67,22 +69,67 @@ int test_normalizedRand3()
double ResultDoubleA = 0.0f;
double ResultDoubleB = 0.0f;
double ResultDoubleC = 0.0f;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloatA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
ResultDoubleA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
ResultFloatA += glm::length(glm::sphericalRand(1.0f));
ResultDoubleA += glm::length(glm::sphericalRand(1.0));
ResultFloatB += glm::length(glm::sphericalRand(2.0f));
ResultDoubleB += glm::length(glm::sphericalRand(2.0));
ResultFloatC += glm::length(glm::sphericalRand(3.0f));
ResultDoubleC += glm::length(glm::sphericalRand(3.0));
}
Error += glm::equalEpsilon(ResultFloatA, float(Max), 100.0f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 100.0) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 100.0001f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 100.0001) ? 0 : 1;
Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatC, float(Max * 3), 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleC, double(Max * 3), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_diskRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
{
ResultFloat += glm::length(glm::diskRand(2.0f));
ResultDouble += glm::length(glm::diskRand(2.0));
}
Error += ResultFloat < 200000.f ? 0 : 1;
Error += ResultDouble < 200000.0 ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_ballRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
{
ResultFloat += glm::length(glm::ballRand(2.0f));
ResultDouble += glm::length(glm::ballRand(2.0));
}
Error += ResultFloat < 200000.f ? 0 : 1;
Error += ResultDouble < 200000.0 ? 0 : 1;
assert(!Error);
}
@ -93,9 +140,11 @@ int main()
{
int Error = 0;
Error += test_signedRand1();
Error += test_normalizedRand2();
Error += test_normalizedRand3();
Error += test_linearRand();
Error += test_circularRand();
Error += test_sphericalRand();
Error += test_diskRand();
Error += test_ballRand();
return Error;
}

View file

@ -121,13 +121,83 @@ int test_swizzle_vec4_const_static()
return Error;
}
int test_swizzle_vec3_partial()
{
int Error = 0;
glm::ivec3 A(0, 1, 2);
{
glm::ivec3 B(A.swizzle(glm::R, glm::G, glm::B));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec3 B(A.swizzle(glm::R, glm::G), 2);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec3 B(0, A.swizzle(glm::G, glm::B));
Error += (A == B) ? 0 : 1;
}
return Error;
}
int test_swizzle_vec4_partial()
{
int Error = 0;
glm::ivec4 A(0, 1, 2, 3);
{
glm::ivec4 B(A.swizzle(glm::R, glm::G, glm::B), 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::R, glm::G), 2, 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(0, A.swizzle(glm::G, glm::B), 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(0, 1, A.swizzle(glm::B, glm::A));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::X, glm::Y), A.swizzle(glm::Z, glm::W));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::X, glm::Y), glm::vec2(2, 3));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(glm::vec2(0, 1), A.swizzle(glm::Z, glm::W));
Error += (A == B) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_swizzle_vec3_partial();
Error += test_swizzle_vec4_ref_dynamic();
Error += test_swizzle_vec4_ref_static();
Error += test_swizzle_vec4_const_dynamic();
Error += test_swizzle_vec4_const_static();
Error += test_swizzle_vec4_partial();
return Error;
}

View file

@ -23,7 +23,7 @@ int test_simplex()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 16.f, y / 16.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -40,7 +40,7 @@ int test_simplex()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 16.f, y / 16.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -57,7 +57,7 @@ int test_simplex()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -81,7 +81,7 @@ int test_perlin()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 16.f, y / 16.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -98,7 +98,7 @@ int test_perlin()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -115,7 +115,7 @@ int test_perlin()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -139,7 +139,7 @@ int test_perlin_pedioric()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 16.f, y / 16.f), glm::vec2(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f), glm::vec2(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -156,7 +156,7 @@ int test_perlin_pedioric()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f), glm::vec3(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f), glm::vec3(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
@ -173,7 +173,7 @@ int test_perlin_pedioric()
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f), glm::vec4(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f), glm::vec4(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}