Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
- Exported types
- Methods
- Overloaded methods
- alloc
- determinant
- equal
- equalFast
- free
- getRow
- getValue
- getXScale
- getXTranslation
- getYScale
- getYTranslation
- getZScale
- getZTranslation
- initFrom2d
- initFromFloat
- initFromMatrix
- initFromVec4
- initFrustum
- initIdentity
- initLookAt
- initOrtho
- initPerspective
- initRotate
- initScale
- initSkew
- initTranslate
- interpolate
- inverse
- is2d
- isBackfaceVisible
- isIdentity
- isSingular
- multiply
- near
- normalize
- perspective
- projectPoint
- projectRect
- projectRectBounds
- rotate
- rotateEuler
- rotateQuaternion
- rotateX
- rotateY
- rotateZ
- scale
- skewXy
- skewXz
- skewYz
- to2d
- transformBounds
- transformBox
- transformPoint
- transformPoint3d
- transformRay
- transformRect
- transformSphere
- transformVec3
- transformVec4
- translate
- transpose
- unprojectPoint3d
- untransformBounds
- untransformPoint
A structure capable of holding a 4x4 matrix.
The contents of the Matrix
structure are private and
should never be accessed directly.
Synopsis
- newtype Matrix = Matrix (ManagedPtr Matrix)
- newZeroMatrix :: MonadIO m => m Matrix
- noMatrix :: Maybe Matrix
- matrixAlloc :: (HasCallStack, MonadIO m) => m Matrix
- matrixDeterminant :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixEqual :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> m Bool
- matrixEqualFast :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> m Bool
- matrixFree :: (HasCallStack, MonadIO m) => Matrix -> m ()
- matrixGetRow :: (HasCallStack, MonadIO m) => Matrix -> Word32 -> m Vec4
- matrixGetValue :: (HasCallStack, MonadIO m) => Matrix -> Word32 -> Word32 -> m Float
- matrixGetXScale :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetXTranslation :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetYScale :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetYTranslation :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetZScale :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetZTranslation :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixInitFrom2d :: (HasCallStack, MonadIO m) => Matrix -> Double -> Double -> Double -> Double -> Double -> Double -> m Matrix
- matrixInitFromFloat :: (HasCallStack, MonadIO m) => Matrix -> [Float] -> m Matrix
- matrixInitFromMatrix :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> m Matrix
- matrixInitFromVec4 :: (HasCallStack, MonadIO m) => Matrix -> Vec4 -> Vec4 -> Vec4 -> Vec4 -> m Matrix
- matrixInitFrustum :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> Float -> Float -> m Matrix
- matrixInitIdentity :: (HasCallStack, MonadIO m) => Matrix -> m Matrix
- matrixInitLookAt :: (HasCallStack, MonadIO m) => Matrix -> Vec3 -> Vec3 -> Vec3 -> m Matrix
- matrixInitOrtho :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> Float -> Float -> m Matrix
- matrixInitPerspective :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> m Matrix
- matrixInitRotate :: (HasCallStack, MonadIO m) => Matrix -> Float -> Vec3 -> m Matrix
- matrixInitScale :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> m Matrix
- matrixInitSkew :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> m Matrix
- matrixInitTranslate :: (HasCallStack, MonadIO m) => Matrix -> Point3D -> m Matrix
- matrixInterpolate :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> Double -> m Matrix
- matrixInverse :: (HasCallStack, MonadIO m) => Matrix -> m (Bool, Matrix)
- matrixIs2d :: (HasCallStack, MonadIO m) => Matrix -> m Bool
- matrixIsBackfaceVisible :: (HasCallStack, MonadIO m) => Matrix -> m Bool
- matrixIsIdentity :: (HasCallStack, MonadIO m) => Matrix -> m Bool
- matrixIsSingular :: (HasCallStack, MonadIO m) => Matrix -> m Bool
- matrixMultiply :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> m Matrix
- matrixNear :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> Float -> m Bool
- matrixNormalize :: (HasCallStack, MonadIO m) => Matrix -> m Matrix
- matrixPerspective :: (HasCallStack, MonadIO m) => Matrix -> Float -> m Matrix
- matrixPrint :: (HasCallStack, MonadIO m) => Matrix -> m ()
- matrixProjectPoint :: (HasCallStack, MonadIO m) => Matrix -> Point -> m Point
- matrixProjectRect :: (HasCallStack, MonadIO m) => Matrix -> Rect -> m Quad
- matrixProjectRectBounds :: (HasCallStack, MonadIO m) => Matrix -> Rect -> m Rect
- matrixRotate :: (HasCallStack, MonadIO m) => Matrix -> Float -> Vec3 -> m ()
- matrixRotateEuler :: (HasCallStack, MonadIO m) => Matrix -> Euler -> m ()
- matrixRotateQuaternion :: (HasCallStack, MonadIO m) => Matrix -> Quaternion -> m ()
- matrixRotateX :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixRotateY :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixRotateZ :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixScale :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> m ()
- matrixSkewXy :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixSkewXz :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixSkewYz :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixTo2d :: (HasCallStack, MonadIO m) => Matrix -> m (Bool, Double, Double, Double, Double, Double, Double)
- matrixTransformBounds :: (HasCallStack, MonadIO m) => Matrix -> Rect -> m Rect
- matrixTransformBox :: (HasCallStack, MonadIO m) => Matrix -> Box -> m Box
- matrixTransformPoint :: (HasCallStack, MonadIO m) => Matrix -> Point -> m Point
- matrixTransformPoint3d :: (HasCallStack, MonadIO m) => Matrix -> Point3D -> m Point3D
- matrixTransformRay :: (HasCallStack, MonadIO m) => Matrix -> Ray -> m Ray
- matrixTransformRect :: (HasCallStack, MonadIO m) => Matrix -> Rect -> m Quad
- matrixTransformSphere :: (HasCallStack, MonadIO m) => Matrix -> Sphere -> m Sphere
- matrixTransformVec3 :: (HasCallStack, MonadIO m) => Matrix -> Vec3 -> m Vec3
- matrixTransformVec4 :: (HasCallStack, MonadIO m) => Matrix -> Vec4 -> m Vec4
- matrixTranslate :: (HasCallStack, MonadIO m) => Matrix -> Point3D -> m ()
- matrixTranspose :: (HasCallStack, MonadIO m) => Matrix -> m Matrix
- matrixUnprojectPoint3d :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> Point3D -> m Point3D
- matrixUntransformBounds :: (HasCallStack, MonadIO m) => Matrix -> Rect -> Rect -> m Rect
- matrixUntransformPoint :: (HasCallStack, MonadIO m) => Matrix -> Point -> Rect -> m (Bool, Point)
Exported types
Memory-managed wrapper type.
Methods
Overloaded methods
alloc
:: (HasCallStack, MonadIO m) | |
=> m Matrix | Returns: the newly allocated matrix |
Allocates a new Matrix
.
Since: 1.0
determinant
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the value of the determinant |
Computes the determinant of the given matrix.
Since: 1.0
equal
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> m Bool | Returns: |
Checks whether the two given Matrix
matrices are equal.
Since: 1.10
equalFast
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> m Bool | Returns: |
Checks whether the two given Matrix
matrices are
byte-by-byte equal.
While this function is faster than matrixEqual
, it
can also return false negatives, so it should be used in
conjuction with either matrixEqual
or
matrixNear
. For instance:
C code
if (graphene_matrix_equal_fast (a, b)) { // matrices are definitely the same } else { if (graphene_matrix_equal (a, b)) // matrices contain the same values within an epsilon of FLT_EPSILON else if (graphene_matrix_near (a, b, 0.0001)) // matrices contain the same values within an epsilon of 0.0001 else // matrices are not equal }
Since: 1.10
free
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m () |
Frees the resources allocated by matrixAlloc
.
Since: 1.0
getRow
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Word32 |
|
-> m Vec4 |
Retrieves the given row vector at index_
inside a matrix.
Since: 1.0
getValue
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Word32 |
|
-> Word32 |
|
-> m Float | Returns: the value at the given indices |
Retrieves the value at the given row
and col
index.
Since: 1.0
getXScale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the value of the scaling factor |
Retrieves the scaling factor on the X axis in m
.
Since: 1.0
getXTranslation
matrixGetXTranslation Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the translation component |
Retrieves the translation component on the X axis from m
.
Since: 1.10
getYScale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the value of the scaling factor |
Retrieves the scaling factor on the Y axis in m
.
Since: 1.0
getYTranslation
matrixGetYTranslation Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the translation component |
Retrieves the translation component on the Y axis from m
.
Since: 1.10
getZScale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the value of the scaling factor |
Retrieves the scaling factor on the Z axis in m
.
Since: 1.0
getZTranslation
matrixGetZTranslation Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: the translation component |
Retrieves the translation component on the Z axis from m
.
Since: 1.10
initFrom2d
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Double |
|
-> Double |
|
-> Double |
|
-> Double |
|
-> Double |
|
-> Double |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
from the values of an affine
transformation matrix.
The arguments map to the following matrix layout:
plain code
⎛ xx yx ⎞ ⎛ a b 0 ⎞ ⎜ xy yy ⎟ = ⎜ c d 0 ⎟ ⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠
This function can be used to convert between an affine matrix type
from other libraries and a Matrix
.
Since: 1.0
initFromFloat
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> [Float] |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with the given array of floating
point values.
Since: 1.0
initFromMatrix
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
using the values of the
given matrix.
Since: 1.0
initFromVec4
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Vec4 |
|
-> Vec4 |
|
-> Vec4 |
|
-> Vec4 |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with the given four row
vectors.
Since: 1.0
initFrustum
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m Matrix | Returns: the initialized matrix |
initIdentity
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with the identity matrix.
Since: 1.0
initLookAt
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Vec3 |
|
-> Vec3 |
|
-> Vec3 |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
so that it positions the "camera"
at the given eye
coordinates towards an object at the center
coordinates. The top of the camera is aligned to the direction
of the up
vector.
Since: 1.0
initOrtho
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with an orthographic projection.
Since: 1.0
initPerspective
matrixInitPerspective Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with a perspective projection.
Since: 1.0
initRotate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Vec3 |
|
-> m Matrix | Returns: the initialized matrix |
Initializes m
to represent a rotation of angle
degrees on
the axis represented by the axis
vector.
Since: 1.0
initScale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with the given scaling factors.
Since: 1.0
initSkew
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with a skew transformation
with the given factors.
Since: 1.0
initTranslate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Point3D |
|
-> m Matrix | Returns: the initialized matrix |
Initializes a Matrix
with a translation to the
given coordinates.
Since: 1.0
interpolate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> Double |
|
-> m Matrix |
Linearly interpolates the two given Matrix
by
interpolating the decomposed transformations separately.
If either matrix cannot be reduced to their transformations then the interpolation cannot be performed, and this function will return an identity matrix.
Since: 1.0
inverse
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m (Bool, Matrix) | Returns: |
Inverts the given matrix.
Since: 1.0
is2d
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Bool | Returns: |
Checks whether the given Matrix
is compatible with an
a 2D affine transformation matrix.
Since: 1.0
isBackfaceVisible
matrixIsBackfaceVisible Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Bool | Returns: |
Checks whether a Matrix
has a visible back face.
Since: 1.0
isIdentity
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Bool | Returns: |
Checks whether the given Matrix
is the identity matrix.
Since: 1.0
isSingular
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Bool | Returns: |
Checks whether a matrix is singular.
Since: 1.0
multiply
Multiplies two Matrix
.
Matrix multiplication is not commutative in general; the order of the factors matters.
The product of this multiplication is (a
× b
)
Since: 1.0
near
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> Float |
|
-> m Bool | Returns: |
Compares the two given Matrix
matrices and checks
whether their values are within the given epsilon
of each
other.
Since: 1.10
normalize
perspective
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m Matrix |
Applies a perspective of depth
to the matrix.
Since: 1.0
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m () |
Prints the contents of a matrix.
Since: 1.0
projectPoint
Projects a Point
using the matrix m
.
Since: 1.0
projectRect
Projects a Rect
using the given matrix.
Since: 1.2
projectRectBounds
matrixProjectRectBounds Source #
Projects a Rect
using the given matrix.
The resulting rectangle is the axis aligned bounding rectangle capable of containing fully the projected rectangle.
Since: 1.0
rotate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Vec3 |
|
-> m () |
Adds a rotation transformation to m
, using the given angle
and axis
vector.
This is the equivalent of calling matrixInitRotate
and
then multiplying the matrix m
with the rotation matrix.
Since: 1.0
rotateEuler
Adds a rotation transformation to m
, using the given
Euler
.
Since: 1.2
rotateQuaternion
matrixRotateQuaternion Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Quaternion |
|
-> m () |
Adds a rotation transformation to m
, using the given
Quaternion
.
This is the equivalent of calling quaternionToMatrix
and
then multiplying m
with the rotation matrix.
Since: 1.2
rotateX
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a rotation transformation around the X axis to m
, using
the given angle
.
See also: matrixRotate
Since: 1.0
rotateY
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a rotation transformation around the Y axis to m
, using
the given angle
.
See also: matrixRotate
Since: 1.0
rotateZ
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a rotation transformation around the Z axis to m
, using
the given angle
.
See also: matrixRotate
Since: 1.0
scale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Adds a scaling transformation to m
, using the three
given factors.
This is the equivalent of calling matrixInitScale
and then
multiplying the matrix m
with the scale matrix.
Since: 1.0
skewXy
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a skew of factor
on the X and Y axis to the given matrix.
Since: 1.0
skewXz
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a skew of factor
on the X and Z axis to the given matrix.
Since: 1.0
skewYz
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Adds a skew of factor
on the Y and Z axis to the given matrix.
Since: 1.0
to2d
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m (Bool, Double, Double, Double, Double, Double, Double) | Returns: |
Converts a Matrix
to an affine transformation
matrix, if the given matrix is compatible.
The returned values have the following layout:
plain code
⎛ xx yx ⎞ ⎛ a b 0 ⎞ ⎜ xy yy ⎟ = ⎜ c d 0 ⎟ ⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠
This function can be used to convert between a Matrix
and an affine matrix type from other libraries.
Since: 1.0
transformBounds
matrixTransformBounds Source #
Transforms each corner of a Rect
using the given matrix m
.
The result is the axis aligned bounding rectangle containing the coplanar quadrilateral.
Since: 1.0
transformBox
Transforms the vertices of a Box
using the given matrix m
.
The result is the axis aligned bounding box containing the transformed vertices.
Since: 1.2
transformPoint
Transforms the given Point
using the matrix m
.
Unlike matrixTransformVec3
, this function will take into
account the fourth row vector of the Matrix
when computing
the dot product of each row vector of the matrix.
See also: graphene_simd4x4f_point3_mul()
Since: 1.0
transformPoint3d
matrixTransformPoint3d Source #
Transforms the given Point3D
using the matrix m
.
Unlike matrixTransformVec3
, this function will take into
account the fourth row vector of the Matrix
when computing
the dot product of each row vector of the matrix.
Since: 1.2
transformRay
Transform a Ray
using the given matrix m
.
Since: 1.4
transformRect
Transforms each corner of a Rect
using the given matrix m
.
The result is a coplanar quadrilateral.
Since: 1.0
transformSphere
matrixTransformSphere Source #
Transforms a Sphere
using the given matrix m
. The
result is the bounding sphere containing the transformed sphere.
Since: 1.2
transformVec3
Transforms the given Vec3
using the matrix m
.
This function will multiply the X, Y, and Z row vectors of the matrix m
with the corresponding components of the vector v
. The W row vector will
be ignored.
See also: graphene_simd4x4f_vec3_mul()
Since: 1.0
transformVec4
translate
Adds a translation transformation to m
using the coordinates
of the given Point3D
.
This is the equivalent of calling matrixInitTranslate
and
then multiplying m
with the translation matrix.
Since: 1.0
transpose
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Matrix |
Transposes the given matrix.
Since: 1.0
unprojectPoint3d
matrixUnprojectPoint3d Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> Point3D |
|
-> m Point3D |
Unprojects the given point
using the projection
matrix and
a modelview
matrix.
Since: 1.2
untransformBounds
matrixUntransformBounds Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Rect |
|
-> Rect |
|
-> m Rect |
Undoes the transformation on the corners of a Rect
using the
given matrix, within the given axis aligned rectangular bounds
.
Since: 1.0
untransformPoint
matrixUntransformPoint Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Point |
|
-> Rect |
|
-> m (Bool, Point) | Returns: |
Undoes the transformation of a Point
using the
given matrix, within the given axis aligned rectangular bounds
.
Since: 1.0