Esempio n. 1
0
    /*
     * 修改:因为unity中绕某一轴(例如X轴,X轴指向自己)顺时针旋转为正角度,逆时针旋转为负角度,
     * 所以改为verticalV = Vector3.Cross(axis, projV).normalized
     * 其中要指出的是Vector3.Cross(a, b)相当于百度百科中叉乘的bxa
     */
    //向量绕着某个平面的法线旋转角度 axis可以看作某个平面的法线
    public static Vector3 RotateAroundAxis(Vector3 v, Vector3 axis, float angle)
    {
        Vector3 projV     = PreDefScrp.ComputeProjection(axis, v); //投影向量
        Vector3 verticalV = Vector3.Cross(axis, projV).normalized; //新得投影向量垂直于旧投影向量的向量,方向指向新向量

        verticalV *= projV.magnitude * Mathf.Sin(angle * Mathf.Deg2Rad);
        Vector3 sectionProjV = projV.normalized * projV.magnitude * Mathf.Cos(angle * Mathf.Deg2Rad);//旧投影向量的一截
        Vector3 newProjV     = verticalV + sectionProjV;

        return(newProjV + (v - projV));
    }
Esempio n. 2
0
    public void UIRecenterControl(Vector3 dir)
    {
        if (IsInLockAngle && IsFirstInLockAngle)
        {
            IsFirstInLockAngle = false;
            return;
        }
        if (!IsInFocus)//重置UI位置,跟随鼠标点击
        {
            Vector3 yDir  = PreDefScrp.ComputeProjection(Vector3.up, dir);
            float   angle = Vector3.Angle(OldUIDir, yDir);
            //Debug.Log("角度" + angle);
            if (!IsPointerEnterVideoPlayerUI)
            {
                if (angle <= 10)
                {
                    if (SwitchVideoPlayerUIVisionCallback != null)
                    {
                        SwitchVideoPlayerUIVisionCallback();
                    }
                }
                else
                {
                    if (ResetUIDirCallback != null)
                    {
                        ResetUIDirCallback();
                    }
                }

                OldUIDir = yDir;
            }
            else
            {
                Debug.Log("已经进入VideoPlayerUI,所以没法动态切换显影");
            }
        }
        else //视角回正
        {
            if (!IsPointerEnterVideoPlayerUI && FocusCompleteCallback != null)
            {
                FocusCompleteCallback();
            }
            else
            {
                Debug.Log("已经进入VideoPlayerUI,所以没法视角调整");
            }
        }
    }
Esempio n. 3
0
    void ResetUIDir()
    {
        Vector3 dir   = Camera.main.transform.forward;
        Vector3 yDir  = PreDefScrp.ComputeProjection(Vector3.up, dir);
        float   angle = Vector3.Angle(OldUIDir, yDir);

        if (angle > 2)
        {
            Vector3 valueDir   = Vector3.Cross(Vector3.forward, yDir);
            float   valueAngle = Vector3.Angle(Vector3.forward, yDir);

            Vector3 cToUVector = PreDefScrp.RotateAroundAxis(CameraToUIVector, valueDir, valueAngle);
            this.transform.forward  = yDir;
            this.transform.position = Camera.main.transform.position + cToUVector;
            OldUIDir = yDir;
        }
    }