December 13, 2013 Implementing vector swizzle. | ||||
---|---|---|---|---|
| ||||
I would like to be able to do this. auto vector = vec4(1,2,3,4); vector.zxy += vec3(4,4,4); I'm currently able to do this: vector.zxy = vec3(4,4,4); Assigns 4 to the x,y and z components. and this auto other = vector.zxy; other is a vector3 with other.x == vector.z other.y == vector.x other.z == vector.y However implementing the +=, -=, *=, /= operators is tricky. How would i go about doing that? |
December 13, 2013 Re: Implementing vector swizzle. | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheFlyingFiddle | On Friday, 13 December 2013 at 00:53:17 UTC, TheFlyingFiddle wrote: > I would like to be able to do this. > > auto vector = vec4(1,2,3,4); > vector.zxy += vec3(4,4,4); > > > > I'm currently able to do this: > > vector.zxy = vec3(4,4,4); > > Assigns 4 to the x,y and z components. > > and this > > auto other = vector.zxy; > other is a vector3 with > other.x == vector.z > other.y == vector.x > other.z == vector.y > > However implementing the > +=, -=, *=, /= operators is tricky. > > How would i go about doing that? i think gl3n[1] have implemented full GLSL-like swizzle. i haven't much used it, but you can look how it's done here. [1] https://github.com/Dav1dde/gl3n |
Copyright © 1999-2021 by the D Language Foundation