Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A CoglMatrix holds a 4x4 transform matrix. This is a single precision, column-major matrix which means it is compatible with what OpenGL expects.
A CoglMatrix can represent transforms such as, rotations, scaling, translation, sheering, and linear projections. You can combine these transforms by multiplying multiple matrices in the order you want them applied.
The transformation of a vertex (x, y, z, w) by a CoglMatrix is given by:
x_new = xx * x + xy * y + xz * z + xw * w y_new = yx * x + yy * y + yz * z + yw * w z_new = zx * x + zy * y + zz * z + zw * w w_new = wx * x + wy * y + wz * z + ww * w
Where w is normally 1
<note>You must consider the members of the CoglMatrix structure read only,
and all matrix modifications must be done via the cogl_matrix API. This
allows Cogl to annotate the matrices internally. Violation of this will give
undefined results. If you need to initialize a matrix with a constant other
than the identity matrix you can use matrixInitFromArray
.</note>
Synopsis
- newtype Matrix = Matrix (ManagedPtr Matrix)
- newZeroMatrix :: MonadIO m => m Matrix
- matrixCopy :: (HasCallStack, MonadIO m) => Matrix -> m Matrix
- matrixEqual :: (HasCallStack, MonadIO m) => Ptr () -> Ptr () -> m Int32
- matrixFree :: (HasCallStack, MonadIO m) => Matrix -> m ()
- matrixFrustum :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> Float -> Float -> m ()
- matrixGetArray :: (HasCallStack, MonadIO m) => Matrix -> m Float
- matrixGetInverse :: (HasCallStack, MonadIO m) => Matrix -> m (Int32, Matrix)
- matrixInitFromArray :: (HasCallStack, MonadIO m) => Matrix -> Float -> m ()
- matrixInitIdentity :: (HasCallStack, MonadIO m) => Matrix -> m ()
- matrixInitTranslation :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> m ()
- matrixIsIdentity :: (HasCallStack, MonadIO m) => Matrix -> m Int32
- matrixLookAt :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> Float -> m ()
- matrixMultiply :: (HasCallStack, MonadIO m) => Matrix -> Matrix -> Matrix -> m ()
- matrixOrtho :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> Float -> Float -> m ()
- matrixPerspective :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> m ()
- matrixRotate :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> m ()
- matrixScale :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> m ()
- matrixTransformPoint :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> Float -> m (Float, Float, Float, Float)
- matrixTranslate :: (HasCallStack, MonadIO m) => Matrix -> Float -> Float -> Float -> m ()
- matrixTranspose :: (HasCallStack, MonadIO m) => Matrix -> m ()
- getMatrixWw :: MonadIO m => Matrix -> m Float
- setMatrixWw :: MonadIO m => Matrix -> Float -> m ()
- getMatrixWx :: MonadIO m => Matrix -> m Float
- setMatrixWx :: MonadIO m => Matrix -> Float -> m ()
- getMatrixWy :: MonadIO m => Matrix -> m Float
- setMatrixWy :: MonadIO m => Matrix -> Float -> m ()
- getMatrixWz :: MonadIO m => Matrix -> m Float
- setMatrixWz :: MonadIO m => Matrix -> Float -> m ()
- getMatrixXw :: MonadIO m => Matrix -> m Float
- setMatrixXw :: MonadIO m => Matrix -> Float -> m ()
- getMatrixXx :: MonadIO m => Matrix -> m Float
- setMatrixXx :: MonadIO m => Matrix -> Float -> m ()
- getMatrixXy :: MonadIO m => Matrix -> m Float
- setMatrixXy :: MonadIO m => Matrix -> Float -> m ()
- getMatrixXz :: MonadIO m => Matrix -> m Float
- setMatrixXz :: MonadIO m => Matrix -> Float -> m ()
- getMatrixYw :: MonadIO m => Matrix -> m Float
- setMatrixYw :: MonadIO m => Matrix -> Float -> m ()
- getMatrixYx :: MonadIO m => Matrix -> m Float
- setMatrixYx :: MonadIO m => Matrix -> Float -> m ()
- getMatrixYy :: MonadIO m => Matrix -> m Float
- setMatrixYy :: MonadIO m => Matrix -> Float -> m ()
- getMatrixYz :: MonadIO m => Matrix -> m Float
- setMatrixYz :: MonadIO m => Matrix -> Float -> m ()
- getMatrixZw :: MonadIO m => Matrix -> m Float
- setMatrixZw :: MonadIO m => Matrix -> Float -> m ()
- getMatrixZx :: MonadIO m => Matrix -> m Float
- setMatrixZx :: MonadIO m => Matrix -> Float -> m ()
- getMatrixZy :: MonadIO m => Matrix -> m Float
- setMatrixZy :: MonadIO m => Matrix -> Float -> m ()
- getMatrixZz :: MonadIO m => Matrix -> m Float
- setMatrixZz :: MonadIO m => Matrix -> Float -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq Matrix Source # | |
GBoxed Matrix Source # | |
Defined in GI.Cogl.Structs.Matrix | |
ManagedPtrNewtype Matrix Source # | |
Defined in GI.Cogl.Structs.Matrix toManagedPtr :: Matrix -> ManagedPtr Matrix | |
TypedObject Matrix Source # | |
Defined in GI.Cogl.Structs.Matrix | |
HasParentTypes Matrix Source # | |
Defined in GI.Cogl.Structs.Matrix | |
tag ~ 'AttrSet => Constructible Matrix tag Source # | |
IsGValue (Maybe Matrix) Source # | Convert |
Defined in GI.Cogl.Structs.Matrix gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe Matrix -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe Matrix) | |
type ParentTypes Matrix Source # | |
Defined in GI.Cogl.Structs.Matrix |
Methods
Click to display all available methods, including inherited ones
Methods
copy, free, frustum, initFromArray, initIdentity, initTranslation, isIdentity, lookAt, multiply, ortho, perspective, rotate, scale, transformPoint, translate, transpose.
Getters
Setters
None.
copy
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Matrix | Returns: A newly allocated |
Allocates a new Matrix
on the heap and initializes it with
the same values as matrix
.
Since: 1.6
equal
:: (HasCallStack, MonadIO m) | |
=> Ptr () |
|
-> Ptr () |
|
-> m Int32 |
Compares two matrices to see if they represent the same transformation. Although internally the matrices may have different annotations associated with them and may potentially have a cached inverse matrix these are not considered in the comparison.
Since: 1.4
free
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m () |
Frees a Matrix
that was previously allocated via a call to
matrixCopy
.
Since: 1.6
frustum
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Multiplies matrix
by the given frustum perspective matrix.
getArray
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Float | Returns: a pointer to the float array |
Casts matrix
to a float array which can be directly passed to OpenGL.
getInverse
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m (Int32, Matrix) | Returns: |
Gets the inverse transform of a given matrix and uses it to initialize
a new Matrix
.
<note>Although the first parameter is annotated as const to indicate
that the transform it represents isn't modified this function may
technically save a copy of the inverse transform within the given
Matrix
so that subsequent requests for the inverse transform may
avoid costly inversion calculations.</note>
Since: 1.2
initFromArray
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> m () |
Initializes matrix
with the contents of array
initIdentity
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m () |
Resets matrix to the identity matrix:
.xx=1; .xy=0; .xz=0; .xw=0; .yx=0; .yy=1; .yz=0; .yw=0; .zx=0; .zy=0; .zz=1; .zw=0; .wx=0; .wy=0; .wz=0; .ww=1;
initTranslation
matrixInitTranslation Source #
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Resets matrix to the (tx, ty, tz) translation matrix:
.xx=1; .xy=0; .xz=0; .xw=tx; .yx=0; .yy=1; .yz=0; .yw=ty; .zx=0; .zy=0; .zz=1; .zw=tz; .wx=0; .wy=0; .wz=0; .ww=1;
Since: 2.0
isIdentity
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m Int32 |
Determines if the given matrix is an identity matrix.
Since: 1.8
lookAt
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Applies a view transform matrix
that positions the camera at
the coordinate (eyePositionX
, eyePositionY
, eyePositionZ
)
looking towards an object at the coordinate (objectX
, objectY
,
objectZ
). The top of the camera is aligned to the given world up
vector, which is normally simply (0, 1, 0) to map up to the
positive direction of the y axis.
Because there is a lot of missleading documentation online for gluLookAt regarding the up vector we want to try and be a bit clearer here.
The up vector should simply be relative to your world coordinates and does not need to change as you move the eye and object positions. Many online sources may claim that the up vector needs to be perpendicular to the vector between the eye and object position (partly because the man page is somewhat missleading) but that is not necessary for this function.
<note>You should never look directly along the world-up vector.</note>
<note>It is assumed you are using a typical projection matrix where your origin maps to the center of your viewport.</note>
<note>Almost always when you use this function it should be the first transform applied to a new modelview transform</note>
Since: 1.8
multiply
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Matrix |
|
-> Matrix |
|
-> m () |
Multiplies the two supplied matrices together and stores
the resulting matrix inside result
.
<note>It is possible to multiply the a
matrix in-place, so
result
can be equal to a
but can't be equal to b
.</note>
ortho
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Deprecated: (Since version 1.10)Use cogl_matrix_orthographic()
Multiplies matrix
by a parallel projection matrix.
perspective
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Multiplies matrix
by the described perspective matrix
<note>You should be careful not to have to great a zFar
/ zNear
ratio since that will reduce the effectiveness of depth testing
since there wont be enough precision to identify the depth of
objects near to each other.</note>
rotate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Multiplies matrix
with a rotation matrix that applies a rotation
of angle
degrees around the specified 3D vector.
scale
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Multiplies matrix
with a transform matrix that scales along the X,
Y and Z axis.
transformPoint
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m (Float, Float, Float, Float) |
Transforms a point whos position is given and returned as four float components.
translate
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m () |
Multiplies matrix
with a transform matrix that translates along
the X, Y and Z axis.
transpose
:: (HasCallStack, MonadIO m) | |
=> Matrix |
|
-> m () |
Replaces matrix
with its transpose. Ie, every element (i,j) in the
new matrix is taken from element (j,i) in the old matrix.
Since: 1.10
Properties
ww
No description available in the introspection data.
getMatrixWw :: MonadIO m => Matrix -> m Float Source #
Get the value of the “ww
” field.
When overloading is enabled, this is equivalent to
get
matrix #ww
setMatrixWw :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “ww
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #ww:=
value ]
wx
No description available in the introspection data.
getMatrixWx :: MonadIO m => Matrix -> m Float Source #
Get the value of the “wx
” field.
When overloading is enabled, this is equivalent to
get
matrix #wx
setMatrixWx :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “wx
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #wx:=
value ]
wy
No description available in the introspection data.
getMatrixWy :: MonadIO m => Matrix -> m Float Source #
Get the value of the “wy
” field.
When overloading is enabled, this is equivalent to
get
matrix #wy
setMatrixWy :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “wy
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #wy:=
value ]
wz
No description available in the introspection data.
getMatrixWz :: MonadIO m => Matrix -> m Float Source #
Get the value of the “wz
” field.
When overloading is enabled, this is equivalent to
get
matrix #wz
setMatrixWz :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “wz
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #wz:=
value ]
xw
No description available in the introspection data.
getMatrixXw :: MonadIO m => Matrix -> m Float Source #
Get the value of the “xw
” field.
When overloading is enabled, this is equivalent to
get
matrix #xw
setMatrixXw :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “xw
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #xw:=
value ]
xx
No description available in the introspection data.
getMatrixXx :: MonadIO m => Matrix -> m Float Source #
Get the value of the “xx
” field.
When overloading is enabled, this is equivalent to
get
matrix #xx
setMatrixXx :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “xx
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #xx:=
value ]
xy
No description available in the introspection data.
getMatrixXy :: MonadIO m => Matrix -> m Float Source #
Get the value of the “xy
” field.
When overloading is enabled, this is equivalent to
get
matrix #xy
setMatrixXy :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “xy
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #xy:=
value ]
xz
No description available in the introspection data.
getMatrixXz :: MonadIO m => Matrix -> m Float Source #
Get the value of the “xz
” field.
When overloading is enabled, this is equivalent to
get
matrix #xz
setMatrixXz :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “xz
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #xz:=
value ]
yw
No description available in the introspection data.
getMatrixYw :: MonadIO m => Matrix -> m Float Source #
Get the value of the “yw
” field.
When overloading is enabled, this is equivalent to
get
matrix #yw
setMatrixYw :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “yw
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #yw:=
value ]
yx
No description available in the introspection data.
getMatrixYx :: MonadIO m => Matrix -> m Float Source #
Get the value of the “yx
” field.
When overloading is enabled, this is equivalent to
get
matrix #yx
setMatrixYx :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “yx
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #yx:=
value ]
yy
No description available in the introspection data.
getMatrixYy :: MonadIO m => Matrix -> m Float Source #
Get the value of the “yy
” field.
When overloading is enabled, this is equivalent to
get
matrix #yy
setMatrixYy :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “yy
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #yy:=
value ]
yz
No description available in the introspection data.
getMatrixYz :: MonadIO m => Matrix -> m Float Source #
Get the value of the “yz
” field.
When overloading is enabled, this is equivalent to
get
matrix #yz
setMatrixYz :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “yz
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #yz:=
value ]
zw
No description available in the introspection data.
getMatrixZw :: MonadIO m => Matrix -> m Float Source #
Get the value of the “zw
” field.
When overloading is enabled, this is equivalent to
get
matrix #zw
setMatrixZw :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “zw
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #zw:=
value ]
zx
No description available in the introspection data.
getMatrixZx :: MonadIO m => Matrix -> m Float Source #
Get the value of the “zx
” field.
When overloading is enabled, this is equivalent to
get
matrix #zx
setMatrixZx :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “zx
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #zx:=
value ]
zy
No description available in the introspection data.
getMatrixZy :: MonadIO m => Matrix -> m Float Source #
Get the value of the “zy
” field.
When overloading is enabled, this is equivalent to
get
matrix #zy
setMatrixZy :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “zy
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #zy:=
value ]
zz
No description available in the introspection data.
getMatrixZz :: MonadIO m => Matrix -> m Float Source #
Get the value of the “zz
” field.
When overloading is enabled, this is equivalent to
get
matrix #zz
setMatrixZz :: MonadIO m => Matrix -> Float -> m () Source #
Set the value of the “zz
” field.
When overloading is enabled, this is equivalent to
set
matrix [ #zz:=
value ]