Package ch.bailu.gtk.graphene
Class Matrix
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.graphene.Matrix
- All Implemented Interfaces:
PointerInterface
A structure capable of holding a 4x4 matrix.
The contents of the #graphene_matrix_t structure are private and
should never be accessed directly.
The contents of the #graphene_matrix_t structure are private and
should never be accessed directly.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
Allocates a new #graphene_matrix_t.boolean
Decomposes a transformation matrix into its component transformations.float
Computes the determinant of the given matrix.boolean
Checks whether the two given #graphene_matrix_t matrices are equal.boolean
Checks whether the two given #graphene_matrix_t matrices are
byte-by-byte equal.void
free()
Frees the resources allocated by graphene_matrix_alloc().static ClassHandler
static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
float
Retrieves the scaling factor on the X axis in @m.float
Retrieves the translation component on the X axis from @m.float
Retrieves the scaling factor on the Y axis in @m.float
Retrieves the translation component on the Y axis from @m.float
Retrieves the scaling factor on the Z axis in @m.float
Retrieves the translation component on the Z axis from @m.initFrom2d
(double xx, double yx, double xy, double yy, double x_0, double y_0) Initializes a #graphene_matrix_t from the values of an affine
transformation matrix.initFromMatrix
(Matrix src) Initializes a #graphene_matrix_t using the values of the
given matrix.initFromVec4
(Vec4 v0, Vec4 v1, Vec4 v2, Vec4 v3) Initializes a #graphene_matrix_t with the given four row
vectors.initFrustum
(float left, float right, float bottom, float top, float z_near, float z_far) Initializes a #graphene_matrix_t compatible with #graphene_frustum_t.Initializes a #graphene_matrix_t with the identity matrix.initLookAt
(Vec3 eye, Vec3 center, Vec3 up) Initializes a #graphene_matrix_t so that it positions the "camera"
at the given @eye coordinates towards an object at the @center
coordinates.initOrtho
(float left, float right, float top, float bottom, float z_near, float z_far) Initializes a #graphene_matrix_t with an orthographic projection.initPerspective
(float fovy, float aspect, float z_near, float z_far) Initializes a #graphene_matrix_t with a perspective projection.initRotate
(float angle, Vec3 axis) Initializes @m to represent a rotation of @angle degrees on
the axis represented by the @axis vector.initScale
(float x, float y, float z) Initializes a #graphene_matrix_t with the given scaling factors.initSkew
(float x_skew, float y_skew) Initializes a #graphene_matrix_t with a skew transformation
with the given factors.Initializes a #graphene_matrix_t with a translation to the
given coordinates.void
interpolate
(Matrix b, double factor, Matrix res) Linearly interpolates the two given #graphene_matrix_t by
interpolating the decomposed transformations separately.boolean
Inverts the given matrix.boolean
is2d()
Checks whether the given #graphene_matrix_t is compatible with an
a 2D affine transformation matrix.boolean
Checks whether a #graphene_matrix_t has a visible back face.boolean
Checks whether the given #graphene_matrix_t is the identity matrix.boolean
Checks whether a matrix is singular.void
Multiplies two #graphene_matrix_t.boolean
Compares the two given #graphene_matrix_t matrices and checks
whether their values are within the given @epsilon of each
other.void
Normalizes the given #graphene_matrix_t.void
perspective
(float depth, Matrix res) Applies a perspective of @depth to the matrix.void
print()
Prints the contents of a matrix to the standard error stream.void
projectPoint
(Point p, Point res) Projects a #graphene_point_t using the matrix @m.void
projectRect
(Rect r, Quad res) Projects all corners of a #graphene_rect_t using the given matrix.void
projectRectBounds
(Rect r, Rect res) Projects a #graphene_rect_t using the given matrix.void
Adds a rotation transformation to @m, using the given @angle
and @axis vector.void
rotateEuler
(Euler e) Adds a rotation transformation to @m, using the given
#graphene_euler_t.void
Adds a rotation transformation to @m, using the given
#graphene_quaternion_t.void
rotateX
(float angle) Adds a rotation transformation around the X axis to @m, using
the given @angle.void
rotateY
(float angle) Adds a rotation transformation around the Y axis to @m, using
the given @angle.void
rotateZ
(float angle) Adds a rotation transformation around the Z axis to @m, using
the given @angle.void
scale
(float factor_x, float factor_y, float factor_z) Adds a scaling transformation to @m, using the three
given factors.void
skewXy
(float factor) Adds a skew of @factor on the X and Y axis to the given matrix.void
skewXz
(float factor) Adds a skew of @factor on the X and Z axis to the given matrix.void
skewYz
(float factor) Adds a skew of @factor on the Y and Z axis to the given matrix.void
Converts a #graphene_matrix_t to an array of floating point
values.void
transformBounds
(Rect r, Rect res) Transforms each corner of a #graphene_rect_t using the given matrix @m.void
transformBox
(Box b, Box res) Transforms the vertices of a #graphene_box_t using the given matrix @m.void
transformPoint
(Point p, Point res) Transforms the given #graphene_point_t using the matrix @m.void
transformPoint3d
(Point3D p, Point3D res) Transforms the given #graphene_point3d_t using the matrix @m.void
transformRay
(Ray r, Ray res) Transform a #graphene_ray_t using the given matrix @m.void
transformRect
(Rect r, Quad res) Transforms each corner of a #graphene_rect_t using the given matrix @m.void
transformSphere
(Sphere s, Sphere res) Transforms a #graphene_sphere_t using the given matrix @m.void
transformVec3
(Vec3 v, Vec3 res) Transforms the given #graphene_vec3_t using the matrix @m.void
transformVec4
(Vec4 v, Vec4 res) Transforms the given #graphene_vec4_t using the matrix @m.void
Adds a translation transformation to @m using the coordinates
of the given #graphene_point3d_t.void
Transposes the given matrix.void
unprojectPoint3d
(Matrix modelview, Point3D point, Point3D res) Unprojects the given @point using the @projection matrix and
a @modelview matrix.void
untransformBounds
(Rect r, Rect bounds, Rect res) Undoes the transformation on the corners of a #graphene_rect_t using the
given matrix, within the given axis aligned rectangular @bounds.boolean
untransformPoint
(Point p, Rect bounds, Point res) Undoes the transformation of a #graphene_point_t using the
given matrix, within the given axis aligned rectangular @bounds.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
Matrix
-
-
Method Details
-
getClassHandler
-
allocMatrix
Allocates a new #graphene_matrix_t.- Returns:
- the newly allocated matrix
-
decompose
public boolean decompose(@Nonnull Vec3 translate, @Nonnull Vec3 scale, @Nonnull Quaternion rotate, @Nonnull Vec3 shear, @Nonnull Vec4 perspective) Decomposes a transformation matrix into its component transformations.
The algorithm for decomposing a matrix is taken from the
[CSS3 Transforms specification](http://dev.w3.org/csswg/css-transforms/);
specifically, the decomposition code is based on the equivalent code
published in "Graphics Gems II", edited by Jim Arvo, and
[available online](http://web.archive.org/web/20150512160205/http://tog.acm.org/resources/GraphicsGems/gemsii/unmatrix.c).- Parameters:
translate
- the translation vectorscale
- the scale vectorrotate
- the rotation quaternionshear
- the shear vectorperspective
- the perspective vector- Returns:
- `true` if the matrix could be decomposed
-
determinant
public float determinant()Computes the determinant of the given matrix.- Returns:
- the value of the determinant
-
equal
Checks whether the two given #graphene_matrix_t matrices are equal.- Parameters:
b
- a #graphene_matrix_t- Returns:
- `true` if the two matrices are equal, and `false` otherwise
-
equalFast
Checks whether the two given #graphene_matrix_t matrices are
byte-by-byte equal.
While this function is faster than graphene_matrix_equal(), it
can also return false negatives, so it should be used in
conjuction with either graphene_matrix_equal() or
graphene_matrix_near(). For instance:
<!-- language="C" --> 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 }
- Parameters:
b
- a #graphene_matrix_t- Returns:
- `true` if the matrices are equal. and `false` otherwise
-
free
public void free()Frees the resources allocated by graphene_matrix_alloc(). -
getXScale
public float getXScale()Retrieves the scaling factor on the X axis in @m.- Returns:
- the value of the scaling factor
-
getXTranslation
public float getXTranslation()Retrieves the translation component on the X axis from @m.- Returns:
- the translation component
-
getYScale
public float getYScale()Retrieves the scaling factor on the Y axis in @m.- Returns:
- the value of the scaling factor
-
getYTranslation
public float getYTranslation()Retrieves the translation component on the Y axis from @m.- Returns:
- the translation component
-
getZScale
public float getZScale()Retrieves the scaling factor on the Z axis in @m.- Returns:
- the value of the scaling factor
-
getZTranslation
public float getZTranslation()Retrieves the translation component on the Z axis from @m.- Returns:
- the translation component
-
initFrom2d
Initializes a #graphene_matrix_t from the values of an affine
transformation matrix.
The arguments map to the following matrix layout:
<!-- language="plain" --> ⎛ 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 #graphene_matrix_t.- Parameters:
xx
- the xx memberyx
- the yx memberxy
- the xy memberyy
- the yy memberx_0
- the x0 membery_0
- the y0 member- Returns:
- the initialized matrix
-
initFromMatrix
Initializes a #graphene_matrix_t using the values of the
given matrix.- Parameters:
src
- a #graphene_matrix_t- Returns:
- the initialized matrix
-
initFromVec4
Initializes a #graphene_matrix_t with the given four row
vectors.- Parameters:
v0
- the first row vectorv1
- the second row vectorv2
- the third row vectorv3
- the fourth row vector- Returns:
- the initialized matrix
-
initFrustum
public Matrix initFrustum(float left, float right, float bottom, float top, float z_near, float z_far) Initializes a #graphene_matrix_t compatible with #graphene_frustum_t.
See also: graphene_frustum_init_from_matrix()- Parameters:
left
- distance of the left clipping planeright
- distance of the right clipping planebottom
- distance of the bottom clipping planetop
- distance of the top clipping planez_near
- distance of the near clipping planez_far
- distance of the far clipping plane- Returns:
- the initialized matrix
-
initIdentity
Initializes a #graphene_matrix_t with the identity matrix.- Returns:
- the initialized matrix
-
initLookAt
Initializes a #graphene_matrix_t 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.
Before the transform, the camera is assumed to be placed at the
origin, looking towards the negative Z axis, with the top side of
the camera facing in the direction of the Y axis and the right
side in the direction of the X axis.
In theory, one could use @m to transform a model of such a camera
into world-space. However, it is more common to use the inverse of
@m to transform another object from world coordinates to the view
coordinates of the camera. Typically you would then apply the
camera projection transform to get from view to screen
coordinates.- Parameters:
eye
- the vector describing the position to look fromcenter
- the vector describing the position to look atup
- the vector describing the world's upward direction; usually, this is the graphene_vec3_y_axis() vector- Returns:
- the initialized matrix
-
initOrtho
public Matrix initOrtho(float left, float right, float top, float bottom, float z_near, float z_far) Initializes a #graphene_matrix_t with an orthographic projection.- Parameters:
left
- the left edge of the clipping planeright
- the right edge of the clipping planetop
- the top edge of the clipping planebottom
- the bottom edge of the clipping planez_near
- the distance of the near clipping planez_far
- the distance of the far clipping plane- Returns:
- the initialized matrix
-
initPerspective
Initializes a #graphene_matrix_t with a perspective projection.- Parameters:
fovy
- the field of view angle, in degreesaspect
- the aspect valuez_near
- the near Z planez_far
- the far Z plane- Returns:
- the initialized matrix
-
initRotate
Initializes @m to represent a rotation of @angle degrees on
the axis represented by the @axis vector.- Parameters:
angle
- the rotation angle, in degreesaxis
- the axis vector as a #graphene_vec3_t- Returns:
- the initialized matrix
-
initScale
Initializes a #graphene_matrix_t with the given scaling factors.- Parameters:
x
- the scale factor on the X axisy
- the scale factor on the Y axisz
- the scale factor on the Z axis- Returns:
- the initialized matrix
-
initSkew
Initializes a #graphene_matrix_t with a skew transformation
with the given factors.- Parameters:
x_skew
- skew factor, in radians, on the X axisy_skew
- skew factor, in radians, on the Y axis- Returns:
- the initialized matrix
-
initTranslate
Initializes a #graphene_matrix_t with a translation to the
given coordinates.- Parameters:
p
- the translation coordinates- Returns:
- the initialized matrix
-
interpolate
Linearly interpolates the two given #graphene_matrix_t 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.- Parameters:
b
- a #graphene_matrix_tfactor
- the linear interpolation factorres
- return location for the interpolated matrix
-
inverse
Inverts the given matrix.- Parameters:
res
- return location for the inverse matrix- Returns:
- `true` if the matrix is invertible
-
is2d
public boolean is2d()Checks whether the given #graphene_matrix_t is compatible with an
a 2D affine transformation matrix.- Returns:
- `true` if the matrix is compatible with an affine transformation matrix
-
isBackfaceVisible
public boolean isBackfaceVisible()Checks whether a #graphene_matrix_t has a visible back face.- Returns:
- `true` if the back face of the matrix is visible
-
isIdentity
public boolean isIdentity()Checks whether the given #graphene_matrix_t is the identity matrix.- Returns:
- `true` if the matrix is the identity matrix
-
isSingular
public boolean isSingular()Checks whether a matrix is singular.- Returns:
- `true` if the matrix is singular
-
multiply
Multiplies two #graphene_matrix_t.
Matrix multiplication is not commutative in general; the order of the factors matters.
The product of this multiplication is (@a × @b)- Parameters:
b
- a #graphene_matrix_tres
- return location for the matrix result
-
near
Compares the two given #graphene_matrix_t matrices and checks
whether their values are within the given @epsilon of each
other.- Parameters:
b
- a #graphene_matrix_tepsilon
- the threshold between the two matrices- Returns:
- `true` if the two matrices are near each other, and `false` otherwise
-
normalize
Normalizes the given #graphene_matrix_t.- Parameters:
res
- return location for the normalized matrix
-
perspective
Applies a perspective of @depth to the matrix.- Parameters:
depth
- the depth of the perspectiveres
- return location for the perspective matrix
-
print
public void print()Prints the contents of a matrix to the standard error stream.
This function is only useful for debugging; there are no guarantees
made on the format of the output. -
projectPoint
Projects a #graphene_point_t using the matrix @m.- Parameters:
p
- a #graphene_point_tres
- return location for the projected point
-
projectRect
Projects all corners of a #graphene_rect_t using the given matrix.
See also: graphene_matrix_project_point()- Parameters:
r
- a #graphene_rect_tres
- return location for the projected rectangle
-
projectRectBounds
Projects a #graphene_rect_t using the given matrix.
The resulting rectangle is the axis aligned bounding rectangle capable
of fully containing the projected rectangle.- Parameters:
r
- a #graphene_rect_tres
- return location for the projected rectangle
-
rotate
Adds a rotation transformation to @m, using the given @angle
and @axis vector.
This is the equivalent of calling graphene_matrix_init_rotate() and
then multiplying the matrix @m with the rotation matrix.- Parameters:
angle
- the rotation angle, in degreesaxis
- the rotation axis, as a #graphene_vec3_t
-
rotateEuler
Adds a rotation transformation to @m, using the given
#graphene_euler_t.- Parameters:
e
- a rotation described by a #graphene_euler_t
-
rotateQuaternion
Adds a rotation transformation to @m, using the given
#graphene_quaternion_t.
This is the equivalent of calling graphene_quaternion_to_matrix() and
then multiplying @m with the rotation matrix.- Parameters:
q
- a rotation described by a #graphene_quaternion_t
-
rotateX
public void rotateX(float angle) Adds a rotation transformation around the X axis to @m, using
the given @angle.
See also: graphene_matrix_rotate()- Parameters:
angle
- the rotation angle, in degrees
-
rotateY
public void rotateY(float angle) Adds a rotation transformation around the Y axis to @m, using
the given @angle.
See also: graphene_matrix_rotate()- Parameters:
angle
- the rotation angle, in degrees
-
rotateZ
public void rotateZ(float angle) Adds a rotation transformation around the Z axis to @m, using
the given @angle.
See also: graphene_matrix_rotate()- Parameters:
angle
- the rotation angle, in degrees
-
scale
public void scale(float factor_x, float factor_y, float factor_z) Adds a scaling transformation to @m, using the three
given factors.
This is the equivalent of calling graphene_matrix_init_scale() and then
multiplying the matrix @m with the scale matrix.- Parameters:
factor_x
- scaling factor on the X axisfactor_y
- scaling factor on the Y axisfactor_z
- scaling factor on the Z axis
-
skewXy
public void skewXy(float factor) Adds a skew of @factor on the X and Y axis to the given matrix.- Parameters:
factor
- skew factor
-
skewXz
public void skewXz(float factor) Adds a skew of @factor on the X and Z axis to the given matrix.- Parameters:
factor
- skew factor
-
skewYz
public void skewYz(float factor) Adds a skew of @factor on the Y and Z axis to the given matrix.- Parameters:
factor
- skew factor
-
toFloat
Converts a #graphene_matrix_t to an array of floating point
values.- Parameters:
v
- return location for an array of floating point values. The array must be capable of holding at least 16 values.
-
transformBounds
Transforms each corner of a #graphene_rect_t using the given matrix @m.
The result is the axis aligned bounding rectangle containing the coplanar
quadrilateral.
See also: graphene_matrix_transform_point()- Parameters:
r
- a #graphene_rect_tres
- return location for the bounds of the transformed rectangle
-
transformBox
Transforms the vertices of a #graphene_box_t using the given matrix @m.
The result is the axis aligned bounding box containing the transformed
vertices.- Parameters:
b
- a #graphene_box_tres
- return location for the bounds of the transformed box
-
transformPoint
Transforms the given #graphene_point_t using the matrix @m.
Unlike graphene_matrix_transform_vec3(), this function will take into
account the fourth row vector of the #graphene_matrix_t when computing
the dot product of each row vector of the matrix.
See also: graphene_simd4x4f_point3_mul()- Parameters:
p
- a #graphene_point_tres
- return location for the transformed #graphene_point_t
-
transformPoint3d
Transforms the given #graphene_point3d_t using the matrix @m.
Unlike graphene_matrix_transform_vec3(), this function will take into
account the fourth row vector of the #graphene_matrix_t when computing
the dot product of each row vector of the matrix.
See also: graphene_simd4x4f_point3_mul()- Parameters:
p
- a #graphene_point3d_tres
- return location for the result
-
transformRay
Transform a #graphene_ray_t using the given matrix @m.- Parameters:
r
- a #graphene_ray_tres
- return location for the transformed ray
-
transformRect
Transforms each corner of a #graphene_rect_t using the given matrix @m.
The result is a coplanar quadrilateral.
See also: graphene_matrix_transform_point()- Parameters:
r
- a #graphene_rect_tres
- return location for the transformed quad
-
transformSphere
Transforms a #graphene_sphere_t using the given matrix @m. The
result is the bounding sphere containing the transformed sphere.- Parameters:
s
- a #graphene_sphere_tres
- return location for the bounds of the transformed sphere
-
transformVec3
Transforms the given #graphene_vec3_t 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()- Parameters:
v
- a #graphene_vec3_tres
- return location for a #graphene_vec3_t
-
transformVec4
Transforms the given #graphene_vec4_t using the matrix @m.
See also: graphene_simd4x4f_vec4_mul()- Parameters:
v
- a #graphene_vec4_tres
- return location for a #graphene_vec4_t
-
translate
Adds a translation transformation to @m using the coordinates
of the given #graphene_point3d_t.
This is the equivalent of calling graphene_matrix_init_translate() and
then multiplying @m with the translation matrix.- Parameters:
pos
- a #graphene_point3d_t
-
transpose
Transposes the given matrix.- Parameters:
res
- return location for the transposed matrix
-
unprojectPoint3d
public void unprojectPoint3d(@Nonnull Matrix modelview, @Nonnull Point3D point, @Nonnull Point3D res) Unprojects the given @point using the @projection matrix and
a @modelview matrix.- Parameters:
modelview
- a #graphene_matrix_t for the modelview matrix; this is the inverse of the modelview used when projecting the pointpoint
- a #graphene_point3d_t with the coordinates of the pointres
- return location for the unprojected point
-
untransformBounds
Undoes the transformation on the corners of a #graphene_rect_t using the
given matrix, within the given axis aligned rectangular @bounds.- Parameters:
r
- a #graphene_rect_tbounds
- the bounds of the transformationres
- return location for the untransformed rectangle
-
untransformPoint
Undoes the transformation of a #graphene_point_t using the
given matrix, within the given axis aligned rectangular @bounds.- Parameters:
p
- a #graphene_point_tbounds
- the bounds of the transformationres
- return location for the untransformed point- Returns:
- `true` if the point was successfully untransformed
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-