예제 #1
0
    private void RotateToTarget()
    {
        var vectorToArrowPosition = arrow.transform.position;

        var rotH = Quaternion.AngleAxis(hAngle, Vector3.up);
        var vectorToAttentionPoint            = rotH * new Vector3(-1, 0, 0); // Vector3.forward;
        var horAngleBeteenArrowAndTargetPoint = Vector2.SignedAngle(new Vector2(vectorToAttentionPoint.x, vectorToAttentionPoint.z), new Vector2(vectorToArrowPosition.x, vectorToArrowPosition.z));

        if (horAngleBeteenArrowAndTargetPoint > 90 || horAngleBeteenArrowAndTargetPoint < -90)
        {
            // the target is on the other side - need to point left/right to assure arrow does't point over the top/bottom of sphere based on nearest bearing
            if (horAngleBeteenArrowAndTargetPoint > 0)
            {
                arrow.transform.localRotation = Quaternion.Euler(new Vector3(90, 0, -90));
            }
            else
            {
                arrow.transform.localRotation = Quaternion.Euler(new Vector3(-90, 0, -90));
            }
        }
        else
        {
            // target is on this side of the sphere - make the arrow point to the correct bearing
            var longLatsForArrowPosition = AngleHelperMethods.PositionToLonLat(vectorToArrowPosition);             //   GetLatLongForEyePosition(vectorToEyePosition);
            //Debug.LogError(longLatsForEyePosition);
            var longLatsForAttentionPosition = new Vector2(hAngle, vAngle);
            var bearingToTarget = GetBearingForLongLats(horAngleBeteenArrowAndTargetPoint, longLatsForArrowPosition, longLatsForAttentionPosition);

            arrow.transform.localRotation = Quaternion.Euler(new Vector3(bearingToTarget, 0, -90));
        }
    }
예제 #2
0
    // From https://github.com/Mouledoux/ConnectedHome/blob/master/Assets/Scripts/TargetIndicator.cs
    private void UpdatePositionWithinFov()
    {
        var newPos     = GetScreenPointOfAttentionTarget(target);
        var leftEyeCam = leftEyeCamera.GetComponent <Camera>();

        var clampedPos = new Vector2();

        clampedPos.x = Mathf.Clamp(newPos.x, m_edgeBufferWidth, leftEyeCam.scaledPixelWidth - m_edgeBufferWidth); // (val, min, max)
        clampedPos.y = Mathf.Clamp(newPos.y, m_edgeBufferHeight, leftEyeCam.scaledPixelHeight - m_edgeBufferHeight);

        if (clampedPos.x != newPos.x || clampedPos.y != newPos.y)
        {
            // the target doesn't fall inside the viewport, so we should place flicker on bearing to target on sphere
            var vectorToAttentionPoint = target.transform.position;
            var vectorToHeadPosition   = leftEyeCamera.transform.forward;

            var horAngleBeteenHeadAndTargetPoint = Vector2.SignedAngle(new Vector2(vectorToAttentionPoint.x, vectorToAttentionPoint.z), new Vector2(vectorToHeadPosition.x, vectorToHeadPosition.z));

            //Debug.LogError(horAngleBeteenHeadAndTargetPoint);

            if (horAngleBeteenHeadAndTargetPoint > 90 || horAngleBeteenHeadAndTargetPoint < -90)
            {
                // the target is on the other side - need to point left/right to assure arrow does't point over the top/bottom of sphere based on nearest bearing
                if (horAngleBeteenHeadAndTargetPoint > 0)
                {
                    tangentRotate.transform.localRotation = Quaternion.Euler(new Vector3(0, 90f, 0f));
                }
                else
                {
                    tangentRotate.transform.localRotation = Quaternion.Euler(new Vector3(180f, 90f, 0f));
                }
            }
            else
            {
                var longLatForHead   = AngleHelperMethods.PositionToLonLat(leftEyeCamera.transform.forward);
                var longLatForTarget = AngleHelperMethods.PositionToLonLat(vectorToAttentionPoint);

                var bearingToTarget = GetBearingForLongLats(horAngleBeteenHeadAndTargetPoint, longLatForHead, longLatForTarget);

                // DEBUG: THIS DOESNT SEEM TO WORK QUITE RIGHT - but is it enough for a pilot study?
                // Actually this totally does work - the issue seems to be later, when we clamp the value to the screen fov
                var rollOfCamera = leftEyeCamera.transform.rotation.eulerAngles.z;
                tangentRotate.transform.localRotation = Quaternion.Euler(bearingToTarget - 90f + rollOfCamera, 90f, 0f);
            }

            newPos = GetScreenPointInDirection(leftEyeCam, tangentRotate.transform.position, tangentPoint.transform.position);

            clampedPos.x = Mathf.Clamp(newPos.x, m_edgeBufferWidth, leftEyeCam.scaledPixelWidth - m_edgeBufferWidth); // (val, min, max)
            clampedPos.y = Mathf.Clamp(newPos.y, m_edgeBufferHeight, leftEyeCam.scaledPixelHeight - m_edgeBufferHeight);
        }

        Ray rayToSceneFlicker = leftEyeCam.ScreenPointToRay(clampedPos);

        Debug.DrawRay(rayToSceneFlicker.origin, rayToSceneFlicker.direction, Color.green, 1f);
        SetAnglesForFlicker(rayToSceneFlicker);

        //m_icon.transform.position = newPos;
    }
예제 #3
0
    private void SetAnglesForFlicker(Ray rayToSceneFlicker)
    {
        // var rotation = Quaternion.FromToRotation(camera.transform.forward, rayToSceneFlicker.direction);
        var oldLatLong = AngleHelperMethods.PositionToLonLat(transform.position);
        var newLatLong = AngleHelperMethods.PositionToLonLat(rayToSceneFlicker.direction);

        var longChange = oldLatLong.x - newLatLong.x;
        var latChange  = oldLatLong.y - newLatLong.y;

        // Debug.LogError("long change: " + longChange);
        // Debug.LogError("lat change: " + latChange);

        var up = new Vector3(0, 1, 0);

        transform.RotateAround(Vector3.zero, up, longChange * -1f);
        transform.RotateAround(Vector3.zero, transform.forward, latChange);
    }