Class ARPose

java.lang.Object
com.codename1.ar.ARPose

public final class ARPose extends Object

An immutable rigid transform - a rotation followed by a translation - that positions something in AR world space. Poses use the AR coordinate convention shared by ARKit and ARCore: units are meters, the coordinate system is right-handed with Y pointing up and -Z pointing forward from the initial camera direction.

The rotation is stored as a unit quaternion (qx, qy, qz, qw) compatible with com.codename1.gpu.Quaternion; the translation is (tx, ty, tz). toMatrix(float[]) produces the equivalent column-major 4x4 matrix, ready for com.codename1.gpu.Matrix4 math.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ARPose
    The identity pose: no rotation, located at the world origin.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ARPose(float tx, float ty, float tz, float qx, float qy, float qz, float qw)
    Creates a pose from a translation and a rotation quaternion.
  • Method Summary

    Modifier and Type
    Method
    Description
    static ARPose
    fromMatrix(float[] m16)
    Extracts a pose from a column-major 4x4 transform matrix whose upper left 3x3 is a pure rotation (no scale or shear).
    float
    The W component of the rotation quaternion.
    float
    The X component of the rotation quaternion.
    float
    The Y component of the rotation quaternion.
    float
    The Z component of the rotation quaternion.
    float
    The X component of the translation in meters.
    float
    The Y component of the translation in meters.
    float
    The Z component of the translation in meters.
    float[]
    Returns this pose as a newly allocated column-major 4x4 transform matrix.
    void
    toMatrix(float[] out16)
    Writes this pose as a column-major 4x4 transform matrix into out16, compatible with com.codename1.gpu.Matrix4.
    Returns a string representation of the object.
    Composes this pose with a pose expressed in this pose's local frame, returning this * local.
    void
    transformPoint(float[] xyzInOut)
    Transforms the point stored in xyzInOut (3 floats) from this pose's local frame to the frame this pose is expressed in, writing the result back in place.

    Methods inherited from class Object

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

    • IDENTITY

      public static final ARPose IDENTITY
      The identity pose: no rotation, located at the world origin.
  • Constructor Details

    • ARPose

      public ARPose(float tx, float ty, float tz, float qx, float qy, float qz, float qw)

      Creates a pose from a translation and a rotation quaternion. The quaternion is normalized defensively; a zero quaternion becomes the identity rotation.

      Parameters
      • tx, ty, tz: the translation in meters

      • qx, qy, qz, qw: the rotation quaternion

  • Method Details

    • fromMatrix

      public static ARPose fromMatrix(float[] m16)

      Extracts a pose from a column-major 4x4 transform matrix whose upper left 3x3 is a pure rotation (no scale or shear).

      Parameters
      • m16: the column-major matrix, 16 floats
      Returns

      the equivalent pose

    • getTx

      public float getTx()
      The X component of the translation in meters.
    • getTy

      public float getTy()
      The Y component of the translation in meters.
    • getTz

      public float getTz()
      The Z component of the translation in meters.
    • getQx

      public float getQx()
      The X component of the rotation quaternion.
    • getQy

      public float getQy()
      The Y component of the rotation quaternion.
    • getQz

      public float getQz()
      The Z component of the rotation quaternion.
    • getQw

      public float getQw()
      The W component of the rotation quaternion.
    • toMatrix

      public void toMatrix(float[] out16)

      Writes this pose as a column-major 4x4 transform matrix into out16, compatible with com.codename1.gpu.Matrix4.

      Parameters
      • out16: the destination array, 16 floats
    • toMatrix

      public float[] toMatrix()
      Returns this pose as a newly allocated column-major 4x4 transform matrix.
    • transform

      public ARPose transform(ARPose local)

      Composes this pose with a pose expressed in this pose's local frame, returning this * local. Use it to convert an offset relative to an anchor into world space.

      Parameters
      • local: the pose in this pose's local coordinate frame
      Returns

      the composed pose in the frame this pose is expressed in

    • transformPoint

      public void transformPoint(float[] xyzInOut)

      Transforms the point stored in xyzInOut (3 floats) from this pose's local frame to the frame this pose is expressed in, writing the result back in place.

      Parameters
      • xyzInOut: the point to transform, modified in place
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object