-
-
Save destiny0114/b85e41c1254036a14a1c8949f39e6e19 to your computer and use it in GitHub Desktop.
tsl rotation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const rotate2D = Fn(({pos,angle})=>{ | |
| const s = sin(angle); | |
| const c = cos(angle); | |
| const m = mat2(c, s, s.mul(-1), c); | |
| return m.mul(pos); | |
| }) | |
| const rotate3D = Fn(({pos,axis,angle})=>{ | |
| const axisNorm = normalize(axis); | |
| const s = sin(angle); | |
| const c = cos(angle); | |
| const oc = float(1).sub(c); | |
| const matrix4 = mat4( | |
| oc.mul(axisNorm.x).mul(axisNorm.x).add(c), oc.mul(axisNorm.x).mul(axisNorm.y).sub(axisNorm.z.mul(s)), oc.mul(axisNorm.z).mul(axisNorm.x).add(axisNorm.y.mul(s)), 0.0, | |
| oc.mul(axisNorm.x).mul(axisNorm.y).add(axisNorm.z.mul(s)), oc.mul(axisNorm.y).mul(axisNorm.y).add(c), oc.mul(axisNorm.y).mul(axisNorm.z).sub(axisNorm.x.mul(s)), 0.0, | |
| oc.mul(axisNorm.z).mul(axisNorm.x).sub(axisNorm.y.mul(s)), oc.mul(axisNorm.y).mul(axisNorm.z).add(axisNorm.x.mul(s)), oc.mul(axisNorm.z).mul(axisNorm.z).add(c), 0.0, | |
| 0.0, 0.0, 0.0, 1.0 | |
| ) | |
| return matrix4.mul(pos).xyz; | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment