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)(Tfov
, Uaspect
, VzMin
, WzMax
) 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)(TxMin
, UxMax
, VyMin
, WyMax
, XzMin
= 0, YzMax
= 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)(Twidth
= 1, Uheight
= 1, Vdeep
= 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)(Vv
) 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)(Tx
, Ty
, Tz
) 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)(Ts
) 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)(Tx
, Ty
, Tz
) 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)(Vv
) 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)(Vv
, Tangle
) if (isVector!V && (V.dim <= 3) && is4dMat!M && __traits(isFloating, T));Creates a rotation matrix from a axis and
angle
in radiansParameters
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)(Tx
, Ty
, Tz
, Uangle
) if (is4dMat!M && is(T : real) && is(U : real));Creates a rotation matrix from a axis and
angle
in radiansParameters
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)(Qq
) 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)(Veye
, Vtarget
, Vup
) if (is4dMat!M && isNumeric!T && isVector!V && (V.dim <= 3));Look At projection Based on gfm code