Beispiel #1
0
        void OnNewPose(MarkerPose pose)
        {
            if (pose.Id == TrackedId)
            {
                if (Invert)
                {
                    Matrix4x4 marker = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
                    Matrix4x4 cam    = marker.inverse;
                    transform.localPosition = cam.GetPosition();
                    transform.localRotation = cam.GetRotation();
                }
                else
                {
                    //transform.localPosition = pose.Position;
                    //transform.localRotation = pose.Rotation;
                    var camPos = (relativeTo == null) ? SceneCameraTracker.Instance.transform.position : relativeTo.position;
                    var camRot = (relativeTo == null) ? SceneCameraTracker.Instance.transform.rotation : relativeTo.rotation;

                    if (ApplyYOffset)
                    {
                        transform.position = camPos + camRot * pose.Position + new Vector3(0, transform.localScale.y, 0) / 2f;
                    }
                    else
                    {
                        transform.position = camPos + camRot * pose.Position;
                    }

                    transform.rotation = camRot * pose.Rotation;
                }
            }
        }
        void OnNewPose(MarkerPose pose)
        {
            if (pose.Id == TrackedId)
            {
                if (Invert)
                {
                    Matrix4x4 marker = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
                    Matrix4x4 cam = marker.inverse;
                    transform.localPosition = cam.GetPosition();
                    transform.localRotation = cam.GetRotation();
                }
                else
                {
                    //transform.localPosition = pose.Position;
                    //transform.localRotation = pose.Rotation;
                    var camPos = (relativeTo == null) ? SceneCameraTracker.Instance.transform.position : relativeTo.position;
                    var camRot = (relativeTo == null) ? SceneCameraTracker.Instance.transform.rotation : relativeTo.rotation;

                    if (ApplyYOffset)
                        transform.position = camPos + camRot * pose.Position + new Vector3(0, transform.localScale.y, 0) / 2f;
                    else
                        transform.position = camPos + camRot * pose.Position;

                    transform.rotation = camRot * pose.Rotation;
                }
            }
        }
Beispiel #3
0
 void OnNewPose(MarkerPose pose)
 {
     if (pose.Id == TrackedMarkerId)
     {
         transform.position = pose.Position;
         transform.rotation = pose.Rotation;
     }
 }
 void OnNewPose(MarkerPose pose)
 {
     if (pose.Name == TrackedMarkerName)
     {
         transform.position = pose.Position;
         transform.rotation = pose.Rotation;
     }
 }
Beispiel #5
0
        protected void OnNewPoseDetected(MarkerPose pose)
        {
            DetectedPoses[pose.Id] = pose;

            if (NewPoseDetected != null)
            {
                NewPoseDetected(pose);
            }
        }
        void OnArucoPose(MarkerPose pose)
        {
            if (pose.Id == MarkerId)
            {
                // pose is marker's pose -> inverted we get camera pose
                var markerMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
                var cameraMatrix = markerMatrix.inverse;
                var cameraLocalPos = cameraMatrix.GetPosition();
                var cameraWorldPos = transform.TransformPoint(cameraLocalPos);

                var camPose = new TimedPose
                {
                    DetectionTime = DateTime.Now,
                    CameraPose = cameraWorldPos
                };

                _savedPoses.Add(camPose);
            }
        }
        private void OnArucoPose(MarkerPose pose)
        {
            var sceneCamTransform = SceneCameraTracker.Instance.transform;
            int index = -1;

            if (pose.Id == TopLeftId)
                index = TOPLEFT;
            else if (pose.Id == BottomRightId)
                index = BOTTOMRIGHT;
            else if (pose.Id == TopRightId)
                index = TOPRIGHT;
            else if (pose.Id == BottomLeftId)
                index = BOTTOMLEFT;
            else
                return;

            var worldPos = sceneCamTransform.TransformPoint(pose.Position);
            var worldRot = sceneCamTransform.rotation * pose.Rotation;

            _poses[index].AddSample(worldPos, worldRot);
        }
        private void OnArucoPose(MarkerPose pose)
        {
            var markerOffset = CalibrationOffsets[pose.Id];

            if (markerOffset == null)
            {
                markerOffset = new MarkerOffset
                {
                    ArMarkerId = pose.Id
                };
                CalibrationOffsets[pose.Id] = markerOffset;
            }

            // pose is marker's pose -> inverted we get camera pose
            var markerMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
            var cameraMatrix = markerMatrix.inverse;

            markerOffset.HasArPose = true;
            markerOffset.ArPoseDetectionTime = Time.unscaledTime;
            markerOffset.ArMarkerPosition = pose.Position;
            markerOffset.ArMarkerRotation = pose.Rotation;
            markerOffset.ArCameraPosition = cameraMatrix.GetPosition();
            markerOffset.ArCameraRotation = cameraMatrix.GetRotation();
        }
        private void OnArucoPose(MarkerPose pose)
        {
            foreach (var cMarker in _markerSetupScript.CalibratedMarkers)
            {
                if (cMarker.Id == pose.Id)
                {
                    // pose is marker's pose -> inverted we get camera pose
                    var markerMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
                    var cameraMatrix = markerMatrix.inverse;
                    var cameraLocalPos = cameraMatrix.GetPosition();
                    var cameraWorldPos = cMarker.Marker.transform.TransformPoint(cameraLocalPos);

                    var cameraLocalRot = cameraMatrix.GetRotation();
                    var cameraWorldForward = cMarker.Marker.transform.TransformDirection(cameraLocalRot * Vector3.forward);
                    var cameraWorldUp = cMarker.Marker.transform.TransformDirection(cameraLocalRot * Vector3.up);
                    var cameraWorldRot = Quaternion.LookRotation(cameraWorldForward, cameraWorldUp);

                    var calibratedPose = new Pose
                    {
                        Id = pose.Id,
                        Position = cameraWorldPos,
                        Rotation = cameraWorldRot
                    };

                    if (_calibratedArucoPoses.ContainsKey(pose.Id))
                    {
                        _calibratedArucoPoses[pose.Id] = calibratedPose;
                    }
                    else
                    {
                        _calibratedArucoPoses.Add(pose.Id, calibratedPose);
                    }

                    // TODO thresholding etc
                    HasSteadyArucoPose = true;

                    break;
                }
            }
        }
        private void OnArucoPose(MarkerPose pose)
        {
            if (pose.Id == ArucoCalibrationId)
            {
                // we're interested in camera's position relative to marker, not markerposition
                // -> we can get camera position by inverting marker transformation matrix
                var transformMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one);
                var invMatrix = transformMatrix.inverse;

                var prevPos = _arucoPos;
                var prevRot = _arucoRot;

                _arucoPos = invMatrix.GetPosition();
                _arucoRot = invMatrix.GetRotation();

                var hasSteadyPos = (_arucoPos - prevPos).sqrMagnitude < SteadyPosThreshold;
                var hasSteadyRot = Quaternion.Angle(prevRot, _arucoRot) < SteadyAngleThreshold;
                HasSteadyArucoPose = hasSteadyPos && hasSteadyRot;
            }
        }
        private void OnArtkPose(MarkerPose pose)
        {
            if (pose.Name == ArtkCalibrationName)
            {
                // we're interested in camera's position relative to marker, not markerposition
                // -> we can get camera position by inverting marker transformation matrix

                var invertedPose = pose.Inverse();

                var prevPos = _artkPos;
                var prevRot = _artkRot;

                _artkPos = invertedPose.Position;
                _artkRot = invertedPose.Rotation;

                var hasSteadyPos = (_artkPos - prevPos).sqrMagnitude < SteadyPosThreshold;
                var hasSteadyRot = Quaternion.Angle(prevRot, _artkRot) < SteadyAngleThreshold;
                HasSteadyArtkPose = hasSteadyPos && hasSteadyRot;
            }
        }