// Update is called once per frame
    void Update()
    {
        DrawCameraLine();

        float kh, kv, mh, mv, h, v;

        kh = Input.GetAxis("Horizontal");
        kv = Input.GetAxis("Vertical");

        bool anyMouseButton = Input.GetMouseButton(0) | Input.GetMouseButton(1) | Input.GetMouseButton(2);

        mh = anyMouseButton ? Input.GetAxis("Mouse X") : 0f;
        mv = anyMouseButton ? Input.GetAxis("Mouse Y") : 0f;

        h = kh * kh > mh * mh ? kh : mh;
        v = kv * kv > mv * mv ? kv : mv;

        if (h * h > Mathf.Epsilon || v * v > Mathf.Epsilon)
        {
            transform.position
                = sphericalCoordinates.Rotate(h * rotateSpeed * Time.deltaTime, v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position;
        }

        float sw = -Input.GetAxis("Mouse ScrollWheel");

        if (sw * sw > Mathf.Epsilon)
        {
            transform.position = sphericalCoordinates.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position;
        }

        transform.LookAt(pivot.position);
    }
Exemple #2
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (Input.GetMouseButton(1))
        {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");

            if (Mathf.Abs(h) > Mathf.Epsilon || Mathf.Abs(v) > Mathf.Epsilon)
            {
                float aOffset = h * rotateSpeed * Time.deltaTime;
                float eOffset = v * rotateSpeed * Time.deltaTime;
                cam.position = sphericalCoordinates.Rotate(aOffset, eOffset).ToCartesian() + pivot.position;
            }
        }

        float scroll = (-1f) * Input.GetAxis("Mouse ScrollWheel");

        if (Mathf.Abs(scroll) > Mathf.Epsilon)
        {
            float scrollOffset = scroll * scrollSpeed * Time.deltaTime;
            cam.position = sphericalCoordinates.TranslateRadius(scrollOffset).ToCartesian() + pivot.position;
        }

        cam.LookAt(pivot);
    }
Exemple #3
0
    void Update()
    {
        float kh, kv, mh, mv, h, v;

        // I have manually inverted the controls because I think it makes it more intuitive
        kh = -1 * Input.GetAxis("Horizontal");
        kv = -1 * Input.GetAxis("Vertical");

        bool anyMouseButton = Input.GetMouseButton(0) | Input.GetMouseButton(1) | Input.GetMouseButton(2);

        mh = anyMouseButton ? Input.GetAxis("Mouse X") : 0f;
        mv = anyMouseButton ? Input.GetAxis("Mouse Y") : 0f;

        h = kh * kh > mh * mh ? kh : mh;
        v = kv * kv > mv * mv ? kv : mv;

        if (h * h > .1f || v * v > .1f)
        {
            transform.position = sc.Rotate(h * rotateSpeed * Time.deltaTime, v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position;
        }

        float sw = -Input.GetAxis("Mouse ScrollWheel");

        if (sw * sw > Mathf.Epsilon)
        {
            transform.position = sc.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position;
        }

        transform.LookAt(pivot.position);
    }
    void UpdateMoveCamera()
    {
        _sphericalCoordinate.SetProperties(
            transform.position, 1, 500,
            0, Mathf.PI * 2,
            Mathf.Deg2Rad * _upDownAngleMinMax.x, Mathf.Deg2Rad * _upDownAngleMinMax.y);

        //Mathf.Deg2Rad * _minAngle.x, Mathf.Deg2Rad * _maxAngle.x,

        transform.position = _sphericalCoordinate.toCartesian + _pivotPoint.position;

        if (Mov.x != 0 || Mov.y != 0)
        {
            transform.position = _sphericalCoordinate.Rotate(Mov.x * _speed * Time.deltaTime, Mov.y * _speed * Time.deltaTime).toCartesian + _pivotPoint.position;
        }

        // temporal zoom in, zoom out
        if (_zoom != 0)
        {
            transform.position = _sphericalCoordinate.TranslateRadius(_zoom * Time.deltaTime * _scrollSpeed).toCartesian + _pivotPoint.position;
        }

        //_distanceToPivot = (_camera.transform.position - _pivotPoint.transform.position).magnitude;

        transform.LookAt(_pivotPoint);
    }
Exemple #5
0
 public void CloseUp(float amount)
 {
     if (Mathf.Abs(amount) > Mathf.Epsilon)
     {
         float scrollOffset = amount * scrollSpeed * Time.deltaTime;
         sphericalCoordinates.TranslateRadius(scrollOffset);
         SetCamera();
     }
 }
Exemple #6
0
 private void Zoom()
 {
     f_scrollWheel = Input.GetAxis("Mouse ScrollWheel");
     if (f_scrollWheel * f_scrollWheel > Mathf.Epsilon)
     {
         transform.position =
             sphericalCoordinates.TranslateRadius(f_scrollWheel * scrollSpeed * Time.deltaTime).toCartesian
             + target.position;
     }
 }
Exemple #7
0
    void Update()
    {
        float h, v;

        h = Input.GetAxis("Mouse X");
        v = Input.GetAxis("Mouse Y");

        if (pivot == null)
        {
            return;
        }
        //Debug.Log("Pivot position: " + pivot.position);
        //Debug.Log("Spherical coordinates: " + sc);
        transform.position = sc.Rotate(-h * rotateSpeed * Time.deltaTime, -v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position;

        float sw = -Input.GetAxis("Mouse ScrollWheel");

        if (sw * sw > Mathf.Epsilon)
        {
            transform.position = sc.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position;
        }

        transform.LookAt(pivot.position + cameraAssign);
    }