コード例 #1
0
        public IEnumerator Marker_AlignObject()
        {
            Marker marker = new Marker()
            {
                RelativePosition      = Vector3.one,
                RelativeRotationEuler = Vector3.zero,
                ObjectScale           = Vector3.one
            };

            Vector3    modelPosition = Vector3.zero;
            Quaternion modelRotation = Quaternion.identity;
            Vector3    modelScale    = Vector3.one;


            GameObject m_VirtualMarkerParent = new GameObject("VirtualMarkerParent");

            m_VirtualMarkerParent.transform.position   = modelPosition;
            m_VirtualMarkerParent.transform.rotation   = modelRotation;
            m_VirtualMarkerParent.transform.localScale = modelScale;

            GameObject m_VirtualMarker = new GameObject("Virtual Marker");

            m_VirtualMarker.transform.SetParent(m_VirtualMarkerParent.transform, false);
            m_VirtualMarker.transform.localPosition    = marker.RelativePosition;
            m_VirtualMarker.transform.localRotation    = Quaternion.Euler(marker.RelativeRotationEuler);
            m_VirtualMarkerParent.transform.localScale = marker.ObjectScale;

            GameObject testModel = new GameObject();

            testModel.transform.position   = new Vector3(234f, 2f, 8f);
            testModel.transform.rotation   = Quaternion.Euler(new Vector3(0f, 23f, 0f));
            testModel.transform.localScale = modelScale;

            yield return(new WaitForSeconds(0.1f));

            // Test with a marker that which is attached to a wall and slightly tilted to the side but otherwise the Y should be the same.
            Pose testPose = new Pose(modelPosition + marker.RelativePosition, Quaternion.Euler(new Vector3(90f, 0f, 0f)));

            marker.AlignObject(testModel.transform, testPose);


            yield return(new WaitForSeconds(0.1f));

            Vector3 positionDiffrence     = testModel.transform.position - m_VirtualMarkerParent.transform.position;
            float   positionDiffMagnitude = positionDiffrence.sqrMagnitude;

            Debug.Log($"Positon Test: {testModel.transform.position} Should match {m_VirtualMarkerParent.transform.position}");
            Debug.Log($"Position Difference of {positionDiffrence} magnitude {positionDiffMagnitude} epsilon {float.Epsilon}");

            Vector3 rotationDifference    = testModel.transform.rotation.eulerAngles - m_VirtualMarkerParent.transform.rotation.eulerAngles;
            float   rotationDiffMagnitude = rotationDifference.sqrMagnitude;

            Debug.Log($"Rotation Test: {testModel.transform.rotation.eulerAngles} Should match {m_VirtualMarkerParent.transform.rotation.eulerAngles}");
            Debug.Log($"Rotation Difference of {rotationDifference} magnitude {rotationDiffMagnitude}");

            Assert.True(positionDiffMagnitude < 0.01f);
            Assert.True(rotationDiffMagnitude < 0.01f);
        }
コード例 #2
0
        public void ActivateMarker()
        {
            Debug.Log("Aligning Object");
            Debug.Log(_modelController.Model);
            _acceptedPose = _currentMarkerPose;
            var result = Marker.AlignObject(_foundMarker, new TransformData(_modelController.Model.transform), _acceptedPose);

            _modelController.Model.transform.position   = result.position;
            _modelController.Model.transform.rotation   = result.rotation;
            _modelController.Model.transform.localScale = result.scale;
            Debug.Log("Opening the transform tools");
            _transformUI.Open(_foundMarker, _modelController.Model.transform);
        }