照相機根據觸摸圍繞目標旋轉

Transform m_Rounder = Camera.main.transform;
Transform m_Center = m_TargetXingqiu.transform;
//當前觸摸的座標與上一個觸摸座標的偏移量
Vector2 offsetPos = m_TouchCurPos - m_TouchPrePos;			//圍繞半徑
float radius = (m_Rounder.position - m_Center.position).magnitude;
//相機到目標的向量
Vector3 camRelativeToTarget = Vector3.Normalize(m_Rounder.position - m_Center.position);
//觸摸爲照相機座標,將此座標轉爲世界座標
Vector3 touchCurWorldPos = m_Rounder.localToWorldMatrix.MultiplyPoint(new Vector3(m_TouchCurPos.x, m_TouchCurPos.y, 0f));
Vector3 touchPreWorldPos = m_Rounder.localToWorldMatrix.MultiplyPoint(new Vector3(m_TouchPrePos.x, m_TouchPrePos.y, 0f));
//觸摸方向向量轉世界向量
Vector3 touchVec = touchCurWorldPos - touchPreWorldPos;
//圍繞的旋轉軸
Vector3 roundAxis = Vector3.Cross(touchVec, camRelativeToTarget);
m_Rounder.RotateAround (m_Center.position, Vector3.Normalize(roundAxis), roundAxis.magnitude*0.1f);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章