码迷,mamicode.com
首页 > 其他好文 > 详细

旋转与缩放

时间:2019-07-31 18:40:51      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:new   wan   gdi   限制   transform   差值   stat   旋转   修改   


mouseInput = scaleFactor;

heightWanted -= zoomStep * mouseInput;
distanceWanted -= zoomStep * mouseInput;
}

// Record our mouse input. If we zoom add this to our height and distance.
//记录鼠标滚轮滚动时的变量 并赋值记录
//mouseInput特性:正常状态为0;滚轮前推一格变为+0.1一次,后拉则变为-0.1一次
// Input.GetAxis("Mouse ScrollWheel");
if (Input.touchCount <= 0)
{
mouseInput = Input.GetAxis("Mouse ScrollWheel");

heightWanted -= zoomStep * mouseInput;
distanceWanted -= zoomStep * mouseInput;
}
//print("+++"+mouseInput);

// Make sure they meet our min/max values.
//限制相机高度范围
heightWanted = Mathf.Clamp(heightWanted, min, max);
distanceWanted = Mathf.Clamp(distanceWanted, min, max);
//差值计算,动态修改相机高度值(平滑的变化)
height = Mathf.Lerp(height, heightWanted, Time.deltaTime * zoomSpeed);
distance = Mathf.Lerp(distance, distanceWanted, Time.deltaTime * zoomSpeed);

// Post our result.
//缩放后坐标
zoomResult = new Vector3(0f, height, -distance);
}
//相机视角旋转
if (doRotate)
{
//print("水平" + Input.GetAxis("Horizontal"));
//print("竖直" + Input.GetAxis("Vertical"));
if (Input.touchCount == 1)
{
Touch newTouch1 = Input.GetTouch(0);
//Touch touch = Input.GetTouch(0);
if (Input.touches[0].phase == TouchPhase.Began)
{
oldTouch1 = newTouch1;
//m_screenPos = touch.position;
}

if (Input.touches[0].phase == TouchPhase.Moved)
{
float CX = newTouch1.position.x - oldTouch1.position.x;
float CY = newTouch1.position.y - oldTouch1.position.y;

velocityX += xSpeed * CX * 0.02f * Time.deltaTime;
velocityY += ySpeed * CY * 0.02f * Time.deltaTime;
}
}
if (Input.GetMouseButton(2) || Input.GetMouseButton(0) || Input.GetMouseButton(1))
{
// print("欧拉角"+transform.eulerAngles);
velocityX += xSpeed * Input.GetAxis("Mouse X") * 0.02f;
velocityY += ySpeed * Input.GetAxis("Mouse Y") * 0.02f;
}
rotationYAxis += velocityX;
rotationXAxis -= velocityY;
if (rotationXAxis >= 90)
{
rotationXAxis = 90;
}
else if (rotationXAxis <= -90)
{
rotationXAxis = -90;
}
}
Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
Quaternion rotation = toRotation;
Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
//相机跟随
Vector3 position = rotation * negDistance + target.position;
//改变相机Rotation,从而旋转相机
transform.rotation = rotation;



//将缩放后的坐标作为相机的当前坐标位置
transform.position = position;
velocityX = Mathf.Lerp(velocityX, 0, Time.deltaTime * smoothTime);
velocityY = Mathf.Lerp(velocityY, 0, Time.deltaTime * smoothTime);


}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
//限制相机转动角度
return Mathf.Clamp(angle, min, max);
}

public void InitPoint()
{
heightWanted = max;
distanceWanted = max;
}

public void InitReturn(float a, float b)
{
heightWanted = a;
distanceWanted = b;
}
public Vector3 Position;//当前摄像机的位置
public Vector3 Rotation;//当前摄像机的角度

public bool IsInit = false;

--------------------- 

旋转与缩放

标签:new   wan   gdi   限制   transform   差值   stat   旋转   修改   

原文地址:https://www.cnblogs.com/liyanyan665/p/11278063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!