├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── rotate.glsl ├── rotateQ.glsl ├── rotateX.glsl ├── rotateY.glsl └── rotateZ.glsl /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/webstorm 2 | 3 | ### WebStorm ### 4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 5 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 6 | 7 | # ---------- whole directory 8 | .idea/ 9 | 10 | ## User-specific stuff: 11 | #.idea/workspace.xml 12 | #.idea/tasks.xml 13 | #.idea/dictionaries 14 | #.idea/vcs.xml 15 | #.idea/jsLibraryMappings.xml 16 | # 17 | ## Sensitive or high-churn files: 18 | #.idea/dataSources.ids 19 | #.idea/dataSources.xml 20 | #.idea/dataSources.local.xml 21 | #.idea/sqlDataSources.xml 22 | #.idea/dynamic.xml 23 | #.idea/uiDesigner.xml 24 | 25 | ## Gradle: 26 | #.idea/gradle.xml 27 | #.idea/libraries 28 | # 29 | ## Mongo Explorer plugin: 30 | #.idea/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.iws 34 | 35 | ## Plugin-specific files: 36 | 37 | # IntelliJ 38 | /out/ 39 | 40 | # mpeltonen/sbt-idea plugin 41 | .idea_modules/ 42 | 43 | # JIRA plugin 44 | atlassian-ide-plugin.xml 45 | 46 | # Crashlytics plugin (for Android Studio and IntelliJ) 47 | com_crashlytics_export_strings.xml 48 | crashlytics.properties 49 | crashlytics-build.properties 50 | fabric.properties 51 | 52 | ### WebStorm Patch ### 53 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 54 | 55 | # *.iml 56 | # modules.xml 57 | # .idea/misc.xml 58 | # *.ipr 59 | 60 | 61 | 62 | 63 | 64 | # Created by https://www.gitignore.io/api/node 65 | 66 | ### Node ### 67 | # Logs 68 | logs 69 | *.log 70 | npm-debug.log* 71 | 72 | # Runtime data 73 | pids 74 | *.pid 75 | *.seed 76 | *.pid.lock 77 | 78 | # Directory for instrumented libs generated by jscoverage/JSCover 79 | lib-cov 80 | 81 | # Coverage directory used by tools like istanbul 82 | coverage 83 | 84 | # nyc test coverage 85 | .nyc_output 86 | 87 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 88 | .grunt 89 | 90 | # node-waf configuration 91 | .lock-wscript 92 | 93 | # Compiled binary addons (http://nodejs.org/api/addons.html) 94 | build/Release 95 | 96 | # Dependency directories 97 | node_modules 98 | jspm_packages 99 | 100 | # Optional npm cache directory 101 | .npm 102 | 103 | # Optional REPL history 104 | .node_repl_history 105 | 106 | 107 | 108 | 109 | 110 | # Created by https://www.gitignore.io/api/windows 111 | 112 | ### Windows ### 113 | # Windows image file caches 114 | Thumbs.db 115 | ehthumbs.db 116 | 117 | # Folder config file 118 | Desktop.ini 119 | 120 | # Recycle Bin used on file shares 121 | $RECYCLE.BIN/ 122 | 123 | # Windows Installer files 124 | *.cab 125 | *.msi 126 | *.msm 127 | *.msp 128 | 129 | # Windows shortcuts 130 | *.lnk 131 | 132 | 133 | 134 | 135 | 136 | # Created by https://www.gitignore.io/api/osx 137 | 138 | ### OSX ### 139 | *.DS_Store 140 | .AppleDouble 141 | .LSOverride 142 | 143 | # Icon must end with two \r 144 | Icon 145 | 146 | 147 | # Thumbnails 148 | ._* 149 | 150 | # Files that might appear in the root of a volume 151 | .DocumentRevisions-V100 152 | .fseventsd 153 | .Spotlight-V100 154 | .TemporaryItems 155 | .Trashes 156 | .VolumeIcon.icns 157 | .com.apple.timemachine.donotpresent 158 | 159 | # Directories potentially created on remote AFP share 160 | .AppleDB 161 | .AppleDesktop 162 | Network Trash Folder 163 | Temporary Items 164 | .apdisk 165 | 166 | 167 | 168 | 169 | 170 | # Created by https://www.gitignore.io/api/linux 171 | 172 | ### Linux ### 173 | *~ 174 | 175 | # temporary files which can be created if a process still has a handle open of a deleted file 176 | .fuse_hidden* 177 | 178 | # KDE directory preferences 179 | .directory 180 | 181 | # Linux trash folder which might appear on any partition or disk 182 | .Trash-* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018, Yuichiroh Arai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glsl-y-rotate 2 | 3 | A GLSL Module which generates a rotation matrix. 4 | 5 | Recommend using [glslify](https://github.com/glslify/glslify). 6 | 7 | ## Usage ## 8 | 9 | [![NPM](https://nodei.co/npm/glsl-y-rotate.png?mini=true)](https://nodei.co/npm/glsl-y-rotate/) 10 | 11 | ### 2D (mat2) ### 12 | 13 | ```glsl 14 | #pragma glslify: rotate = require(glsl-y-rotate) 15 | 16 | const float DEG_TO_RAD = 3.141592653589793 / 180.0; 17 | 18 | void main(void) { 19 | vec2 pos = vec2(1.0, 0.0); 20 | 21 | pos = rotate(45.0 * DEG_TO_RAD) * pos; 22 | } 23 | ``` 24 | 25 | ### 3D (mat3) ### 26 | 27 | ```glsl 28 | #pragma glslify: rotateX = require(glsl-y-rotate/rotateX) 29 | #pragma glslify: rotateY = require(glsl-y-rotate/rotateY) 30 | #pragma glslify: rotateZ = require(glsl-y-rotate/rotateZ) 31 | 32 | const float DEG_TO_RAD = 3.141592653589793 / 180.0; 33 | 34 | void main(void) { 35 | vec3 pos = vec3(0.0, 0.0, 1.0); 36 | 37 | pos = rotateZ(20.0 * DEG_TO_RAD) * pos; 38 | pos = rotateY(15.0 * DEG_TO_RAD) * pos; 39 | pos = rotateX(10.0 * DEG_TO_RAD) * pos; 40 | } 41 | ``` 42 | 43 | ### Quaternion (mat3) ### 44 | 45 | ```glsl 46 | #pragma glslify: rotateQ = require(glsl-y-rotate/rotateQ) 47 | 48 | const float DEG_TO_RAD = 3.141592653589793 / 180.0; 49 | 50 | void main(void) { 51 | vec3 pos = vec3(0.0, 0.0, 1.0); 52 | 53 | vec3 axis = normalize(vec3(1.0, 1.0, 0.0)); 54 | 55 | pos = rotateQ(axis, 20.0 * DEG_TO_RAD) * pos; 56 | } 57 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "glsl-y-rotate", 3 | "version": "3.0.0", 4 | "description": "A GLSL Module which generates a rotation matrix", 5 | "main": "rotate.glsl", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://yuichiroharai@github.com/yuichiroharai/glsl-y-rotate.git" 10 | }, 11 | "keywords": [ 12 | "glsl", 13 | "glslify", 14 | "shader", 15 | "webgl", 16 | "math", 17 | "matrix", 18 | "quaternion", 19 | "rotate" 20 | ], 21 | "author": { 22 | "name": "Yuichiroh Arai", 23 | "url": "http://www.yuichiroharai.com/" 24 | }, 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/yuichiroharai/glsl-y-rotate/issues" 28 | }, 29 | "homepage": "https://github.com/yuichiroharai/glsl-y-rotate#readme" 30 | } 31 | -------------------------------------------------------------------------------- /rotate.glsl: -------------------------------------------------------------------------------- 1 | mat2 rotate(float rad) { 2 | float c = cos(rad); 3 | float s = sin(rad); 4 | return mat2( 5 | c, s, 6 | -s, c 7 | ); 8 | } 9 | 10 | #pragma glslify: export(rotate) -------------------------------------------------------------------------------- /rotateQ.glsl: -------------------------------------------------------------------------------- 1 | mat3 rotateQ(vec3 axis, float rad) { 2 | float hr = rad / 2.0; 3 | float s = sin( hr ); 4 | vec4 q = vec4(axis * s, cos( hr )); 5 | vec3 q2 = q.xyz + q.xyz; 6 | vec3 qq2 = q.xyz * q2; 7 | vec2 qx = q.xx * q2.yz; 8 | float qy = q.y * q2.z; 9 | vec3 qw = q.w * q2.xyz; 10 | 11 | return mat3( 12 | 1.0 - (qq2.y + qq2.z), qx.x - qw.z, qx.y + qw.y, 13 | qx.x + qw.z, 1.0 - (qq2.x + qq2.z), qy - qw.x, 14 | qx.y - qw.y, qy + qw.x, 1.0 - (qq2.x + qq2.y) 15 | ); 16 | } 17 | 18 | #pragma glslify: export(rotateQ) -------------------------------------------------------------------------------- /rotateX.glsl: -------------------------------------------------------------------------------- 1 | mat3 rotateX(float rad) { 2 | float c = cos(rad); 3 | float s = sin(rad); 4 | return mat3( 5 | 1.0, 0.0, 0.0, 6 | 0.0, c, s, 7 | 0.0, -s, c 8 | ); 9 | } 10 | 11 | #pragma glslify: export(rotateX) -------------------------------------------------------------------------------- /rotateY.glsl: -------------------------------------------------------------------------------- 1 | mat3 rotateY(float rad) { 2 | float c = cos(rad); 3 | float s = sin(rad); 4 | return mat3( 5 | c, 0.0, -s, 6 | 0.0, 1.0, 0.0, 7 | s, 0.0, c 8 | ); 9 | } 10 | 11 | #pragma glslify: export(rotateY) -------------------------------------------------------------------------------- /rotateZ.glsl: -------------------------------------------------------------------------------- 1 | mat3 rotateZ(float rad) { 2 | float c = cos(rad); 3 | float s = sin(rad); 4 | return mat3( 5 | c, s, 0.0, 6 | -s, c, 0.0, 7 | 0.0, 0.0, 1.0 8 | ); 9 | } 10 | 11 | #pragma glslify: export(rotateZ) --------------------------------------------------------------------------------