Package snap.gfx3d
Class Matrix3D
java.lang.Object
snap.gfx3d.Matrix3D
- All Implemented Interfaces:
Cloneable
This class represents a 3D transform.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Standard clone implementation.final Matrix3D
fromArray
(double[] mat2) Loads the transform from a double array.final Matrix3D
invert()
Invert.Multiplies receiver by given transform: [this] = [this] x [aTrans]static Matrix3D
newOrtho
(double left, double right, double bottom, double top, double nearZ, double farZ) Returns a orthographic transform.static Matrix3D
newPerspective
(double d) Returns a simple perspective transform.static Matrix3D
newPerspective
(double fieldOfViewY, double aspect, double nearZ, double farZ) Returns a perspective transform.premultiply
(Matrix3D aTransform) Multiplies receiver by given transform: [this] = [aTrans] x [this]rotateAboutAxis
(double anAngle, double aX, double aY, double aZ) Rotate about arbitrary axis.rotateX
(double anAngle) Rotate x axis by given degrees.rotateXYZ
(double rx, double ry, double rz) Rotate x,y,z with three Euler angles (same as rotateX(rx).rotateY(ry).rotateZ(rz)).rotateY
(double anAngle) Rotate y axis by given degrees.rotateZ
(double anAngle) Rotate z axis by given degrees.scale
(double aSX, double aSY, double aSZ) Skew by the given degrees.final double[]
toArray()
Returns a double array for the transform.final double[]
toArray
(double[] anArray) Returns a double array for the transform.toString()
Standard toString implementation.final Point3D
transformPoint
(Point3D aPoint) Transforms a given point (and returns it as a convenience).final Vector3D
transformVector
(Vector3D aVector) Transforms a given vector (and returns it as a convenience).final Vector3D
transformVectorXYZ
(double vx, double vy, double vz) Transforms a given vector (and returns it as a convenience).final Point3D
transformXYZ
(double aX, double aY, double aZ) Transforms a given point (and returns it as a convenience).final void
transformXYZArray
(float[] pointsArray, int aPointCount) Transforms a given point (and returns it as a convenience).translate
(double x, double y, double z) Translates by given x, y & z.
-
Field Details
-
mtx
public double[] mtx -
IDENTITY
-
-
Constructor Details
-
Matrix3D
public Matrix3D()Constructor (creates identity). -
Matrix3D
public Matrix3D(double[] theDoubles) Constructor (creates identity). -
Matrix3D
public Matrix3D(double aX, double aY, double aZ) Constructor with given translations.
-
-
Method Details
-
multiply
Multiplies receiver by given transform: [this] = [this] x [aTrans] -
premultiply
Multiplies receiver by given transform: [this] = [aTrans] x [this] -
translate
Translates by given x, y & z. -
rotateX
Rotate x axis by given degrees. -
rotateY
Rotate y axis by given degrees. -
rotateZ
Rotate z axis by given degrees. -
rotateAboutAxis
Rotate about arbitrary axis. -
rotateXYZ
Rotate x,y,z with three Euler angles (same as rotateX(rx).rotateY(ry).rotateZ(rz)). -
scale
Skew by the given degrees. -
invert
Invert. -
transformPoint
Transforms a given point (and returns it as a convenience). This pre-multiplies OpenGL style: [ P' ] = [ Matrix ] x [ P ] 3 x 1 3 x 3 3 x 1 3 x 1 [ px' ] [ m00 m10 m20 m30 ] [ px ] [ m00 * px + m10 * py + m20 * pz + m30, [ py' ] = [ m01 m11 m21 m31 ] x [ py ] = m01 * px + m11 * py + m21 * pz + m31, [ pz' ] [ m02 m12 m22 m32 ] [ pz ] m02 * px + m12 * py + m22 * pz + m32, [ w ] [ m03 m13 m23 m33 ] [ 1 ] m03 * px + m13 * py + m23 * pz + m33 (w) ] JOML looks like this: double W = Math.fma(mat.m03(), x, Math.fma(mat.m13(), y, Math.fma(mat.m23(), z, mat.m33() * w))); double rx = Math.fma(mat.m00(), x, Math.fma(mat.m10(), y, Math.fma(mat.m20(), z, mat.m30() * w))) / W; double ry = Math.fma(mat.m01(), x, Math.fma(mat.m11(), y, Math.fma(mat.m21(), z, mat.m31() * w))) / W; double rz = Math.fma(mat.m02(), x, Math.fma(mat.m12(), y, Math.fma(mat.m22(), z, mat.m32() * w))) / W; -
transformXYZ
Transforms a given point (and returns it as a convenience). -
transformXYZArray
public final void transformXYZArray(float[] pointsArray, int aPointCount) Transforms a given point (and returns it as a convenience). -
transformVector
Transforms a given vector (and returns it as a convenience). -
transformVectorXYZ
Transforms a given vector (and returns it as a convenience). -
toArray
public final double[] toArray()Returns a double array for the transform. -
toArray
public final double[] toArray(double[] anArray) Returns a double array for the transform. -
fromArray
Loads the transform from a double array. -
clone
Standard clone implementation. -
toString
Standard toString implementation. -
newPerspective
Returns a simple perspective transform. -
newPerspective
public static Matrix3D newPerspective(double fieldOfViewY, double aspect, double nearZ, double farZ) Returns a perspective transform. [ f / aspect 0 0 0 ] [ px ] [ 0 f 0 0 ] x [ py ] [ 0 0 (far + near) / (near - far) 2 * far * near / (near - far) ] [ pz ] [ 0 0 -1 0 ] [ w ] -
newOrtho
public static Matrix3D newOrtho(double left, double right, double bottom, double top, double nearZ, double farZ) Returns a orthographic transform. [ 2 / (r - l) 0 0 tx ] [ px ] [ 0 2 / (t - b) 0 ty ] x [ py ] [ 0 0 -2 / (far - near) tz ] [ pz ] [ 0 0 -1 0 ] [ w ]
-