Ejemplo n.º 1
0
        /////////////////////////////////////////////
        void Start()
        {
            mInput = GameManager.GetInstance().GetInputManager();
            if (!mInput || mAlternativeCameras.Count == 0 /*|| mRearCamera == null*/)
            {
                Debug.LogWarning("CameraManager: Error in manager configuration");
                enabled = false;
            }
            //Notify is it is a fps camera
            bool isFps = mAlternativeCameras[mActiveCamera].IsFirstPerson();

            mOnCameraChangedIsFPS.Invoke(isFps);
        }
Ejemplo n.º 2
0
 public void OnCameraMove(InputAction.CallbackContext context)
 {
     if (context.phase == InputActionPhase.Performed)
     {
         CameraEvent?.Invoke(context.ReadValue <Vector2>());
     }
 }
        protected override void OnUpdateCamera()
        {
            float moveStep = moveSpeed * Time.deltaTime;

            basePosition = Vector3.MoveTowards(basePosition, target.transform.position, moveStep);
            Vector3 position = basePosition + positionOffset;

            targetCamera.transform.position = position;

            switch (lookAtType)
            {
            case LookAtType.Target:
                LookAtTarget();
                break;

            case LookAtType.BasePosition:
                LookAtBasePosition();
                break;

            default:
                Debug.LogError(lookAtType);
                break;
            }

            if (isMoving == true && basePosition.magnitude < freeMovement)
            {
                isMoving = false;
                onMoveEnd.Invoke(this);
            }
            else if (isMoving == false && basePosition.magnitude > freeMovement)
            {
                isMoving = true;
                onMoveStart.Invoke(this);
            }
        }
Ejemplo n.º 4
0
 public void InvokeCameraEvent(JCIW.Data.Drawing.ImageSource imageSource)
 {
     if (CameraEvent != null && ByteArrayLastImageCaptured != null)
     {
         imageSource.Image = ByteArrayLastImageCaptured;
         CameraEvent.Invoke(imageSource, EventArgs.Empty);
     }
 }
Ejemplo n.º 5
0
        private void Run()
        {
            CameraCoordinator.Open(0);
            while (isRunning)
            {
                if (!CameraCoordinator.IsOpened())
                {
                    break;
                }

                //Mat img = new Mat(@"D:\ProjectData\MonitorMysticLight\Gaming\MAG271VCR\MAG271VCR_device.png");
                Mat img = new Mat();
                if (CameraCoordinator.Read(img))
                {
                    var img_dispaly = OpenCvSharp.Extensions.BitmapSourceConverter.ToBitmapSource(img);
                    img_dispaly.Freeze();
                    CameraEvent?.Invoke(img_dispaly);
                    //Thread.Sleep(1000);
                }
            }
            CameraCoordinator.Release();
        }
Ejemplo n.º 6
0
    public Coroutine SwitchCamera(bool ortho)
    {
        StopAllCoroutines();
        Camera newCamera = ortho ? orthoCam : perspectiveCam;

        if (!ortho)
        {
            perspectiveRig.GetComponent <MixedAutoCam>().YRotation = orthoCam.transform.rotation.eulerAngles.y;
        }

        Matrix4x4  oldMatrix   = activeCamera.projectionMatrix;
        Matrix4x4  newMatrix   = newCamera.projectionMatrix;
        Vector3    newPosition = ortho ? orthoPos : perspectivePos;
        Quaternion newRotation = ortho ? orthoRot : perspectiveRot;

        newCamera.transform.position = activeCamera.transform.position;
        newCamera.transform.rotation = activeCamera.transform.rotation;
        (ortho ? perspectiveRig : orthoRig).SetActive(false);
        (ortho ? orthoRig : perspectiveRig).SetActive(true);
        activeCamera = newCamera;
        onSwitchCamera.Invoke(newCamera);
        return(StartCoroutine(LerpFromTo(oldMatrix, newMatrix, activeCamera.transform.localPosition,
                                         newPosition, activeCamera.transform.localRotation, newRotation, defaultTransitionDuration)));
    }
Ejemplo n.º 7
0
        void Update()
        {
            switch (_state)
            {
            case State.Setup:
                if (_moving)
                {
                    if (_progress < 1f && _startTransform != _targetView.transform)
                    {
                        _progress += _speed * Time.deltaTime;

                        // Lerp position
                        transform.position = Vector3.Slerp(_startTransform.position, _targetView.transform.position, _progress);

                        // Lerp Rotation
                        transform.rotation = Quaternion.Slerp(_startTransform.rotation, _targetView.transform.rotation, _progress);

                        Camera.main.fieldOfView = Mathf.Lerp(_startFOV, _targetView.fov, Mathf.Sqrt(_progress));
                    }
                    else
                    {
                        _moving            = false;
                        _startTransform    = _targetView.transform;
                        transform.position = _startTransform.position;
                        transform.rotation = _startTransform.rotation;
                        onCompleteLerp.Invoke();
                    }
                }
                break;


            case State.Live:
                if (!_paused)
                {
                    // Check each mapped key for input
                    foreach (KeyCode key in _KeyToView.Keys)
                    {
                        if (Input.GetKeyDown(key) && CameraBlocker.Instance.GetComponent <Fadeable>().NotFading)
                        {
                            if (_controlMode != CameraControlMode.Manual)
                            {
                                _controlMode = CameraControlMode.Manual;
                            }
                            StartFade();
                            _targetAngle = _KeyToView[key];
                        }
                    }

                    UpdateAllAngles();

                    // Move camera to current angle position
                    transform.position = _currentAngle.pos;
                    transform.rotation = _currentAngle.rot;

                    // Update transition timer
                    if (_controlMode == CameraControlMode.Random)
                    {
                        if (_transitionTimer <= 0f)
                        {
                            _transitionTimer = _liveModeTransitionFreq;
                            _targetAngle     = -1;
                            StartFade();
                        }
                        else
                        {
                            _transitionTimer--;
                        }
                    }

                    if (CameraBlocker.Instance.GetComponent <Fadeable>().DoneUnfading)
                    {
                        UIManager.Instance.HideMenu(CameraBlocker.Instance);
                        if (_targetAngle == -1)
                        {
                            ChangeAngle();
                        }
                        else
                        {
                            ChangeAngle(_targetAngle);
                        }
                    }

                    // Check if camera is out of range
                    float distToPlayer = Vector3.Distance(transform.position, PlayerMovement.Instance.transform.position);
                    if (distToPlayer > _resetDistance && !CameraBlocker.Instance.GetComponent <Fadeable>().Busy)
                    {
                        StartFade();
                    }
                }
                break;

            case State.Free:

                // Rotate camera
                Vector3 d    = InputManager.Instance.MouseDelta;
                Vector3 old  = transform.rotation.eulerAngles;
                bool    slow = Input.GetAxisRaw("Slow") != 0f;
                old.z  = 0f;
                old.x += -d.y * _rotateSensitivity * (slow ? 0.05f : 1f);
                old.y += d.x * _rotateSensitivity * (slow ? 0.05f : 1f);
                transform.rotation = Quaternion.Euler(old);

                // Translate camera
                float forward = Input.GetAxisRaw("Forward") * _moveSensitivity * (slow ? 0.05f : 1f);
                float up      = Input.GetAxisRaw("Up") * _moveSensitivity * (slow ? 0.05f : 1f);
                float right   = Input.GetAxisRaw("Right") * _moveSensitivity * (slow ? 0.05f : 1f);
                transform.Translate(new Vector3(right, up, forward));

                break;
            }

            if (_doSway)
            {
                // Calculate sway
                float bx = ((Mathf.PerlinNoise(0f, Time.time * _swaySpeed) - 0.5f)) * _baseSway * Camera.main.fieldOfView / DEFAULT_FOV;
                float by = ((Mathf.PerlinNoise(0f, (Time.time * _swaySpeed) + 100f)) - 0.5f) * _baseSway * Camera.main.fieldOfView / DEFAULT_FOV;

                // Do sway
                transform.Rotate(bx, by, 0f);
            }
        }
Ejemplo n.º 8
0
 private void InvokeCameraEvent()
 {
     onEventRaised?.Invoke(currentCamera);
 }