相机围绕目标旋转

来源:互联网 发布:javascript new关键字 编辑:程序博客网 时间:2024/06/15 19:21
  1. Transform m_Rounder = Camera.main.transform;  
  2. Transform m_Center = m_TargetXingqiu.transform;  
  3. //当前触摸的坐标与上一个触摸坐标的偏移量  
  4. Vector2 offsetPos = m_TouchCurPos - m_TouchPrePos; //围绕半径  
  5. float radius = (m_Rounder.position - m_Center.position).magnitude;  
  6. //相机到目标的向量  
  7. Vector3 camRelativeToTarget = Vector3.Normalize(m_Rounder.position - m_Center.position);  
  8. //触摸为照相机坐标,将此坐标转为世界坐标  
  9. Vector3 touchCurWorldPos = m_Rounder.localToWorldMatrix.MultiplyPoint(new Vector3(m_TouchCurPos.x, m_TouchCurPos.y, 0f));  
  10. Vector3 touchPreWorldPos = m_Rounder.localToWorldMatrix.MultiplyPoint(new Vector3(m_TouchPrePos.x, m_TouchPrePos.y, 0f));  
  11. //触摸方向向量转世界向量  
  12. Vector3 touchVec = touchCurWorldPos - touchPreWorldPos;  
  13. //围绕的旋转轴  
  14. Vector3 roundAxis = Vector3.Cross(touchVec, camRelativeToTarget);  
  15. m_Rounder.RotateAround (m_Center.position, Vector3.Normalize(roundAxis), roundAxis.magnitude*0.1f);  
原创粉丝点击