//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))); }
public void ChangeSelectedCamIdByCamId(int camId) { Debug.Log("ChangeSelectedCamIdByCamId: " + camId); if (camId == nextCameraId) { return; } var nowFrame = (int)videoPlayer.frame; var totalFrame = videoPlayer.frameCount; int totalKeyFrame = smoothPath[0].Count; var beginKeyFrame = GetCurrentKeyFrame(); if (ifCloseCameraWindow[camId][beginKeyFrame]) { 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); var nowDownsamplePixel = opticalFlowCamerasController.PixelToOriginPixelFloatValue(panelVideoController.EulerAngleToPixel(mainNFOVCamera.transform.eulerAngles), originSize, downsampleSize); bool ifGetNextCam = false; var minV = new Vector2(1e9f, 1e9f); int newNowFrame = (int)videoPlayer.frame; Debug.Log("newNowFrame: " + newNowFrame); int nextCameraIdTmp = 0; int nextJustOkCamIdTmp = 0; float justOkV = 1e9f; int justOkKeyFrame = Mathf.Min(totalKeyFrame - 1, beginKeyFrame + 1); for (int i = beginKeyFrame + 1; i < Mathf.Min(totalKeyFrame, beginKeyFrame + maxTransferKeyFrameNum); i++) { int frameNum = KeyFrameToFrame(i) - nowFrame; if (frameNum < 0) { continue; } float timeGap = frameNum / videoPlayer.frameRate; if (nextCameraId == nowCameraId && nowCameraId == camId) { continue; } var path = opticalFlowCamerasController.smoothPath[camId]; var futureDownsamplePixel = path[i]; var v = GetVector2Of2Pixels(nowDownsamplePixel, futureDownsamplePixel, downsampleWidth, -1) / timeGap; if (v.magnitude <= moveMaxPixelSpeed) { if (v.magnitude < minV.magnitude) { nextCameraIdTmp = camId; ifGetNextCam = true; minV = v; } } else { if (justOkV > v.magnitude) { justOkV = v.magnitude; nextJustOkCamIdTmp = camId; justOkKeyFrame = i; } } if (ifGetNextCam) { ChangeHintFrameStatus(nextCameraId, false); ChangeHintFrameStatus(nextCameraIdTmp, true); nextCameraId = nextCameraIdTmp; nextKeyFrame = i; reachable = true; selectedDirection = -1; oldFrame = nowFrame; var nextFrame = KeyFrameToFrame(nextKeyFrame); if (nextFrame < nowFrame) { Debug.Log(string.Format("Strange!oldFrame:{0}, nowFrame:{1}, nextFrame:{2}", oldFrame, nowFrame, nextFrame)); } transferSpeed = minV; //ShowImageArrow(); break; } } if (!ifGetNextCam) { ChangeHintFrameStatus(nextCameraId, false); ChangeHintFrameStatus(nextJustOkCamIdTmp, true); nextCameraId = nextJustOkCamIdTmp; nextKeyFrame = justOkKeyFrame; reachable = false; selectedDirection = -1; oldFrame = nowFrame; transferSpeed = minV; } }
//The main view changes the selected camera ID private void ChangeSelectedCamId(int direction) { //It is consistent with the currently selected camera ID int totalKeyFrame = opticalFlowCamerasController.smoothPath[0].Count; var nowFrame = (int)videoPlayer.frame; var totalFrame = videoPlayer.frameCount; Debug.Log("nowFrame: " + nowFrame); Debug.Log("totalKeyFrame: " + totalKeyFrame); Debug.Log("totalFrame: " + totalFrame); int beginKeyFrame = Mathf.Min((int)((float)nowFrame * totalKeyFrame / totalFrame), totalKeyFrame - 1) + 1; 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); var nowDownsamplePixel = opticalFlowCamerasController.PixelToOriginPixelFloatValue(panelVideoController.EulerAngleToPixel(mainNFOVCamera.transform.eulerAngles), originSize, downsampleSize); bool ifGetNextCam = false; var minV = new Vector2(1e9f, 1e9f); int newNowFrame = (int)videoPlayer.frame; Debug.Log("newNowFrame: " + newNowFrame); int nextCameraIdTmp = 0; for (int i = beginKeyFrame; i < Mathf.Min(totalKeyFrame, beginKeyFrame + maxTransferKeyFrameNum); i++) { int frameNum = KeyFrameToFrame(i) - nowFrame; if (frameNum < 0) { continue; } float timeGap = frameNum / videoPlayer.frameRate; for (int camId = 0; camId < panelVideoController.cameraGroupNum; camId++) { if (nextCameraId == nowCameraId && nowCameraId == camId) { continue; } if (ifCloseCameraWindow != null && ifCloseCameraWindow[camId][i]) { continue; } var path = opticalFlowCamerasController.smoothPath[camId]; var futureDownsamplePixel = path[i]; var v = GetVector2Of2Pixels(nowDownsamplePixel, futureDownsamplePixel, downsampleWidth, direction); if (v.magnitude / timeGap <= moveMaxPixelSpeed) { bool ifOk = false; switch (direction) { case 0: ifOk = v.y < 0; break; case 1: ifOk = v.y > 0; break; case 2: ifOk = v.x < 0; break; case 3: ifOk = v.x > 0; break; } if (ifOk) { if (v.magnitude < minV.magnitude) { nextCameraIdTmp = camId; ifGetNextCam = true; minV = v; } } } } if (ifGetNextCam) { panelVideoController.selectedHintFrames[nextCameraId].gameObject.SetActive(false); panelVideoController.selectedHintFrames[nextCameraIdTmp].gameObject.SetActive(true); nextCameraId = nextCameraIdTmp; nextKeyFrame = i; reachable = true; selectedDirection = direction; oldFrame = nowFrame; var nextFrame = KeyFrameToFrame(nextKeyFrame); if (nextFrame < nowFrame) { Debug.Log(string.Format("Strange!oldFrame:{0}, nowFrame:{1}, nextFrame:{2}", oldFrame, nowFrame, nextFrame)); } ShowImageArrow(); break; } } }