示例#1
0
        void UpdateEventData(LinearHandleEventData eventData, bool setLastPosition = true)
        {
            var rayOrigin     = eventData.rayOrigin;
            var lastPosition  = m_LastPositions[rayOrigin];
            var worldPosition = lastPosition;

            var thisTransform = transform;

            if (m_OrientDragPlaneToRay)
            {
                // Orient a plane through the axis.
                // To avoid the plane being at a glancing angle from the ray, extend the plane perpendicular to the direction towards the ray origin.
                var rotation = thisTransform.rotation;
                var position = thisTransform.position;
                var forward  = Quaternion.Inverse(rotation) * (rayOrigin.position - position);
                forward.z = 0;
                m_Plane.SetNormalAndPosition(rotation * forward.normalized, position);
            }
            else
            {
                // Orient the plane with the handle's XZ axis, do not account for the direction the ray is starting from
                m_Plane.SetNormalAndPosition(thisTransform.up, thisTransform.position);
            }

            float distance;
            var   ray = eventData.GetRay();

            if (m_Plane.Raycast(ray, out distance))
            {
                worldPosition = ray.GetPoint(Mathf.Min(distance, HandleSettings.instance.MaxDragDistance * this.GetViewerScale()));
            }

            eventData.raycastHitWorldPosition = worldPosition;

            eventData.deltaPosition = Vector3.Project(worldPosition - lastPosition, thisTransform.forward);
            if (setLastPosition)
            {
                m_LastPositions[rayOrigin] = worldPosition;
            }
        }
示例#2
0
        void UpdateEventData(LinearHandleEventData eventData, bool setLastPosition = true)
        {
            var rayOrigin     = eventData.rayOrigin;
            var lastPosition  = m_LastPositions[rayOrigin];
            var worldPosition = lastPosition;

            var thisTransform = transform;

            if (m_OrientDragPlaneToRay)
            {
                // Orient a plane for dragging purposes through the axis that rotates to avoid being parallel to the ray,
                // so that you can prevent intersections at infinity
                var rotation = thisTransform.rotation;
                var position = thisTransform.position;
                var forward  = Quaternion.Inverse(rotation) * (rayOrigin.position - position);
                forward.z = 0;
                m_Plane.SetNormalAndPosition(rotation * forward.normalized, position);
            }
            else
            {
                m_Plane.SetNormalAndPosition(thisTransform.up, thisTransform.position);
            }

            float distance;
            var   ray = eventData.GetRay();

            if (m_Plane.Raycast(ray, out distance))
            {
                worldPosition = ray.GetPoint(Mathf.Min(distance, k_MaxDragDistance * this.GetViewerScale()));
            }

            eventData.raycastHitWorldPosition = worldPosition;

            eventData.deltaPosition = Vector3.Project(worldPosition - lastPosition, thisTransform.forward);

            if (setLastPosition)
            {
                m_LastPositions[rayOrigin] = worldPosition;
            }
        }