www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Implementing vector swizzle.

reply "TheFlyingFiddle" <theflyingfiddle gmail.com> writes:
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?
Dec 12 2013
parent "evilrat" <evilrat666 gmail.com> writes:
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
Dec 12 2013