旋转与缩放

Posted liyanyan665

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了旋转与缩放相关的知识,希望对你有一定的参考价值。


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;

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

以上是关于旋转与缩放的主要内容,如果未能解决你的问题,请参考以下文章

Python图像处理丨图像缩放旋转翻转与图像平移

UIImageView 手势(缩放、旋转)问题

Zbrush教程:怎样位移,缩放和旋转

如何使用ZBrush中的位移、旋转和缩放功能

旋转与缩放

UIGesture 缩放与旋转手势