zmath.math3d

Usefull functions to work in 3d math

  • Declaration

    immutable bool is4dMat(M);

    Checks if a type is a valid Matrix for 3d math over 4d

  • Declaration

    pure nothrow @nogc M perspectiveMat(M = Mat4f, T = float, U = float, V = float, W = float)(T fov, U aspect, V zMin, W zMax) if (is4dMat!M && isNumeric!T && isNumeric!U && isNumeric!V && isNumeric!W);

    Creates a projection matrix (similar to gluPerspective)

    Parameters

    T fov

    Field of View in radians (PI_2 -> 90ยบ)

    U aspect

    Aspect ratio (x/y)

    V zMin

    Near clipping plane

    W zMax

    Far clipping plane Returns a perspective projection matrix

  • Declaration

    pure nothrow @nogc M orthoMat(M = Mat4f, T = float, U = float, V = float, W = float, X = float, Y = float)(T xMin, U xMax, V yMin, W yMax, X zMin = 0, Y zMax = 1) if (is4dMat!M && isNumeric!T && isNumeric!U && isNumeric!V && isNumeric!W && isNumeric!X && isNumeric!Y);

    Creates a orthographic projection matrix

    Parameters

    T xMin

    Left clipping plane

    U xMax

    Right clipping plane

    V yMin

    Bottom clipping plane

    W yMax

    Top clipping plane

    X zMin

    Near clipping plane

    Y zMax

    Far clipping plane Returns a orthographic projection matrix

  • Declaration

    pure nothrow @nogc M orthoMat(M = Mat4f, T = float, U = float, V = float)(T width = 1, U height = 1, V deep = 1) if (is4dMat!M && isNumeric!T && isNumeric!U && isNumeric!V);

    Creates a orthographic projection matrix

    Parameters

    T width

    Width of visible zone

    U height

    Height of visible zone

    V deep

    Deep of visible zone Returns a orthographic projection matrix

  • Declaration

    pure nothrow @nogc M translateMat(M = Mat4f, V = Vec3f)(V v) if (isVector!V && (V.dim <= 3) && is4dMat!M);

    Creates a translation matrix from a 2d/3d Vector

    Parameters

    V v

    2d/3d Vector Returns a translation matrix

  • Declaration

    pure nothrow @nogc M translateMat(M = Mat4f, T = float)(T x, T y, T z) if (is4dMat!M && is(T : real));

    Creates a translation matrix from xyz coords

    Parameters

    T x

    X coord

    T y

    Y coord

    T z

    Z coord Returns a translation matrix

  • Declaration

    pure nothrow @nogc M scaleMat(M = Mat4f, T = float)(T s) if (is4dMat!M && is(T : real));

    Creates a uniform 3d scale matrix

    Parameters

    T s

    scale factor Returns a scale matrix

  • Declaration

    pure nothrow @nogc M scaleMat(M = Mat4f, T = float)(T x, T y, T z) if (is4dMat!M && is(T : real));

    Creates a not uniform 3d scale matrix

    Parameters

    T x

    X axis scale

    T y

    Y axis scale

    T z

    Z axis scale Returns a scale matrix

  • Declaration

    pure nothrow @nogc M scaleMat(M = Mat4f, V = Vec3f)(V v) if (isVector!V && (V.dim <= 3) && is4dMat!M);

    Creates a not uniform 3d scale matrix

    Parameters

    V v

    Vector with scale factor. If is a 2d Vector, z axis scale factor is 1 Returns a scale matrix

  • Declaration

    pure nothrow @nogc M rotMat(M = Mat4f, V = Vec3f, T = float)(V v, T angle) if (isVector!V && (V.dim <= 3) && is4dMat!M && __traits(isFloating, T));

    Creates a rotation matrix from a axis and angle in radians

    Parameters

    V v

    Rotation axis

    T angle

    angle in radians Returns a 3d rotation matrix

  • Declaration

    pure nothrow @nogc M rotMat(M = Mat4f, T = float, U = float)(T x, T y, T z, U angle) if (is4dMat!M && is(T : real) && is(U : real));

    Creates a rotation matrix from a axis and angle in radians

    Parameters

    T x

    X coord of rotation axis

    T y

    Y coord of rotation axis

    T z

    Z coord of rotation axis

    U angle

    angle in radians Returns a 3d rotation matrix

  • Declaration

    M rotMat(M = Mat4f, Q = Qua_f)(Q q) if (is4dMat!M && isQuaternion!Q);

    Creates a rotation matrix from a Quaternion

    Parameters

    Q q

    Quaternion that represents a rotation Returns a 3d rotation matrix

  • Declaration

    pure nothrow @nogc M lookAt(M = Mat4f, V = Vec3f, T = float)(V eye, V target, V up) if (is4dMat!M && isNumeric!T && isVector!V && (V.dim <= 3));

    Look At projection Based on gfm code