Class Matrix
- All Implemented Interfaces:
Proxy
The contents of the graphene_matrix_t structure are private and
should never be accessed directly.
-
Constructor Summary
ConstructorsConstructorDescriptionMatrix()Allocate a new Matrix.Allocate a new Matrix.Matrix(MemorySegment address) Create a Matrix proxy instance for the provided memory address.Allocate a new Matrix with the fields set to the provided values.Allocate a new Matrix with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionstatic Matrixalloc()Allocates a newgraphene_matrix_t.booleanDecomposes a transformation matrix into its component transformations.floatComputes the determinant of the given matrix.booleanChecks whether the two givengraphene_matrix_tmatrices are equal.booleanChecks whether the two givengraphene_matrix_tmatrices are byte-by-byte equal.voidfree()Frees the resources allocated by graphene_matrix_alloc().static MemoryLayoutThe memory layout of the native struct.voidRetrieves the given row vector atindexinside a matrix.static @Nullable TypegetType()Get the GType of the Matrix classfloatgetValue(int row, int col) Retrieves the value at the givenrowandcolindex.floatRetrieves the scaling factor on the X axis inm.floatRetrieves the translation component on the X axis fromm.floatRetrieves the scaling factor on the Y axis inm.floatRetrieves the translation component on the Y axis fromm.floatRetrieves the scaling factor on the Z axis inm.floatRetrieves the translation component on the Z axis fromm.initFrom2d(double xx, double yx, double xy, double yy, double x0, double y0) Initializes agraphene_matrix_tfrom the values of an affine transformation matrix.initFromFloat(@org.jspecify.annotations.Nullable float @Nullable [] v) Initializes agraphene_matrix_twith the given array of floating point values.initFromMatrix(Matrix src) Initializes agraphene_matrix_tusing the values of the given matrix.initFromVec4(Vec4 v0, Vec4 v1, Vec4 v2, Vec4 v3) Initializes agraphene_matrix_twith the given four row vectors.initFrustum(float left, float right, float bottom, float top, float zNear, float zFar) Initializes agraphene_matrix_tcompatible withgraphene_frustum_t.Initializes agraphene_matrix_twith the identity matrix.initLookAt(Vec3 eye, Vec3 center, Vec3 up) Initializes agraphene_matrix_tso that it positions the "camera" at the giveneyecoordinates towards an object at thecentercoordinates.initOrtho(float left, float right, float top, float bottom, float zNear, float zFar) Initializes agraphene_matrix_twith an orthographic projection.initPerspective(float fovy, float aspect, float zNear, float zFar) Initializes agraphene_matrix_twith a perspective projection.initRotate(float angle, Vec3 axis) Initializes this Matrix to represent a rotation ofangledegrees on the axis represented by theaxisvector.initScale(float x, float y, float z) Initializes agraphene_matrix_twith the given scaling factors.initSkew(float xSkew, float ySkew) Initializes agraphene_matrix_twith a skew transformation with the given factors.Initializes agraphene_matrix_twith a translation to the given coordinates.voidinterpolate(Matrix b, double factor, Matrix res) Linearly interpolates the two givengraphene_matrix_tby interpolating the decomposed transformations separately.booleanInverts the given matrix.booleanis2d()Checks whether the givengraphene_matrix_tis compatible with an a 2D affine transformation matrix.booleanChecks whether agraphene_matrix_thas a visible back face.booleanChecks whether the givengraphene_matrix_tis the identity matrix.booleanChecks whether a matrix is singular.voidMultiplies twographene_matrix_t.booleanCompares the two givengraphene_matrix_tmatrices and checks whether their values are within the givenepsilonof each other.voidNormalizes the givengraphene_matrix_t.voidperspective(float depth, Matrix res) Applies a perspective ofdepthto the matrix.voidprint()Prints the contents of a matrix to the standard error stream.voidprojectPoint(Point p, Point res) Projects agraphene_point_tusing the matrixm.voidprojectRect(Rect r, Quad res) Projects all corners of agraphene_rect_tusing the given matrix.voidprojectRectBounds(Rect r, Rect res) Projects agraphene_rect_tusing the given matrix.@Nullable Simd4X4FRead the value of the fieldvalue.voidAdds a rotation transformation tom,using the givenangleandaxisvector.voidrotateEuler(Euler e) Adds a rotation transformation tom,using the givengraphene_euler_t.voidAdds a rotation transformation tom,using the givengraphene_quaternion_t.voidrotateX(float angle) Adds a rotation transformation around the X axis tom,using the givenangle.voidrotateY(float angle) Adds a rotation transformation around the Y axis tom,using the givenangle.voidrotateZ(float angle) Adds a rotation transformation around the Z axis tom,using the givenangle.voidscale(float factorX, float factorY, float factorZ) Adds a scaling transformation tom,using the three given factors.voidskewXy(float factor) Adds a skew offactoron the X and Y axis to the given matrix.voidskewXz(float factor) Adds a skew offactoron the X and Z axis to the given matrix.voidskewYz(float factor) Adds a skew offactoron the Y and Z axis to the given matrix.booleanto2d(Out<Double> xx, Out<Double> yx, Out<Double> xy, Out<Double> yy, Out<Double> x0, Out<Double> y0) Converts agraphene_matrix_tto an affine transformation matrix, if the given matrix is compatible.voidConverts agraphene_matrix_tto an array of floating point values.voidtransformBounds(Rect r, Rect res) Transforms each corner of agraphene_rect_tusing the given matrixm.voidtransformBox(Box b, Box res) Transforms the vertices of agraphene_box_tusing the given matrixm.voidtransformPoint(Point p, Point res) Transforms the givengraphene_point_tusing the matrixm.voidtransformPoint3d(Point3D p, Point3D res) Transforms the givengraphene_point3d_tusing the matrixm.voidtransformRay(Ray r, Ray res) Transform agraphene_ray_tusing the given matrixm.voidtransformRect(Rect r, Quad res) Transforms each corner of agraphene_rect_tusing the given matrixm.voidtransformSphere(Sphere s, Sphere res) Transforms agraphene_sphere_tusing the given matrixm.The result is the bounding sphere containing the transformed sphere.voidtransformVec3(Vec3 v, Vec3 res) Transforms the givengraphene_vec3_tusing the matrixm.voidtransformVec4(Vec4 v, Vec4 res) Transforms the givengraphene_vec4_tusing the matrixm.voidAdds a translation transformation to this Matrix using the coordinates of the givengraphene_point3d_t.voidTransposes the given matrix.voidunprojectPoint3d(Matrix modelview, Point3D point, Point3D res) Unprojects the givenpointusing the this Matrix matrix and amodelviewmatrix.voiduntransformBounds(Rect r, Rect bounds, Rect res) Undoes the transformation on the corners of agraphene_rect_tusing the given matrix, within the given axis aligned rectangularbounds.booleanuntransformPoint(Point p, Rect bounds, Point res) Undoes the transformation of agraphene_point_tusing the given matrix, within the given axis aligned rectangularbounds.voidwriteValue(@Nullable Simd4X4F value) Write a value in the fieldvalue.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Matrix
Create a Matrix proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Matrix
Allocate a new Matrix.- Parameters:
arena- to control the memory allocation scope
-
Matrix
public Matrix()Allocate a new Matrix. The memory is allocated withArena.ofAuto(). -
Matrix
-
Matrix
Allocate a new Matrix with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
value- value for the fieldvalue
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readValue
Read the value of the fieldvalue.- Returns:
- The value of the field
value
-
writeValue
Write a value in the fieldvalue.- Parameters:
value- The new value for the fieldvalue
-
alloc
Allocates a newgraphene_matrix_t.- Returns:
- the newly allocated matrix
- Since:
- 1.0
-
decompose
public boolean decompose(Vec3 translate, Vec3 scale, Quaternion rotate, Vec3 shear, Vec4 perspective) Decomposes a transformation matrix into its component transformations.The algorithm for decomposing a matrix is taken from the CSS3 Transforms specification; specifically, the decomposition code is based on the equivalent code published in "Graphics Gems II", edited by Jim Arvo, and available online.
- Parameters:
translate- the translation vectorscale- the scale vectorrotate- the rotation quaternionshear- the shear vectorperspective- the perspective vector- Returns:
trueif the matrix could be decomposed
-
determinant
public float determinant()Computes the determinant of the given matrix.- Returns:
- the value of the determinant
- Since:
- 1.0
-
equal
Checks whether the two givengraphene_matrix_tmatrices are equal.- Parameters:
b- agraphene_matrix_t- Returns:
trueif the two matrices are equal, andfalseotherwise- Since:
- 1.10
-
equalFast
Checks whether the two givengraphene_matrix_tmatrices 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:
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- agraphene_matrix_t- Returns:
trueif the matrices are equal. andfalseotherwise- Since:
- 1.10
-
free
public void free()Frees the resources allocated by graphene_matrix_alloc().- Since:
- 1.0
-
getRow
Retrieves the given row vector atindexinside a matrix.- Parameters:
index- the index of the row vector, between 0 and 3res- return location for thegraphene_vec4_tthat is used to store the row vector- Since:
- 1.0
-
getValue
public float getValue(int row, int col) Retrieves the value at the givenrowandcolindex.- Parameters:
row- the row indexcol- the column index- Returns:
- the value at the given indices
- Since:
- 1.0
-
getXScale
public float getXScale()Retrieves the scaling factor on the X axis inm.- Returns:
- the value of the scaling factor
- Since:
- 1.0
-
getXTranslation
public float getXTranslation()Retrieves the translation component on the X axis fromm.- Returns:
- the translation component
- Since:
- 1.10
-
getYScale
public float getYScale()Retrieves the scaling factor on the Y axis inm.- Returns:
- the value of the scaling factor
- Since:
- 1.0
-
getYTranslation
public float getYTranslation()Retrieves the translation component on the Y axis fromm.- Returns:
- the translation component
- Since:
- 1.10
-
getZScale
public float getZScale()Retrieves the scaling factor on the Z axis inm.- Returns:
- the value of the scaling factor
- Since:
- 1.0
-
getZTranslation
public float getZTranslation()Retrieves the translation component on the Z axis fromm.- Returns:
- the translation component
- Since:
- 1.10
-
initFrom2d
Initializes agraphene_matrix_tfrom the values of an affine transformation matrix.The arguments map to the following matrix layout:
⎛ 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 memberx0- the x0 membery0- the y0 member- Returns:
- the initialized matrix
- Since:
- 1.0
-
initFromFloat
Initializes agraphene_matrix_twith the given array of floating point values.- Parameters:
v- an array of at least 16 floating point values- Returns:
- the initialized matrix
- Throws:
IllegalArgumentException- when length ofvis less than 16- Since:
- 1.0
-
initFromMatrix
-
initFromVec4
-
initFrustum
public Matrix initFrustum(float left, float right, float bottom, float top, float zNear, float zFar) Initializes agraphene_matrix_tcompatible withgraphene_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 planezNear- distance of the near clipping planezFar- distance of the far clipping plane- Returns:
- the initialized matrix
- Since:
- 1.2
-
initIdentity
Initializes agraphene_matrix_twith the identity matrix.- Returns:
- the initialized matrix
- Since:
- 1.0
-
initLookAt
Initializes agraphene_matrix_tso that it positions the "camera" at the giveneyecoordinates towards an object at thecentercoordinates. The top of the camera is aligned to the direction of theupvector.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 this Matrix to transform a model of such a camera into world-space. However, it is more common to use the inverse of this Matrix 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
- Since:
- 1.0
-
initOrtho
Initializes agraphene_matrix_twith 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 planezNear- the distance of the near clipping planezFar- the distance of the far clipping plane- Returns:
- the initialized matrix
- Since:
- 1.0
-
initPerspective
Initializes agraphene_matrix_twith a perspective projection.- Parameters:
fovy- the field of view angle, in degreesaspect- the aspect valuezNear- the near Z planezFar- the far Z plane- Returns:
- the initialized matrix
- Since:
- 1.0
-
initRotate
-
initScale
Initializes agraphene_matrix_twith 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
- Since:
- 1.0
-
initSkew
Initializes agraphene_matrix_twith a skew transformation with the given factors.- Parameters:
xSkew- skew factor, in radians, on the X axisySkew- skew factor, in radians, on the Y axis- Returns:
- the initialized matrix
- Since:
- 1.0
-
initTranslate
-
interpolate
Linearly interpolates the two givengraphene_matrix_tby 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- agraphene_matrix_tfactor- the linear interpolation factorres- return location for the interpolated matrix- Since:
- 1.0
-
inverse
Inverts the given matrix.- Parameters:
res- return location for the inverse matrix- Returns:
trueif the matrix is invertible- Since:
- 1.0
-
is2d
public boolean is2d()Checks whether the givengraphene_matrix_tis compatible with an a 2D affine transformation matrix.- Returns:
trueif the matrix is compatible with an affine transformation matrix- Since:
- 1.0
-
isBackfaceVisible
public boolean isBackfaceVisible()Checks whether agraphene_matrix_thas a visible back face.- Returns:
trueif the back face of the matrix is visible- Since:
- 1.0
-
isIdentity
public boolean isIdentity()Checks whether the givengraphene_matrix_tis the identity matrix.- Returns:
trueif the matrix is the identity matrix- Since:
- 1.0
-
isSingular
public boolean isSingular()Checks whether a matrix is singular.- Returns:
trueif the matrix is singular- Since:
- 1.0
-
multiply
Multiplies twographene_matrix_t.Matrix multiplication is not commutative in general; the order of the factors matters. The product of this multiplication is (this Matrix ×
b)- Parameters:
b- agraphene_matrix_tres- return location for the matrix result- Since:
- 1.0
-
near
Compares the two givengraphene_matrix_tmatrices and checks whether their values are within the givenepsilonof each other.- Parameters:
b- agraphene_matrix_tepsilon- the threshold between the two matrices- Returns:
trueif the two matrices are near each other, andfalseotherwise- Since:
- 1.10
-
normalize
Normalizes the givengraphene_matrix_t.- Parameters:
res- return location for the normalized matrix- Since:
- 1.0
-
perspective
Applies a perspective ofdepthto the matrix.- Parameters:
depth- the depth of the perspectiveres- return location for the perspective matrix- Since:
- 1.0
-
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.
- Since:
- 1.0
-
projectPoint
-
projectRect
-
projectRectBounds
Projects agraphene_rect_tusing the given matrix.The resulting rectangle is the axis aligned bounding rectangle capable of fully containing the projected rectangle.
- Parameters:
r- agraphene_rect_tres- return location for the projected rectangle- Since:
- 1.0
-
rotate
Adds a rotation transformation tom,using the givenangleandaxisvector.This is the equivalent of calling graphene_matrix_init_rotate() and then multiplying the matrix this Matrix with the rotation matrix.
- Parameters:
angle- the rotation angle, in degreesaxis- the rotation axis, as agraphene_vec3_t- Since:
- 1.0
-
rotateEuler
Adds a rotation transformation tom,using the givengraphene_euler_t.- Parameters:
e- a rotation described by agraphene_euler_t- Since:
- 1.2
-
rotateQuaternion
Adds a rotation transformation tom,using the givengraphene_quaternion_t.This is the equivalent of calling graphene_quaternion_to_matrix() and then multiplying this Matrix with the rotation matrix.
- Parameters:
q- a rotation described by agraphene_quaternion_t- Since:
- 1.2
-
rotateX
public void rotateX(float angle) Adds a rotation transformation around the X axis tom,using the givenangle.See also: graphene_matrix_rotate()
- Parameters:
angle- the rotation angle, in degrees- Since:
- 1.0
-
rotateY
public void rotateY(float angle) Adds a rotation transformation around the Y axis tom,using the givenangle.See also: graphene_matrix_rotate()
- Parameters:
angle- the rotation angle, in degrees- Since:
- 1.0
-
rotateZ
public void rotateZ(float angle) Adds a rotation transformation around the Z axis tom,using the givenangle.See also: graphene_matrix_rotate()
- Parameters:
angle- the rotation angle, in degrees- Since:
- 1.0
-
scale
public void scale(float factorX, float factorY, float factorZ) Adds a scaling transformation tom,using the three given factors.This is the equivalent of calling graphene_matrix_init_scale() and then multiplying the matrix this Matrix with the scale matrix.
- Parameters:
factorX- scaling factor on the X axisfactorY- scaling factor on the Y axisfactorZ- scaling factor on the Z axis- Since:
- 1.0
-
skewXy
public void skewXy(float factor) Adds a skew offactoron the X and Y axis to the given matrix.- Parameters:
factor- skew factor- Since:
- 1.0
-
skewXz
public void skewXz(float factor) Adds a skew offactoron the X and Z axis to the given matrix.- Parameters:
factor- skew factor- Since:
- 1.0
-
skewYz
public void skewYz(float factor) Adds a skew offactoron the Y and Z axis to the given matrix.- Parameters:
factor- skew factor- Since:
- 1.0
-
to2d
public boolean to2d(Out<Double> xx, Out<Double> yx, Out<Double> xy, Out<Double> yy, Out<Double> x0, Out<Double> y0) Converts agraphene_matrix_tto an affine transformation matrix, if the given matrix is compatible.The returned values have the following layout:
⎛ xx yx ⎞ ⎛ a b 0 ⎞ ⎜ xy yy ⎟ = ⎜ c d 0 ⎟ ⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠This function can be used to convert between a
graphene_matrix_tand an affine matrix type from other libraries.- Parameters:
xx- return location for the xx memberyx- return location for the yx memberxy- return location for the xy memberyy- return location for the yy memberx0- return location for the x0 membery0- return location for the y0 member- Returns:
trueif the matrix is compatible with an affine transformation matrix- Since:
- 1.0
-
toFloat
Converts agraphene_matrix_tto 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.- Since:
- 1.0
-
transformBounds
Transforms each corner of agraphene_rect_tusing the given matrixm.The result is the axis aligned bounding rectangle containing the coplanar quadrilateral.
See also: graphene_matrix_transform_point()
- Parameters:
r- agraphene_rect_tres- return location for the bounds of the transformed rectangle- Since:
- 1.0
-
transformBox
-
transformPoint
Transforms the givengraphene_point_tusing the matrixm.Unlike graphene_matrix_transform_vec3(), this function will take into account the fourth row vector of the
graphene_matrix_twhen computing the dot product of each row vector of the matrix.See also: graphene_simd4x4f_point3_mul()
- Parameters:
p- agraphene_point_tres- return location for the transformedgraphene_point_t- Since:
- 1.0
-
transformPoint3d
Transforms the givengraphene_point3d_tusing the matrixm.Unlike graphene_matrix_transform_vec3(), this function will take into account the fourth row vector of the
graphene_matrix_twhen computing the dot product of each row vector of the matrix.See also: graphene_simd4x4f_point3_mul()
- Parameters:
p- agraphene_point3d_tres- return location for the result- Since:
- 1.2
-
transformRay
-
transformRect
-
transformSphere
-
transformVec3
Transforms the givengraphene_vec3_tusing the matrixm.This function will multiply the X, Y, and Z row vectors of the matrix this Matrix with the corresponding components of the vector
v.The W row vector will be ignored.See also: graphene_simd4x4f_vec3_mul()
- Parameters:
v- agraphene_vec3_tres- return location for agraphene_vec3_t- Since:
- 1.0
-
transformVec4
-
translate
Adds a translation transformation to this Matrix using the coordinates of the givengraphene_point3d_t.This is the equivalent of calling graphene_matrix_init_translate() and then multiplying this Matrix with the translation matrix.
- Parameters:
pos- agraphene_point3d_t- Since:
- 1.0
-
transpose
Transposes the given matrix.- Parameters:
res- return location for the transposed matrix- Since:
- 1.0
-
unprojectPoint3d
Unprojects the givenpointusing the this Matrix matrix and amodelviewmatrix.- Parameters:
modelview- agraphene_matrix_tfor the modelview matrix; this is the inverse of the modelview used when projecting the pointpoint- agraphene_point3d_twith the coordinates of the pointres- return location for the unprojected point- Since:
- 1.2
-
untransformBounds
Undoes the transformation on the corners of agraphene_rect_tusing the given matrix, within the given axis aligned rectangularbounds.- Parameters:
r- agraphene_rect_tbounds- the bounds of the transformationres- return location for the untransformed rectangle- Since:
- 1.0
-
untransformPoint
Undoes the transformation of agraphene_point_tusing the given matrix, within the given axis aligned rectangularbounds.- Parameters:
p- agraphene_point_tbounds- the bounds of the transformationres- return location for the untransformed point- Returns:
trueif the point was successfully untransformed- Since:
- 1.0
-