Rotate Camera around Focus Point

Hi,

I would like to add Rotation , Pan, Zoom via touch to my camera. I made Rotation work but i would like to rotate the camera around a point thats in front of the camera, a focus point like on a real camera.

how can i do this?

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class MoveCamera : MonoBehaviour
{
    // FOR TESTING

    public Text txt;
    public Text txttwo;

    //
    // VARIABLES
    //

    //private Vector3 fingerOne;
    //private Vector3 fingerTwo;

    //private Vector3 fingerOneStart;
    //private Vector3 fingerTwoStart;
   
    //private Vector3 fingerOneCurrent;
    //private Vector3 fingerTwoCurrent;

    private int fingerCount;

    public float turnSpeed = 1f;        // Speed of camera turning when mouse moves in along an axis
    public float panSpeed = 1f;        // Speed of the camera when being panned
    public float zoomSpeed = 1f;        // Speed of the camera going back and forth

    private Vector3 firstpoint; //change type on Vector3
    private Vector3 secondpoint;

    private float xAngle = 0f; //angle for axes x for rotation
    private float yAngle = 0f;
    private float xAngTemp = 0f; //temp variable for angle
    private float yAngTemp = 0f;



    //
    // Start
    //

    void Start()
    {
        txt.text = " X ";
        txttwo.text = " X ";

        fingerCount = 0;


        //Initialization our angles of camera
        xAngle = 0f;
        yAngle = 0f;
        this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0f);

    }


    //
    // UPDATE
    //

    void Update()
    {

        // TOUCH RECOGNITION
        fingerCount = 0;

        foreach (Touch touch in Input.touches)
        {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
            {
                fingerCount++;
            }
        }


        if (fingerCount == 1)
        {
            txt.text = " 1 ";
            //Touch Start
            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                firstpoint = Input.GetTouch(0).position;
                xAngTemp = xAngle;
                yAngTemp = yAngle;
            }

            //Move finger by screen
            if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                secondpoint = Input.GetTouch(0).position;
               
                //Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
                xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 180f * turnSpeed / Screen.width;
                yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 90f * turnSpeed / Screen.height;

                //Rotate camera
                txttwo.text = " Rotating ";
                this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0f) * Quaternion.AngleAxis(30, Vector3.up);
            }
        }


        if (fingerCount == 2)
        {
            //PAN/Zoom
        }




    }
}
1 Like