Shurjo
Shurjo

Reputation: 31

What is simdTransform in SceneKit and ARKit?

In different ARKit and SceneKit projects, I see people working with simdTransform.

But I can't understand why they are using it?

And when should I use it?

Upvotes: 1

Views: 2627

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58563

In the world of 3D graphics, simdTransform 4x4 matrices is a regular way to work with translation, rotation, scaling, shearing and projection of 3D models, cameras and lights.

Here's what Apple says about simdTransform :

simdTransform is the combination of the node’s simdRotation, simdPosition, and simdScale properties. The default transform is the identity matrix.

var simdTransform: simd_float4x4 { get set }

// all these properties are parts of a simdTransform
var simdPosition: simd_float3 { get set }
var simdRotation: simd_float4 { get set }
var simdEulerAngles: simd_float3 { get set }
var simdOrientation: simd_quatf { get set }
var simdScale: simd_float3 { get set }
var simdPivot: simd_float4x4 { get set }

Here's how 4x4 identity matrix looks like:

      x  y  z
   ┌              ┐
x  |  1  0  0  0  |
y  |  0  1  0  0  |
z  |  0  0  1  0  |
   |  0  0  0  1  |
   └              ┘

...and in code:

var transform = matrix_identity_float4x4

EXAMPLE – Change a position using 4x4 matrix :

      0  1  2  3      // column index
   ┌               ┐
   |  1  0  0  tx  |
   |  0  1  0  ty  |
   |  0  0  1  tz  |
   |  0  0  0  1   |
   └               ┘

...in code:

var translation = matrix_identity_float4x4

translation.columns.3.x = 10.25
translation.columns.3.y = 20.50
translation.columns.3.z = 30.75

If you need more info on how 4x4 transformation matrix works, look at this SO post.

P.S. SIMD stands for Single Instruction, Multiple Data. You can read about it HERE.

enter image description here

Upvotes: 4

Related Questions