Exemplo n.º 1
0
    public void UpdateMainNFOVCamera()
    {
        if (opticalFlowCamerasController.smoothPath == null || !videoPlayer.isPlaying)
        {
            return;
        }
        var originSize = new Vector2(videoPlayer.targetTexture.width, videoPlayer.targetTexture.height);
        int downsampleWidth, downsampleHeight;

        opticalFlowCamerasController.GetDownsampleSize(out downsampleWidth, out downsampleHeight);
        var downsampleSize = new Vector2(downsampleWidth, downsampleHeight);
        int nowFrame       = (int)videoPlayer.frame;
        var cameraNFOVs    = panelVideoController.cameraNFOVs;
        var nextFrame      = KeyFrameToFrame(nextKeyFrame);

        //Debug.Log(string.Format("oldFrame: {0}, nowFrame: {1}, nextFrame: {2}", oldFrame, nowFrame, nextFrame));
        if (nextCameraId >= 0)
        {
            if (nowFrame < nextFrame || !reachable)
            {
                var path     = opticalFlowCamerasController.smoothPath[nextCameraId];
                var mForward = mainNFOVCamera.transform.forward;
                var desP     = path[nextKeyFrame];
                var nowP     = opticalFlowCamerasController.PixelToOriginPixelFloatValue(panelVideoController.EulerAngleToPixel(mainNFOVCamera.transform.eulerAngles), originSize, downsampleSize);
                //Debug.Log(string.Format("frames: {0}, nowP: {1}, Time.deltaTime:{2}", (nowFrame - oldFrame), nowP, Time.deltaTime));
                var v = GetVector2Of2Pixels(nowP, desP, downsampleWidth, selectedDirection);
                var pixelDistPerFrame = nextFrame - oldFrame <= 0 ? 1e9f : v.magnitude / (nextFrame - oldFrame);
                pixelDistPerFrame = Mathf.Min(moveMaxPixelPerFrame, pixelDistPerFrame);
                var theta = Mathf.Max((nowFrame - oldFrame) * pixelDistPerFrame, 0);
                var nv    = v.normalized;
                //var nextP = nowP + new Vector2(nv.x * theta, nv.y * theta);
                var nextP = nowP + Mathf.Min(transferSpeed.magnitude, moveMaxPixelSpeed) * Time.deltaTime * transferSpeed.normalized;//只用帧数的话会比较卡顿
                OpticalFlowCamerasController.NormalizePixelInRange(ref nextP.x, ref nextP.y, downsampleWidth, downsampleHeight);
                var newForward = panelVideoController.PixelToVector3(opticalFlowCamerasController.PixelToOriginPixelFloatValue(nextP, downsampleSize, originSize));
                mainNFOVCamera.transform.forward = newForward;
                manager.panoramaVideoController.UpdateTextMethodStatus(2);
                mainNFOVCamera.Render();
            }
            else
            {
                mainNFOVCamera.transform.forward = cameraNFOVs[nextCameraId].transform.forward;
                manager.panoramaVideoController.UpdateTextMethodStatus(2);
                mainNFOVCamera.Render();
                nextKeyFrame      = -1;
                nowCameraId       = nextCameraId;
                selectedDirection = -1;
            }
        }
        oldFrame = nowFrame;
    }
Exemplo n.º 2
0
    //Limit the maximum moving speed to prevent the window from shaking too much
    public Vector3 ApplyMaxSpeedLimit(Vector3 fa, Vector3 fb, float t)
    {
        if (fa.Equals(fb))
        {
            return(fa);
        }
        var originSize = new Vector2(videoPlayer.targetTexture.width, videoPlayer.targetTexture.height);
        int downsampleWidth, downsampleHeight;

        opticalFlowCamerasController.GetDownsampleSize(out downsampleWidth, out downsampleHeight);
        var cameraCalculate = manager.cameraCalculate;

        cameraCalculate.transform.forward = fa;
        var ea = cameraCalculate.transform.eulerAngles;
        var pa = panelVideoController.EulerAngleToPixel(ea);

        pa = opticalFlowCamerasController.PixelToOriginPixelFloatValue(pa, originSize, new Vector2(downsampleWidth, downsampleHeight));
        cameraCalculate.transform.forward = fb;
        var eb = cameraCalculate.transform.eulerAngles;
        var pb = panelVideoController.EulerAngleToPixel(eb);

        pb = opticalFlowCamerasController.PixelToOriginPixelFloatValue(pb, originSize, new Vector2(downsampleWidth, downsampleHeight));
        var v = opticalFlowCamerasController.GetVector2Of2Pixels(pa, pb, downsampleWidth);

        if (v.magnitude == 0)
        {
            return(fa);
        }
        v = v / v.magnitude * Mathf.Min(maxSpeed * t, v.magnitude);
        Debug.Log("ApplyMaxSpeedLimit");
        Debug.Log(string.Format("t:{0}, v: {1}", t, v));
        var p = pa + v;

        OpticalFlowCamerasController.NormalizePixelInRange(ref p.x, ref p.y, downsampleWidth, downsampleHeight);
        return(panelVideoController.PixelToVector3(opticalFlowCamerasController.PixelToOriginPixelFloatValue(p, new Vector2(downsampleWidth, downsampleHeight), originSize)));
    }