0

I got a simd_float4*4 matrix from ARKit. I want to check the values of the matrix but found myself do not know how to do it in Objective-C. In Swift, this can be written as matrix.columns.3 to fetch a vector of values. But I do not know how to do it in Objective-C. Could someone point me a direction please. Thanks!

Anson Yao
  • 1,544
  • 17
  • 27
  • 1
    Working with matrices from apple developer, https://developer.apple.com/documentation/accelerate/simd/working_with_matrices?language=objc – XXLIVE Dec 04 '18 at 10:22

2 Answers2

2

simd_float4x4 is a struct (like 4 simd_float4), and you can use

simd_float4x4.columns[index]

to access column in matrix.

/*! @abstract A matrix with 4 rows and 4 columns.*/
struct simd_float4x4 {
    public var columns: (simd_float4, simd_float4, simd_float4, simd_float4)
    public init()
    public init(columns: (simd_float4, simd_float4, simd_float4, simd_float4))
}

Apple document link: https://developer.apple.com/documentation/simd/simd_float4x4?language=objc

hope helpful!

XXLIVE
  • 156
  • 7
2

here's an example -- from this project, a pretty nice reference for Obj-C ARKit adventures -- https://github.com/markdaws/arkit-by-example/blob/part3/arkit-by-example/ViewController.m

- (void)insertGeometry:(ARHitTestResult *)hitResult {
  // Right now we just insert a simple cube, later we will improve these to be more
  // interesting and have better texture and shading

  float dimension = 0.1;
  SCNBox *cube = [SCNBox boxWithWidth:dimension height:dimension length:dimension chamferRadius:0];
  SCNNode *node = [SCNNode nodeWithGeometry:cube];

  // The physicsBody tells SceneKit this geometry should be manipulated by the physics engine
  node.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeDynamic shape:nil];
  node.physicsBody.mass = 2.0;
  node.physicsBody.categoryBitMask = CollisionCategoryCube;

  // We insert the geometry slightly above the point the user tapped, so that it drops onto the plane
  // using the physics engine
  float insertionYOffset = 0.5;
  node.position = SCNVector3Make(
                                 hitResult.worldTransform.columns[3].x,
                                 hitResult.worldTransform.columns[3].y + insertionYOffset,
                                 hitResult.worldTransform.columns[3].z
                                 );
  [self.sceneView.scene.rootNode addChildNode:node];
  [self.boxes addObject:node];
}