I calculate the camera position of a SCNScene
that is rendered in Vuforia. However the object is not staying fixed on the marker but jumping around when moving. The cube in the scene appears only orthographically, no matter how the device is moved around the sides cannot be seen.
The camera position is calculated with every frame:
// Get model view matrix
Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose());
// Convert to extrinsic matrix
SCNMatrix4 extrinsic = [self SCNMatrix4FromVuforiaMatrix44: modelViewMatrix];
SCNMatrix4 inverted = SCNMatrix4Invert(extrinsic);
// Set new position of SCNCamera
cameraNode.transform = inverted;
The camera projection matrix is calculated when the camera is stared:
// Get device camera calibration
const Vuforia::CameraCalibration& cameraCalibration = Vuforia::CameraDevice::getInstance().getCameraCalibration();
projectionGLMatrix = Vuforia::Tool::getProjectionGL(cameraCalibration, 2.0f, 5000.0f);
// Convert matrix
GLKMatrix4 glkMatrix;
for(int i=0; i<16; i++) {
glkMatrix.m[i] = projectionGLMatrix.data[i];
}
// Convert matrix
SCNMatrix4 projectionTransform = SCNMatrix4FromGLKMatrix4(glkMatrix);
cameraNode.camera.projectionTransform = projectionTransform;
What am I doing wrong here?
Update 1
The projection matrix is now calculated like this, when the camera starts:
const Vuforia::CameraCalibration& cameraCalibration = Vuforia::CameraDevice::getInstance().getCameraCalibration();
Vuforia::Matrix44F vuforiaMatrix = Vuforia::Tool::getProjectionGL(cameraCalibration, 2.0f, 5000.0f);
matrix_float4x4 simdMatrix = simdMatrixWithVuforiaMatrix44F(vuforiaMatrix);
cameraNode.camera.projectionTransform = SCNMatrix4FromMat4(simdMatrix);
The camera position is updated with every frame:
Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose());
matrix_float4x4 simdMatrix = simdMatrixWithVuforiaMatrix44F(modelViewMatrix);
cameraNode.transform = SCNMatrix4FromMat4(simdMatrix);
NSLog(@"camera position: x%lf, y%lf, z%lf, rotation: x%lf, y%lf, z%lf", _cameraNode.position.x, _cameraNode.position.y, _cameraNode.position.z, _cameraNode.rotation.x, _cameraNode.rotation.y, _cameraNode.rotation.z);
By moving the device and observing the logging of the camera position (left graph) and rotation (right graph) it seems that the axes are:
The axes for rotation are different from position axes. Also a rotation around the remaining axis (untitled in the graph below) does not have any influence on the cameraNode.rotation.x value which floats around 0.999.
What is wrong here?