4 ms·
WebGL's swizzling vector selectors.[1] Where v.x desugars as v[0], v.y as v[1]. Similarly for z and w. Also r,g,b,a. And they swizzle: v.rgb, v.xz, v.zx . So `v
by mncharity 4y ago
WebGL's swizzling vector selectors.[1] Where v.x desugars as v[0], v.y as v[1]. Similarly for z and w. Also r,g,b,a. And they swizzle: v.rgb, v.xz, v.zx . So `v1.xy = v0.yx` reflects.
[1] https://www.w3.org/TR/WGSL/#vector-access-expr https://www.w3.org/TR/WGSL/#vector-access-expr
- unsafecast 4y agoThat applies to GLSL in general. I tried once to emulate that using C unions, but quickly realized that there's no solution for v.xz, v.xw, v.yw, etc. You can write functions like xyz(v) and that works well enough. Even better if you have ufcs or methods.
- still_grokking 4y agoWhich leads to the question why you would use offset / index syntax instead of dot syntax in the first place. Therefore I would prefer something like this to be the usual array access syntax: val chars = Array("a", "b", "c") val secondChar = a.2 // as a shorthand for `chars.atIndex(2)`, or equivalently `chars.atOffset(1)`, maybe also with `a..1` for the offset case (Also we should stop calling the offset "index", and get a proper "atIndex" method.)