Package snap.gfx3d

Class Matrix3D

java.lang.Object
snap.gfx3d.Matrix3D
All Implemented Interfaces:
Cloneable

public class Matrix3D extends Object implements Cloneable
This class represents a 3D transform.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Matrix3D
     
    double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor (creates identity).
    Matrix3D(double[] theDoubles)
    Constructor (creates identity).
    Matrix3D(double aX, double aY, double aZ)
    Constructor with given translations.
  • Method Summary

    Modifier and Type
    Method
    Description
    Standard clone implementation.
    final Matrix3D
    fromArray(double[] mat2)
    Loads the transform from a double array.
    final Matrix3D
    Invert.
    multiply(Matrix3D aTransform)
    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[]
    Returns a double array for the transform.
    final double[]
    toArray(double[] anArray)
    Returns a double array for the transform.
    Standard toString implementation.
    final Point3D
    Transforms a given point (and returns it as a convenience).
    final Vector3D
    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.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • mtx

      public double[] mtx
    • IDENTITY

      public static Matrix3D 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

      public Matrix3D multiply(Matrix3D aTransform)
      Multiplies receiver by given transform: [this] = [this] x [aTrans]
    • premultiply

      public Matrix3D premultiply(Matrix3D aTransform)
      Multiplies receiver by given transform: [this] = [aTrans] x [this]
    • translate

      public Matrix3D translate(double x, double y, double z)
      Translates by given x, y & z.
    • rotateX

      public Matrix3D rotateX(double anAngle)
      Rotate x axis by given degrees.
    • rotateY

      public Matrix3D rotateY(double anAngle)
      Rotate y axis by given degrees.
    • rotateZ

      public Matrix3D rotateZ(double anAngle)
      Rotate z axis by given degrees.
    • rotateAboutAxis

      public Matrix3D rotateAboutAxis(double anAngle, double aX, double aY, double aZ)
      Rotate about arbitrary axis.
    • rotateXYZ

      public Matrix3D rotateXYZ(double rx, double ry, double rz)
      Rotate x,y,z with three Euler angles (same as rotateX(rx).rotateY(ry).rotateZ(rz)).
    • scale

      public Matrix3D scale(double aSX, double aSY, double aSZ)
      Skew by the given degrees.
    • invert

      public final Matrix3D invert()
      Invert.
    • transformPoint

      public final Point3D transformPoint(Point3D aPoint)
      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

      public final Point3D transformXYZ(double aX, double aY, double aZ)
      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

      public final Vector3D transformVector(Vector3D aVector)
      Transforms a given vector (and returns it as a convenience).
    • transformVectorXYZ

      public final Vector3D transformVectorXYZ(double vx, double vy, double vz)
      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

      public final Matrix3D fromArray(double[] mat2)
      Loads the transform from a double array.
    • clone

      public Matrix3D clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Standard toString implementation.
      Overrides:
      toString in class Object
    • newPerspective

      public static Matrix3D newPerspective(double d)
      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 ]