opengl 一种将字符旋转到相应输入glm的方法

wj8zmpe1  于 2023-04-20  发布在  其他
关注(0)|答案(1)|浏览(138)

我一直在尝试旋转(并有一个平滑的旋转)字符到相应的用户输入,但我总是有一个问题,我需要知道如何解决它。由于非平滑旋转工作,我试图使一个是顺利的。
我使用的代码:

if (LeftKey == true)
{
        if (RightKey == true)
        {
            PlayerOrientation = 0;
        }
        else
        {
            PlayerOrientation = 45;
        }
}
else
{
        if (RightKey == true)
        {
            PlayerOrientation = -45;
        }
        else
        {
            PlayerOrientation = 0;
        }
    }
}
else if (RightKey == false && LeftKey == true)
{
    if (DownKey == true)
    {
        if (UpKey == true)
        {
            PlayerOrientation = 90;
        }
        else
        {
            PlayerOrientation = 135;
        }
    }
    else
    {
        if (UpKey == true)
        {
            PlayerOrientation = 45;
        }  
        else
        {
            PlayerOrientation = 90;
        }
    }
}
else if (UpKey == false && DownKey == true)
{
    if (LeftKey == true)
    {
        if (RightKey == true)
        {
            PlayerOrientation = 180;
        }
        else
        {
            PlayerOrientation = 135;
        }
    }
    else
    {
        if (RightKey == true)
        {
            PlayerOrientation = -135;
        }
        else
        {
            PlayerOrientation = 180;
        }
    }
}
else if (LeftKey == false && RightKey == true)
{
    if (DownKey == true)
    {
        if (UpKey == true)
        {
            PlayerOrientation = -90;
        }
        else
        {
            PlayerOrientation = -135;
        }
    }
    else
    {
        if (UpKey == true)
        {
            PlayerOrientation = -45;
        }
        else
        {
            PlayerOrientation = -90;
        }
    }
}

if (UpKey == true || DownKey == true || RightKey == true || LeftKey == true)
{
    if (ThePlayerOrientation != PlayerOrientation)
    {
        float difference = (PlayerOrientation - ThePlayerOrientation) / 20;
        thePlayerPos += difference;

        if (PlayerOrientation == thePlayerPos)
        {
            ThePlayerOrientation = PlayerOrientation;
            thePlayerPos = PlayerOrientation;
        }
    }
}

如果有人能帮助我,那将是非常有帮助的。

6ss1mwsb

6ss1mwsb1#

我可能搞错了,但我的理解是,目前当你按下一个键时,你的角色会立即从0度向右旋转到95度,为了改善旋转动画,你可能要考虑设置每秒90度的旋转速度,然后,在每一帧中计算从上一帧开始经过的时间,并将相应的旋转Angular 添加到角色的Angular 。我希望它能回答,如果不能,对不起。PS:xD没看到你11个月前问的

相关问题