Exemple #1
0
        /// <summary>
        /// Update the rotation based on input.
        /// </summary>
        /// <returns>A Vector3 describing the desired position</returns>
        public Vector3 Update(MixedRealityPose pointerCentroidPose, Quaternion objectRotation, Vector3 objectScale, bool usePointerRotation, MovementConstraintType movementConstraint)
        {
            float distanceRatio = 1.0f;

            if (pointerPosIndependentOfHead && movementConstraint != MovementConstraintType.FixDistanceFromHead)
            {
                // Compute how far away the object should be based on the ratio of the current to original hand distance
                float currentHandDistance = GetDistanceToBody(pointerCentroidPose);
                distanceRatio = currentHandDistance / pointerRefDistance;
            }

            if (usePointerRotation)
            {
                Vector3 scaledGrabToObject    = Vector3.Scale(objectLocalGrabPoint, objectScale);
                Vector3 adjustedPointerToGrab = (pointerLocalGrabPoint * distanceRatio);
                adjustedPointerToGrab = pointerCentroidPose.Rotation * adjustedPointerToGrab;

                return(adjustedPointerToGrab - objectRotation * scaledGrabToObject + pointerCentroidPose.Position);
            }
            else
            {
                return(pointerCentroidPose.Position + pointerCentroidPose.Rotation * pointerLocalGrabPoint + grabToObject * distanceRatio);
            }
        }
        /// <summary>
        /// Update the rotation based on input.
        /// </summary>
        /// <param name="pointerCentroidPose"></param>
        /// <param name="objectRotation"></param>
        /// <param name="objectScale"></param>
        /// <param name="isNearMode"></param>
        /// <param name="usePointerRotation"></param>
        /// <param name="movementConstraint"></param>
        /// <returns>A Vector3 describing the desired position</returns>
        public Vector3 Update(MixedRealityPose pointerCentroidPose, Quaternion objectRotation, Vector3 objectScale, bool isNearMode, bool usePointerRotation, MovementConstraintType movementConstraint)
        {
            if (!isNearMode || usePointerRotation)
            {
                Vector3 headPosition  = CameraCache.Main.transform.position;
                float   distanceRatio = 1.0f;

                if (movementConstraint != MovementConstraintType.FixDistanceFromHead)
                {
                    // Compute how far away the object should be based on the ratio of the current to original hand distance
                    var currentHandDistance = Vector3.Magnitude(pointerCentroidPose.Position - headPosition);
                    distanceRatio = currentHandDistance / pointerRefDistance;
                }

                Vector3 scaledGrabToObject    = Vector3.Scale(objectLocalGrabPoint, objectScale);
                Vector3 adjustedPointerToGrab = (pointerLocalGrabPoint * distanceRatio);
                adjustedPointerToGrab = pointerCentroidPose.Rotation * adjustedPointerToGrab;

                return(adjustedPointerToGrab - objectRotation * scaledGrabToObject + pointerCentroidPose.Position);
            }
            else
            {
                return(pointerCentroidPose.Position + pointerToObject);
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="movementConstraint"></param>
 public TwoHandMoveLogic(MovementConstraintType movementConstraint)
 {
     this.movementConstraint = movementConstraint;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="rotationConstraint"></param>
 public TwoHandMoveLogic(MovementConstraintType _movementConstraint)
 {
     movementConstraint = _movementConstraint;
 }