Esempio n. 1
0
        void UpdateCameraTransform()
        {
            // Update points.
            for (int p = 0; p < pointCount; p++)
            {
                Vector2 posImage = _userPointRects[p].anchorMin;
                posImage.Scale(new Vector2(_cameraTexture.width, _cameraTexture.height));
                _anchorPointsImage[p].set(new double[] { posImage.x, posImage.y });
                Vector3 posWorld = _anchorTransform.TransformPoint(defaultPointPositions[p] - Vector2.one * 0.5f);
                _anchorPointsWorld[p].set(new double[] { posWorld.x, posWorld.y, posWorld.z });
            }
            _anchorPointsImageMat.fromArray(_anchorPointsImage);
            _anchorPointsWorldMat.fromArray(_anchorPointsWorld);

            // Compute
            bool success = Calib3d.solvePnP(_anchorPointsWorldMat, _anchorPointsImageMat, _cameraMatrix, _noDistCoeffs, _rVec, _tVec);

            if (!success)
            {
                return;
            }

            // Convert.
            bool inverse = true;

            TrackingToolsHelper.ApplyPose(_rVec, _tVec, _targetCameraTransform, inverse);

            /*
             * Vector3 translation = TrackingToolsHelper.TranslationMatVectorToVector3( _tVec  );
             * Quaternion rotation = TrackingToolsHelper.RotationMatVectorToQuaternion( _rVec );
             * translation = rotation * translation;
             *
             * // Apply.
             * _targetCameraTransform.SetPositionAndRotation( translation, rotation );
             */

            // Save.
            SaveCircleAnchorPoints();
        }