示例#1
0
        public static Quaternion GetLocalRotationForDynamicProngs(SpawnedPoseTargetPoint targetPoint)
        {
            bool needToFlip = false;

            Transform tpTransform = targetPoint.transform;
            Transform viveOrigin  = ObjectManager.Instance.ViveOrigin; // the coordinate system of the Vive. The floor plane will be relative to this.

            Vector3 tpUp_world = tpTransform.forward;                  // the +Z direction ends up being the "up" of the controller
            Vector3 tpUp_vive  = viveOrigin.InverseTransformDirection(tpUp_world);

            if (tpUp_vive.y < 0)
            {
                needToFlip = true;
                Debug.Log("need to flip");
            }

            Vector3 tpForward_world = -tpTransform.up; // note that the -Y direction ends up being the "forward" of the controller

            Vector3 rayDir_world = tpForward_world;

            if (needToFlip)
            {
                rayDir_world = tpUp_world;
            }

            Vector3 rayDir_vive = viveOrigin.InverseTransformDirection(rayDir_world);

            Vector3 groundPlaneNormal_vive = Vector3.up;

            Vector3 rayDir_ProjectedOntoGroundPlane_vive = Vector3.ProjectOnPlane(rayDir_vive, groundPlaneNormal_vive).normalized;

            float tp_to_quad_distance = GetProjectorProngsQuadDistance();

            Vector3 tpPosition_world = tpTransform.position;

            Vector3 tpPosition_vive           = viveOrigin.InverseTransformPoint(tpPosition_world);
            Vector3 tpNewForwardEndpoint_vive = tpPosition_vive + tp_to_quad_distance * rayDir_ProjectedOntoGroundPlane_vive;

            // raise it up to user head height
            tpNewForwardEndpoint_vive.y = ObjectManager.Instance.SessionManager.UserHeightToFloor;

            Vector3 new_tpForward_vive = (tpNewForwardEndpoint_vive - tpPosition_vive).normalized;

            Vector3 new_tpForward_world = viveOrigin.TransformDirection(new_tpForward_vive);

            float degrees = Vector3.SignedAngle(tpForward_world, new_tpForward_world, tpTransform.right);

            Debug.Log("degrees: " + degrees);

            Quaternion localRotation_tp = Quaternion.AngleAxis(degrees, Vector3.right);

            return(localRotation_tp);
        }
    public void OnTargetSpawned(SpawnedPoseTargetPoint spawnedPoseTargetPoint, InterfaceType alignmentInterfaceType, ControllerTargetPointLocation controllerTargetPointLocation)
    {
        CurrentSpawnedPoseTargetPoint = spawnedPoseTargetPoint;

        RefreshVisualization(alignmentInterfaceType, controllerTargetPointLocation);
    }
    public void OnAlignmentConfirmed()
    {
        HideAllInterfaces();

        CurrentSpawnedPoseTargetPoint = null;
    }