Unity3D 四元数摄像机空间旋转模型(展示台)

想做一个展示台
参考: https://gamedev.stackexchange.com/questions/61381/rotate-an-object-smoothly-on-the-y-axis-in-unity
四元数是可以相乘的

在这里插入图片描述

if (Input.GetMouseButton(0))
{
    var d = (target.position - m_MainCameraTrans.position).magnitude;
    //transform.DOKill();
    m_X -= Input.GetAxis("Mouse X") * 8 * d;
    m_Y += Input.GetAxis("Mouse Y") * 4 * d;

}

Quaternion newRotation = Quaternion.AngleAxis(m_X, Vector3.up);
newRotation = Quaternion.AngleAxis(m_Y, m_MainCameraTrans.right) * newRotation;

//transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * Speed * 10);
if (newRotation != transform.rotation)
{
    transform.DORotateQuaternion(newRotation, 0.4f);
}

if (Input.GetMouseButton(2))
{
   var d = (target.position - m_MainCameraTrans.position).magnitude;
   var x = Input.GetAxis("Mouse X") * 0.02f * d;
   var y = Input.GetAxis("Mouse Y") * 0.02f * d;

   transform.position += m_MainCameraTrans.up * y;
   transform.position += m_MainCameraTrans.right * x;
}

CameraController.cs

var d = (target.position - transform.position).magnitude;
z -= Input.GetAxis("Mouse ScrollWheel") * d;
// far near limit
z = Mathf.Clamp(z, distanceMin, distanceMax);
Vector3 position = m_TargetOriginPos + -transform.forward * z;

// transform.position = position;
// smoothing
if (Vector3.Distance(position, transform.position) > 0.01f)
{
    transform.DOMove(position, 0.4f);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值