【问题标题】:How can I use sin and cos for rotation?如何使用 sin 和 cos 进行旋转?
【发布时间】:2015-02-20 18:38:17
【问题描述】:

好的,这是我的代码:

float temp1 = Mathf.Sin(Input.mousePosition.x - Screen.width / 2);
float temp2 = Mathf.Cos(Input.mousePosition.y - Screen.height / 2);
Camera.mainCamera.transform.parent.transform.Rotate(temp1,temp2,0);

因此,我尝试根据鼠标与相机父级之间的角度旋转相机的父级。除了我做错了什么,有人可以帮帮我吗?

提前致谢!

【问题讨论】:

  • 嗯,你可能需要在减法周围加上括号。除法具有更高的优先级。
  • 好的,我这样做了,但现在它转向完全相反的方向
  • 1) 怀疑你想要float angle = arctan2f(Input.mousePosition.y - Screen.height / 2, Input.mousePosition.x - Screen.width / 2); (Change radians to degrees if needed) Camera.mainCamera.transform.parent.transform.Rotate(angle);。但这不在我的wheelhouse 范围内。
  • 建议在帖子中添加标签Unity3D而不是标题。

标签: unity3d trigonometry


【解决方案1】:
float temp1 = Mathf.Cos(  (Input.mousePosition.x - Screen.width) / 2 );
float temp2 = Mathf.Sin( -(Input.mousePosition.y - Screen.height) / 2);
Camera.mainCamera.transform.parent.transform.Rotate(temp1, temp2, 0);

【讨论】:

  • 它仍然在随机方向转动,你知道为什么吗?
  • 因为 x 和 y 是从左上角开始测量的?这只是我的猜测。
  • 仔细看,我发现您可能也将 sin() 和 cos() 颠倒了。
  • code float temp1 = Mathf.Cos( (Input.mousePosition.x - Screen.width) / 2 ); float temp2 = Mathf.Sin( (Screen.height - Input.mousePosition.y) / 2); Camera.mainCamera.transform.parent.transform.Rotate(temp1, temp2, 0);
  • 我不知道如何使用该旋转功能,但我看到了另一个具有 (y, x) 的链接。所以颠倒 temp1 和 temp2 的值。
猜你喜欢
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多