reflect

3D reflect, like the GLSL function.

@nogc pure nothrow
Vector!(T, N)
reflect
(
T
int N
)
(
const Vector!(T, N) a
,
const Vector!(T, N) b
)

Return Value

Type: Vector!(T, N)

a reflected by normal b.

Examples

// reflect a 2D vector across the x axis (the normal points along the y axis)
assert(vec2f(1,1).reflect(vec2f(0,1)) == vec2f(1,-1));
assert(vec2f(1,1).reflect(vec2f(0,-1)) == vec2f(1,-1));

// note that the normal must be, well, normalized:
assert(vec2f(1,1).reflect(vec2f(0,20)) != vec2f(1,-1));

// think of this like a ball hitting a flat floor at an angle.
// the x and y components remain unchanged, and the z inverts
assert(vec3f(2,3,-0.5).reflect(vec3f(0,0,1)) == vec3f(2,3,0.5));

Meta