Class Matrix4f
java.lang.Object
dev.prozilla.pine.common.math.matrix.Matrix4f
Represents a 4x4-Matrix. GLSL equivalent to mat4.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds this matrix to another matrix.static Matrix4f
frustum
(float left, float right, float bottom, float top, float near, float far) Creates a perspective projection matrix.multiply
(float scalar) Multiplies this matrix with a scalar.Multiplies this matrix to another matrix.Multiplies this matrix to a vector.negate()
Negates this matrix.static Matrix4f
orthographic
(float left, float right, float bottom, float top, float near, float far) Creates a orthographic projection matrix.static Matrix4f
perspective
(float fovy, float aspect, float near, float far) Creates a perspective projection matrix.static Matrix4f
rotate
(float angle, float x, float y, float z) Creates a rotation matrix.static Matrix4f
scale
(float x, float y, float z) Creates a scaling matrix.final void
Sets this matrix to the identity matrix.Subtracts this matrix from another matrix.void
toBuffer
(FloatBuffer buffer) Stores the matrix in a given Buffer.static Matrix4f
translate
(float x, float y, float z) Creates a translation matrix.Transposes this matrix.
-
Constructor Details
-
Matrix4f
public Matrix4f()Creates a 4x4 identity matrix. -
Matrix4f
Creates a 4x4 matrix with specified columns.- Parameters:
col1
- Vector with values of the first columncol2
- Vector with values of the second columncol3
- Vector with values of the third columncol4
- Vector with values of the fourth column
-
-
Method Details
-
setIdentity
public final void setIdentity()Sets this matrix to the identity matrix. -
add
Adds this matrix to another matrix.- Parameters:
other
- The other matrix- Returns:
- Sum of this + other
-
negate
Negates this matrix.- Returns:
- Negated matrix
-
subtract
Subtracts this matrix from another matrix.- Parameters:
other
- The other matrix- Returns:
- Difference of this - other
-
multiply
Multiplies this matrix with a scalar.- Parameters:
scalar
- The scalar- Returns:
- Scalar product of this * scalar
-
multiply
Multiplies this matrix to a vector.- Parameters:
vector
- The vector- Returns:
- Vector product of this * other
-
multiply
Multiplies this matrix to another matrix.- Parameters:
other
- The other matrix- Returns:
- Matrix product of this * other
-
transpose
Transposes this matrix.- Returns:
- Transposed matrix
-
toBuffer
Stores the matrix in a given Buffer.- Parameters:
buffer
- The buffer to store the matrix data
-
orthographic
public static Matrix4f orthographic(float left, float right, float bottom, float top, float near, float far) Creates a orthographic projection matrix. Similar toglOrtho(left, right, bottom, top, near, far)
.- Parameters:
left
- Coordinate for the left vertical clipping paneright
- Coordinate for the right vertical clipping panebottom
- Coordinate for the bottom horizontal clipping panetop
- Coordinate for the bottom horizontal clipping panenear
- Coordinate for the near depth clipping panefar
- Coordinate for the far depth clipping pane- Returns:
- Orthographic matrix
-
frustum
public static Matrix4f frustum(float left, float right, float bottom, float top, float near, float far) Creates a perspective projection matrix. Similar toglFrustum(left, right, bottom, top, near, far)
.- Parameters:
left
- Coordinate for the left vertical clipping paneright
- Coordinate for the right vertical clipping panebottom
- Coordinate for the bottom horizontal clipping panetop
- Coordinate for the bottom horizontal clipping panenear
- Coordinate for the near depth clipping pane, must be positivefar
- Coordinate for the far depth clipping pane, must be positive- Returns:
- Perspective matrix
-
perspective
Creates a perspective projection matrix. Similar togluPerspective(fovy, aspec, zNear, zFar)
.- Parameters:
fovy
- Field of view angle in degreesaspect
- The aspect ratio is the ratio of width to heightnear
- Distance from the viewer to the near clipping plane, must be positivefar
- Distance from the viewer to the far clipping plane, must be positive- Returns:
- Perspective matrix
-
translate
Creates a translation matrix. Similar toglTranslate(x, y, z)
.- Parameters:
x
- x coordinate of translation vectory
- y coordinate of translation vectorz
- z coordinate of translation vector- Returns:
- Translation matrix
-
rotate
Creates a rotation matrix. Similar toglRotate(angle, x, y, z)
.- Parameters:
angle
- Angle of rotation in degreesx
- x coordinate of the rotation vectory
- y coordinate of the rotation vectorz
- z coordinate of the rotation vector- Returns:
- Rotation matrix
-
scale
Creates a scaling matrix. Similar toglScale(x, y, z)
.- Parameters:
x
- Scale factor along the x coordinatey
- Scale factor along the y coordinatez
- Scale factor along the z coordinate- Returns:
- Scaling matrix
-