API reference
API reference
Select your platform
No SDKs available
No versions available

TransformerUtils Class

Contains a variety of static methods for specialized utility purposes, along with related child structures and classes.
The static methods constrain a 3D data in a variety of ways, or encapsulate highly specific arithmetic operations.
These functions are not general; they are used by various ITransformer implementations, and the degree to which each function is tightly coupled to the conventions and assumptions of its usage varies. For that reason, you should avoid leveraging these directly; only add new usage if copy-pasting from existing usages, and use the existing implementation as a guide to understand how to use each of these correctly.

Static Methods

AlignLocalToWorldPose ( localToWorld , local , world )
This is an old utility method, new uses of which should be avoided.
For homogeneous transform arithmetic, just use Unity's built-in Transform and matrix math support.
The naming and use of Pose representation in this implementation can be confusing, so this explanation will avoid them and map back at the end. Conceptually, there are three things: a scaled transform T in world space, an unscaled transform A in T space, and an unscaled transform B in world space. The goal is to find a scaled transform T' (sharing the scale of T) such that an unmodified A in T' equals B when mapped to world space; colloquially, "find where we need to move T to so that A and B are on top of one another." Mathematically, this means the relationship between T' and B is the same as the relationship between T and A; thus, if we find T in the space of A (or, more precisely, A as a scaled transform in world space), we can use that same relationship with B to find T'. This gives us the following arithmetic (treating each transform as a "local to world" matrix): given T, A, and B A_inWorldSpace := T * A T_inASpace := inverse(A_inWorldSpace) * T T' := b * T_inASpace
Mapping this back to the variables and assumptions of this implementation, localToWorld is T, local is A, and world is B. The fact that the result T' is a scaled transform is not reflected in the return value of this extension and is instead implicit in its usage. The position and rotation of the returned Pose must be assigned directly to the corresponding fields of the Transform which provided localToWorld, without modifying the scale of that Transform; any other usage may not yield the desired alignment.
Signature
static Pose Oculus.Interaction.TransformerUtils.AlignLocalToWorldPose(Matrix4x4 localToWorld, Pose local, Pose world)
Parameters
localToWorld: Matrix4x4  T (see remarks for details).
local: Pose  A (see remarks for details).
world: Pose  B (see remarks for details).
Returns
Pose  T', excluding scale (see remarks for details).
ConstrainAlongDirection ( position , origin , direction , min , max )
Constrains a position to a certain range of positions along a line defined by position and direction minimally distant from a range of points from origin plus direction scaled by min to origin plus direction scaled by max .
This is an extremely specialized utility used only by TwoGrabPlaneTransformer.
Signature
static Vector3 Oculus.Interaction.TransformerUtils.ConstrainAlongDirection(Vector3 position, Vector3 origin, Vector3 direction, FloatConstraint min, FloatConstraint max)
Parameters
position: Vector3  The position to be constrained.
origin: Vector3  The origin of the line to which position should be projected for constraint.
direction: Vector3  The direction along which position should be constrained.
min: FloatConstraint  The minimum signed distance along the line defined by origin and direction to which the closest projection of position should be constrained.
max: FloatConstraint  The maximum signed distance along the line defined by origin and direction to which the closest projection of position should be constrained.
Returns
Vector3  The constrained position.
GenerateParentConstraints ( constraints , initialPosition )
Generates a new set of PositionConstraints based on an initialPosition .
Signature
static PositionConstraints Oculus.Interaction.TransformerUtils.GenerateParentConstraints(PositionConstraints constraints, Vector3 initialPosition)
Parameters
constraints: PositionConstraints  The PositionConstraints upon which the new constraints should be based.
initialPosition: Vector3  The initial position from which relative constraints should be relative.
Returns
PositionConstraints  New constraints which take initialPosition into account.
GenerateParentConstraints ( constraints , initialScale )
Generates a new set of ScaleConstraints based on an initialScale .
Signature
static ScaleConstraints Oculus.Interaction.TransformerUtils.GenerateParentConstraints(ScaleConstraints constraints, Vector3 initialScale)
Parameters
constraints: ScaleConstraints  The ScaleConstraints upon which the new constraints should be based.
initialScale: Vector3  The initial scale from which relative constraints should be relative.
Returns
ScaleConstraints  New constraints which take initialScale into account.
GetConstrainedTransformPosition ( unconstrainedPosition , positionConstraints , relativeTransform )
Applies a set of PositionConstraints to a vector representing the position of a Transform.
Signature
static Vector3 Oculus.Interaction.TransformerUtils.GetConstrainedTransformPosition(Vector3 unconstrainedPosition, PositionConstraints positionConstraints, Transform relativeTransform=null)
Parameters
unconstrainedPosition: Vector3  The position of the Transform before constraining.
positionConstraints: PositionConstraints  The constraints to be applied to positionConstraints .
relativeTransform: Transform  The transform to which constraint should be considered relative; if omitted, constraining will be applied relative to world space.
Returns
Vector3  A position which is as similar as possible to unconstrainedPosition but allowed by positionConstraints .
GetConstrainedTransformRotation ( unconstrainedRotation , rotationConstraints , relativeTransform )
Applies a set of RotationConstraints to a Quaternion representing the rotation of a Transform.
Signature
static Quaternion Oculus.Interaction.TransformerUtils.GetConstrainedTransformRotation(Quaternion unconstrainedRotation, RotationConstraints rotationConstraints, Transform relativeTransform=null)
Parameters
unconstrainedRotation: Quaternion  The rotation of the Transform before constraining.
rotationConstraints: RotationConstraints  The constraints to be applied to unconstrainedRotation .
relativeTransform: Transform  The transform to which constraint should be considered relative; if omitted, constraining will be applied relative to world space.
Returns
Quaternion  A rotation which is as similar as possible to unconstrainedRotation but allowed by rotationConstraints .
GetConstrainedTransformScale ( unconstrainedScale , scaleConstraints )
Applies a set of ScaleConstraints to a vector representing the scale of a Transform.
Signature
static Vector3 Oculus.Interaction.TransformerUtils.GetConstrainedTransformScale(Vector3 unconstrainedScale, ScaleConstraints scaleConstraints)
Parameters
unconstrainedScale: Vector3  The scale of the Transform before constraining.
scaleConstraints: ScaleConstraints  The constraints to be applied to unconstrainedScale .
Returns
Vector3  A scale which is as similar as possible to unconstrainedScale but allowed by scaleConstraints .
LocalToWorldMagnitude ( magnitude , localToWorld )
Calculates how large a certain magnitude in local space is in world space.
This method specifically works by approximating the scale change from the local-space Z axis. If the transform hierarchy involves skew (rotated nonuniform scales), the result may not fully describe the scale relationship between local and world space. For more information, refer to Unity's documentation for Transform.lossyScale.
Signature
static float Oculus.Interaction.TransformerUtils.LocalToWorldMagnitude(float magnitude, Matrix4x4 localToWorld)
Parameters
magnitude: float  The magnitude to be converted to world space.
localToWorld: Matrix4x4  The homogeneous transform from local to world space.
Returns
float  The magnitude in world space.
WorldToLocalMagnitude ( magnitude , worldToLocal )
Calculates how large a certain magnitude in world space is in local space.
This method specifically works by approximating the scale change from the world-space Z axis. If the transform hierarchy involves skew (rotated nonuniform scales), the result may not fully describe the scale relationship between local and world space. For more information, refer to Unity's documentation for Transform.lossyScale.
Signature
static float Oculus.Interaction.TransformerUtils.WorldToLocalMagnitude(float magnitude, Matrix4x4 worldToLocal)
Parameters
magnitude: float  The magnitude to be converted to local space.
worldToLocal: Matrix4x4
Returns
float  The magnitude in local space.
WorldToLocalPose ( worldPose , worldToLocal )
Convenience method for taking a Pose in world space (or whatever space is the domain of the transform represented by worldToLocal ) and returning its representation in local space (or whatever space is the range of worldToLocal ).
Signature
static Pose Oculus.Interaction.TransformerUtils.WorldToLocalPose(Pose worldPose, Matrix4x4 worldToLocal)
Parameters
worldPose: Pose  The Pose to be transformed.
worldToLocal: Matrix4x4  The transformation to be applied.
Returns
Pose  The image of worldPose in worldToLocal 's range.

Inner Classes

PositionConstraints Class

A collection of ConstrainedAxis constraints specifically constraining the position values of a 3D datum (typically a Transform).

Fields

ConstraintsAreRelative : bool
Indicates whether the constraints should be considered relative (i.e., applying to a Transform's local position relative to its parent Transform) or absolute (i.e., applying to a Transform's position in world space).
Signature
bool Oculus.Interaction.TransformerUtils.PositionConstraints.ConstraintsAreRelative
XAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.PositionConstraints.XAxis
YAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.PositionConstraints.YAxis
ZAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.PositionConstraints.ZAxis

RotationConstraints Class

A collection of ConstrainedAxis constraints specifically constraining the rotation values of a 3D datum (typically a Transform).
These constraints are Euler angles expressed in degrees.

Fields

XAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.RotationConstraints.XAxis
YAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.RotationConstraints.YAxis
ZAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.RotationConstraints.ZAxis

ScaleConstraints Class

A collection of ConstrainedAxis constraints specifically constraining the scale values of a 3D datum (typically a Transform).

Fields

ConstraintsAreRelative : bool
Indicates whether the constraints should be considered relative (i.e., applying to a Transform's local scale relative to its parent Transform) or absolute (i.e., applying to a Transform's scale relative to world space).
Signature
bool Oculus.Interaction.TransformerUtils.ScaleConstraints.ConstraintsAreRelative
XAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.ScaleConstraints.XAxis
YAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.ScaleConstraints.YAxis
ZAxis : ConstrainedAxis
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.ScaleConstraints.ZAxis

Inner Structs

ConstrainedAxis Struct

Struct describing a set of constraints for a one-dimensional floating point datum.
This is used to describe, store, and apply constraints to values like spatial axes (X axis, Y axis, etc.).

Fields

AxisRange : FloatRange
Indicates the FloatRange of permissible values for the datum to which this ConstrainedAxis pertains.
Signature
FloatRange Oculus.Interaction.TransformerUtils.ConstrainedAxis.AxisRange
ConstrainAxis : bool
Indicates whether the constraints described in this ConstrainedAxis should be applied.
If false, the datum to which this ConstrainedAxis pertains should be left unconstrained by this instance.
Signature
bool Oculus.Interaction.TransformerUtils.ConstrainedAxis.ConstrainAxis

Static Fields

Unconstrained : ConstrainedAxis
A default ConstrainedAxis instance which applies no constraints.
Signature
ConstrainedAxis Oculus.Interaction.TransformerUtils.ConstrainedAxis.Unconstrained

FloatRange Struct

Indicates an inclusive range of permissible values for a given floating point datum.

Fields

Max : float
Signature
float Oculus.Interaction.TransformerUtils.FloatRange.Max
Min : float
Signature
float Oculus.Interaction.TransformerUtils.FloatRange.Min