Пример #1
0
    public void RotateOnAxis(float sign, Vector3 rotationAxis, ref float lastRotationAmount)
    {
        float   distance;
        float   rotationAmount;
        Vector3 objCenter = handsManager.objCenter;

        distance = Mathf.Abs(sign);
        if (initialDistance < 0)
        {
            initialDistance = distance;
        }

        rotationAmount = distance * 1800;

        //rotate object
        rotationAmount *= sign < 0 ? -1 : 1;
        handsManager.objFocused.transform.RotateAround(objCenter, rotationAxis, rotationAmount - lastRotationAmount);
        TwoHandedCursorManager.SetBoundingCubeSize(handsManager.objFocused, handsManager.boundingCube);

        direction          = sign;
        lastRotationAmount = rotationAmount;
    }
    public void resetAndShowHologramAtIndex(int index, bool showTarget)
    {
        int hologramNum = index + 1;

        UnityEngine.Debug.Log("Resetting Hologram " + hologramNum + " and showTarget is " + showTarget);
        Vector3    textPosition, roundTextPosition;
        GameObject manipulatableObject = manipulatableGameObjects[index];
        GameObject targetObject        = targetGameObjects[index];

        hideAllHolograms();

        //reset hologram to initial state
        TransformHelper initialManipulatableTransform = initialTransforms[manipulatableObject];

        manipulatableObject.transform.position   = initialManipulatableTransform.position;
        manipulatableObject.transform.localScale = initialManipulatableTransform.localScale;
        manipulatableObject.transform.rotation   = initialManipulatableTransform.rotation;

        TwoHandedCursorManager.SetBoundingCubeSize(manipulatableObject, TwoHandedCursorManager.boundingCubesInverse [manipulatableObject]);

        TwoHandedCursorManager.extents[manipulatableObject] = manipulatableObject.GetComponent <Renderer>().bounds.extents.magnitude *TwoHandedCursorManager.RADIUS_MULTIPLIER;


        TwoHandedCursorManager.boundingCubesInverse [manipulatableObject].SetActive(true);

        if (showTarget && roundStarted)
        {
            roundStarted = false;
            handsManager.userStudyOrientationText.gameObject.SetActive(true);
            handsManager.userStudyRoundText.gameObject.SetActive(true);
            handsManager.startRoundButton.gameObject.SetActive(false);
            manipulatableObject.SetActive(true);
            targetObject.SetActive(true);
            textPosition    = targetObject.GetComponent <Renderer>().bounds.center;
            textPosition.y += targetObject.GetComponent <Renderer>().bounds.size.y / 2 * 1.1f;
            handsManager.userStudyOrientationText.text = "Target Image Orientation and Size";

            roundTextPosition = (targetObject.GetComponent <Renderer>().bounds.center + manipulatableObject.GetComponent <Renderer>().bounds.center) / 2.0f;

            roundTextPosition.y += 0.6f;

            handsManager.userStudyRoundText.text = "Round " + hologramNum + "/" + hologramCount;

            float roundTextHeight = handsManager.userStudyRoundText.preferredHeight * handsManager.menu.transform.parent.localScale.x / 2;
            roundTextPosition.y += roundTextHeight;

            handsManager.userStudyRoundText.transform.position = roundTextPosition;
            handsManager.userStudyRoundText.gameObject.SetActive(true);

            float textHeight = handsManager.userStudyOrientationText.preferredHeight * handsManager.menu.transform.parent.localScale.x / 2;
            textPosition.y += textHeight;

            handsManager.userStudyOrientationText.transform.position = textPosition;
            handsManager.userStudyOrientationText.gameObject.SetActive(true);

            hologramShown = true;
            //reset stats
            resetStats();
            totalTimeInRound.Start();
        }
        else if (!showTarget)
        {
            manipulatableObject.SetActive(true);
            hologramShown = true;
            handsManager.userStudyRoundText.gameObject.SetActive(false);
            textPosition    = manipulatableObject.GetComponent <Renderer>().bounds.center;
            textPosition.y -= manipulatableObject.GetComponent <Renderer>().bounds.size.y *2;

            handsManager.userStudyOrientationText.transform.position = textPosition;
            handsManager.userStudyOrientationText.gameObject.SetActive(true);

            //reset stats
            resetStats();
            totalTimeInRound.Start();
        }
        else if (!roundStarted)
        {
            disableImages = true;
            handsManager.startRoundButton.gameObject.SetActive(true);
            handsManager.userStudyOrientationText.gameObject.SetActive(false);
            handsManager.userStudyRoundText.gameObject.SetActive(false);
            handsManager.userStudyButtonText.text = "Press Start Round When Ready";

            disableTimedButton = true;
            handsManager.beginUserStudyButton.interactable = false;
            handsManager.startRoundButton.GetComponentInChildren <Text>().text = "Rest your arms. When you are ready, press here to start round " + hologramNum;
            hologramShown = false;
        }
    }
Пример #3
0
    public void RotateObject()
    {
        Vector3 cameraPosition           = Camera.main.transform.position;
        float   currentRightFaceDistance = Vector3.Distance(cameraPosition, handsManager.rightHandPosition);
        float   currentLeftFaceDistance  = Vector3.Distance(cameraPosition, handsManager.leftHandPosition);
        float   sign;
        float   angle;
        Vector3 cross;
        Vector3 newPosition, oldPosition;
        int     resetFrames  = NUM_FRAMES_RESET;
        Vector3 rotationAxis = handsManager.axisForRotation;

        if (handsManager.rotationFrameNumber == 0)
        {
            SetInitialPositions(handsManager.initialRight, handsManager.initialLeft);
            initialGazeDirection = handsManager.objCenter - Camera.main.transform.position;             //or can use Camera.main.transform.forward;
        }

        switch (handsManager.rotationType)
        {
        case pitchRotation:
            if (TwoHandedGesturesManager.TECHNIQUE_SELECTED == TwoHandedGesturesManager.TECHNIQUE_1)
            {
                sign = ((handsManager.rightHandPosition.y - rotationInitialRight.y) + (handsManager.leftHandPosition.y - rotationInitialLeft.y)) / 2;
            }
            else
            {
                sign = ((initialRightFaceDistance - currentRightFaceDistance) + (currentLeftFaceDistance - initialLeftFaceDistance)) / 2;
                if (rotationInitialRight.y > rotationInitialLeft.y)
                {
                    sign *= -1;
                }
            }
            RotateOnAxis(sign, rotationAxis, ref lastPitchRotationAmount);
            break;

        case rollRotation:
            sign = ((handsManager.rightHandPosition.y - rotationInitialRight.y) + (rotationInitialLeft.y - handsManager.leftHandPosition.y)) / 2;
            RotateOnAxis(sign, rotationAxis, ref lastRollRotationAmount);
            break;

        case yawRotation:
            sign = ((initialRightFaceDistance - currentRightFaceDistance) + (currentLeftFaceDistance - initialLeftFaceDistance)) / 2;
            RotateOnAxis(sign, rotationAxis, ref lastYawRotationAmount);
            break;

        case spindleRotation:
            Vector3 newRightSide = handsManager.rightHandSpindlePosition - handsManager.objCenter;
            Vector3 oldRightSide = handsManager.rightHandInitialSpindlePosition - handsManager.objCenter;
            Vector3 newLeftSide  = handsManager.leftHandSpindlePosition - handsManager.objCenter;
            Vector3 oldLeftSide  = handsManager.leftHandInitialSpindlePosition - handsManager.objCenter;

            angle = -(Vector3.Angle(oldRightSide, newRightSide) + Vector3.Angle(oldLeftSide, newLeftSide)) / 2;

            cross = Vector3.Cross(newRightSide, oldRightSide);

            // attempt at pitch starts here
            sign         = ((handsManager.rightHandPosition.y - rotationInitialRight.y) + (handsManager.leftHandPosition.y - rotationInitialLeft.y)) / 3;
            rotationAxis = handsManager.rightHandSpindlePosition - handsManager.leftHandSpindlePosition;
            RotateOnAxis(sign, rotationAxis, ref lastPitchRotationAmount);
            // and it ends here

            if (handsManager.rotationFrameNumber != 0)
            {
                handsManager.objFocused.transform.RotateAround(handsManager.objCenter, lastAxis, -lastYawRotationAmount);
                handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, lastAxis, -lastYawRotationAmount);
            }
            lastAxis = cross;
            handsManager.objFocused.transform.RotateAround(handsManager.objCenter, cross, angle);                    // = rotation;
            handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, cross, angle);
            TwoHandedCursorManager.SetBoundingCubeSize(handsManager.objFocused, handsManager.boundingCube);

            lastYawRotationAmount = angle;
            ++handsManager.rotationFrameNumber;
            break;

        case arcBallRotation:
            newPosition = handsManager.arcBallHandPosition - handsManager.objCenter;
            oldPosition = handsManager.initialArcballHandPosition - handsManager.objCenter;


            angle = -Vector3.Angle(oldPosition, newPosition);

            cross = Vector3.Cross(newPosition, oldPosition);

            if (handsManager.rotationFrameNumber != 0)
            {
                handsManager.objFocused.transform.RotateAround(handsManager.objCenter, lastAxis, -lastPitchRotationAmount);
                handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, lastAxis, -lastPitchRotationAmount);
            }
            lastAxis = cross;
            handsManager.objFocused.transform.RotateAround(handsManager.objCenter, cross, angle);
            handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, cross, angle);
            TwoHandedCursorManager.SetBoundingCubeSize(handsManager.objFocused, handsManager.boundingCube);

            lastPitchRotationAmount = angle;
            ++handsManager.rotationFrameNumber;
            return;

        case wireFrameRotation:
            float   initialDistance;
            float   newDistance;
            Vector3 C, A;

            C = handsManager.handBeingTrackedPosition;
            A = handsManager.initialHandBeingTrackedPosition;

            initialDistance = Vector3.Distance(handsManager.initialHandBeingTrackedPosition, handsManager.objCenter);
            newDistance     = Vector3.Distance(handsManager.handBeingTrackedPosition, handsManager.objCenter);

            float sign2;

            if (TwoHandedCursorManager.sphereIndexUnderCursor < 4)
            {
                sign = handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, C) - handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, A);
                //yaw
            }
            else if (TwoHandedCursorManager.sphereIndexUnderCursor < 6)
            {
                // pitch
                sign  = initialDistance - newDistance;
                sign2 = handsManager.handBeingTrackedPosition.y - handsManager.initialHandBeingTrackedPosition.y;
                sign  = (sign + sign2);
            }
            else
            {
                sign  = handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, A) - handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, C);
                sign2 = handsManager.initialHandBeingTrackedPosition.y - handsManager.handBeingTrackedPosition.y;
                sign  = (sign + sign2);
                //roll
            }
            RotateOnAxis(sign, handsManager.axisForRotation, ref lastPitchRotationAmount);
            ++handsManager.rotationFrameNumber;
            return;

        case selectionRotation:
            newPosition = handsManager.arcBallHandPosition - handsManager.objCenter;
            oldPosition = handsManager.initialArcballHandPosition - handsManager.objCenter;


            angle = -Vector3.Angle(oldPosition, newPosition);

            cross = Vector3.Cross(newPosition, oldPosition);

            if (handsManager.rotationFrameNumber != 0)
            {
                handsManager.objFocused.transform.RotateAround(handsManager.objCenter, lastAxis, -lastPitchRotationAmount);
                handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, lastAxis, -lastPitchRotationAmount);
            }

            lastAxis = cross;

            handsManager.objFocused.transform.RotateAround(handsManager.objCenter, cross, angle);
            handsManager.boundingSphere.transform.RotateAround(handsManager.objCenter, cross, angle);
            TwoHandedCursorManager.SetBoundingCubeSize(handsManager.objFocused, handsManager.boundingCube);

            lastPitchRotationAmount = angle;
            ++handsManager.rotationFrameNumber;
            return;

        default:
            GuessRotationType();
            return;
        }

        if (++handsManager.rotationFrameNumber % resetFrames == 0)
        {
            SetInitialPositions(handsManager.rightHandPosition, handsManager.leftHandPosition);
        }
    }
Пример #4
0
    public void ScaleObject()
    {
        float initialDistance;
        float newDistance;
        float linearScale;
        float scale;

        if (TwoHandedGesturesManager.TECHNIQUE_SELECTED == TwoHandedGesturesManager.TECHNIQUE_5)
        {
            initialDistance = Vector3.Distance(handsManager.initialHandBeingTrackedPosition, handsManager.objCenter);
            newDistance     = Vector3.Distance(handsManager.handBeingTrackedPosition, handsManager.objCenter);
            Vector3 C = handsManager.handBeingTrackedPosition;
            Vector3 A = handsManager.initialHandBeingTrackedPosition;

            float sign  = handsManager.DotProduct(handsManager.objCenter, Camera.main.transform.position - handsManager.objCenter, TwoHandedCursorManager.objectUnderCursor.transform.position);
            float sign2 = handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, C) - handsManager.DotProduct(Camera.main.transform.position, Camera.main.transform.forward, A);;
            if (sign > 0)
            {
                newDistance -= sign2;
            }
            else
            {
                newDistance += sign2;
            }
        }
        else
        {
            initialDistance = Vector3.Distance(handsManager.initialLeft, handsManager.initialRight);
            newDistance     = Vector3.Distance(handsManager.leftHandPosition, handsManager.rightHandPosition);
        }

        linearScale = newDistance / initialDistance;

        if (TwoHandedGesturesManager.TECHNIQUE_SELECTED == TwoHandedGesturesManager.TECHNIQUE_5)
        {
            scale = (float)Mathf.Pow(linearScale, 15f);
        }
        else if (TwoHandedGesturesManager.TECHNIQUE_SELECTED != TwoHandedGesturesManager.TECHNIQUE_3)
        {
            scale = (float)Mathf.Pow(linearScale, 4f);
        }
        else
        {
            scale = (float)Mathf.Pow(linearScale, 2f);
        }


        Vector3 newSize = handsManager.initialSize;

        newSize *= scale;

        Vector3 newBoundsSize = handsManager.objFocused.GetComponent <Renderer>().bounds.size *scale;

        float x = newBoundsSize.x, y = newBoundsSize.y, z = newBoundsSize.z;
        float smallestSideLimit = .017f;

        float largestSide       = Mathf.Max(x, Mathf.Max(y, z));

        if (largestSide <= smallestSideLimit)
        {
            if ((x > y) && (x > z))
            {
                newSize.x = newSize.y = newSize.z = smallestSideLimit * newSize.x / x;
            }
            else if ((y > x) && (y > z))
            {
                newSize.x = newSize.y = newSize.z = smallestSideLimit * newSize.y / y;
            }
            else
            {
                newSize.x = newSize.y = newSize.z = smallestSideLimit * newSize.z / z;
            }
        }

        TwoHandedCursorManager.extents[handsManager.objFocused] = newSize.x / handsManager.initialSize.x * handsManager.initialExtent;

        Vector3 oldCenter = handsManager.objFocused.GetComponent <Renderer> ().bounds.center;

        handsManager.objFocused.transform.localScale = newSize;
        Vector3 newCenter = handsManager.objFocused.GetComponent <Renderer> ().bounds.center;

        handsManager.objFocused.transform.position += (oldCenter - newCenter);
        TwoHandedCursorManager.SetBoundingCubeSize(handsManager.objFocused, handsManager.boundingCube);
    }