统一 - 反向变换欧拉角,因此顺时针计数吗?

发布于 2025-02-08 07:33:43 字数 1237 浏览 3 评论 0原文

我正在做某种鸡蛋计时器的东西...您可以在其中旋转时钟输入分钟。但是,transform.eulerangles的解决方法是错误的:

”“在此处输入图像描述”

但是我需要这样做:

“在此处输入映像”

这样我就可以通过将数字除以6来轻松地获得我的分钟...但是我不能以某种方式弄清楚,如何将其翻转。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;

public class Test3 : MonoBehaviour
{
    [SerializeField] RectTransform rectTransform;
    int[] snapValues = new int[13]{0,30,60,90,120,150,180,210,240,270,300,330,360};
    public void Drag()
    {
        var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(rectTransform.anchoredPosition);
        var angle = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);

        var nearest = snapValues.OrderBy(x => Mathf.Abs(x - transform.eulerAngles.z)).First();

        print(transform.eulerAngles.z);

    }
}

I'm making some sort of a egg timer thing... where you can input your minutes by rotating the clock. transform.Eulerangles however goes the wrong way around:

enter image description here

But I need it to go this way around:

enter image description here

So I can can easily get my minutes by dividing the numbers by 6... but I can somehow not figure it out, how to flip it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;

public class Test3 : MonoBehaviour
{
    [SerializeField] RectTransform rectTransform;
    int[] snapValues = new int[13]{0,30,60,90,120,150,180,210,240,270,300,330,360};
    public void Drag()
    {
        var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(rectTransform.anchoredPosition);
        var angle = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);

        var nearest = snapValues.OrderBy(x => Mathf.Abs(x - transform.eulerAngles.z)).First();

        print(transform.eulerAngles.z);

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2025-02-15 07:33:43

要翻转结果(即360 = 0,180 = 180,0 = 360),您可以从360中减去它:

var angle = 360 - ( Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg );

To flip the result (i.e. 360 = 0, 180 = 180, 0 = 360), you can just subtract it from 360:

var angle = 360 - ( Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文