Skip to content

Transformations

Overview

Drawables and AR primitives support matrix-based transformations for precise positioning, rotation, and scaling.

The SDK provides two levels of transform support:

Interface Matrix Used By
IM2Transformable3x3 3x3 (2D) M2RectTexture (M2Image, M2Texture, M2SpriteImage), M2HudGeometry (M2Triangles, M2Strip, M2Fan), M2Segment (M2Line, M2Path)
IM2Transformable4x4 4x4 (3D) M2ArGeometry (M2ArMesh, M2ArLines, M2ArPoints)

2D Transforms (HUD Drawables)

HUD drawables that implement IM2Transformable3x3 support 2D affine transforms:

// Apply a 2D transform matrix to an image
val image = M2Image()
image.setResource(myImageResource)

val matrix = M2TransformMatrix()
matrix.translate(dx = 10f, dy = 20f)
matrix.rotate(angleDegrees = 45f)
matrix.scale(sx = 1.5f, sy = 1.5f)

image.setTransformMatrix(matrix)

Transform matrices can be animated using the matrix animator types:

  • AnimatorType.MatrixDx, AnimatorType.MatrixDy - translation
  • AnimatorType.MatrixRz - rotation (2D)
  • AnimatorType.MatrixScale - uniform scale

3D Transforms (AR Drawables)

AR geometry (M2ArGeometry subclasses) uses full 4x4 transforms for 3D positioning:

val mesh = M2ArMesh(vertices, indices)

// Translate in world space (ENU)
mesh.translate(east = 1.0f, north = 0.0f, up = 0.5f)

// Rotate around the object's own position
mesh.rotateLocal(angleDegrees = 90f, axis = floatArrayOf(0f, 0f, 1f))

// Rotate around the world origin
mesh.rotateWorld(angleDegrees = 45f, axis = floatArrayOf(0f, 1f, 0f))

// Scale uniformly
mesh.scale(factor = 2.0f)

3D transforms can be animated using:

  • AnimatorType.WorldVecX, AnimatorType.WorldVecY, AnimatorType.WorldVecZ - world position
  • AnimatorType.MatrixDx, AnimatorType.MatrixDy, AnimatorType.MatrixDz - matrix translation
  • AnimatorType.MatrixRx, AnimatorType.MatrixRy, AnimatorType.MatrixRz - matrix rotation
  • AnimatorType.MatrixScale - matrix scale

Which Drawables Support Transforms?

Not all drawables support matrix transforms. Drawables that implement IM2Transformable3x3 or IM2Transformable4x4 support transforms.

Use transform updates together with animators for smooth motion.


See Also