Log in or register to post comments

Ground Plane with SceneKit Integration

May 10, 2018 - 5:54am #1

Hello,

I am trying to use Ground Plane detection in order to render a scene using SceneKit. Unfortunately, I think I'm still a little unsure about how the matrix math should work when translated to using SceneKit. From my understanding, I should be able to get the pose from the DeviceTrackableResult and convert it to a Model View Matrix using convertPose2GLMatrix, then invert it and set that to the transform of my camera node for the scene:

if (result->isOfType(Vuforia::DeviceTrackableResult::getClassType())) {
   Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose()); // get model view
matrix
   devicePoseMatrix = VuforiaEAGLViewUtils::Matrix44FTranspose(VuforiaEAGLViewUtils::Matrix44FInverse(modelViewMatrix));
   _worldCameraNode.transform = SCNMatrix4Invert([self SCNMatrix4FromVuforiaMatrix44:modelViewMatrix]);
}

Then I perform a hit test to find where to render the reticle and transform the node representing the reticle (in the same scene):

const Vuforia::HitTestResult *result = [_manager hitTestWithNormalizedTouchPointX:0.5 andNormalizedTouchPointY:0.5 withDeviceHeightInMeters:1.4 andStateToUse:state];
if (result != nullptr) {
   Vuforia::Matrix44F poseMatrix = VuforiaEAGLViewUtils::Matrix44FIdentity();
   Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose());

   VuforiaEAGLViewUtils::multiplyMatrix(&devicePoseMatrix.data[0], &modelViewMatrix.data[0], &poseMatrix.data[0]);
   _reticleNode.transform = [self SCNMatrix4FromVuforiaMatrix44:poseMatrix];
}

Unfortunately, this didn't seem to work. Since I'm applying the device pose matrix to the camera node, I thought perhaps I don't need to do the matrix multiplication, however, removing that still didn't seem to produce proper results.

Any advice on how to proceed would be helpful!

Log in or register to post comments