1

我正在寻找我正在制作的这个 lua 脚本的一些帮助。我想使用四元数根据您的鼠标移动/拖动来旋转对象。我将这个库用于我的四元数https://github.com/topameng/CsToLua/。我已经让物体移动了,但是所有的旋转都搞砸了,这里有一个链接到我到目前为止的视频http://img.bcdojrp.net/videos/uploads/2021-03-17%2003- 58-07_Trim.mp4我已经花了好几个小时来查看它,但找不到要更改的内容...感谢您的帮助,谢谢!

function GetCursor()
    local sx, sy = GetActiveScreenResolution()
    local cx, cy = GetNuiCursorPosition()
    local cx, cy = (cx / sx) + 0.008, (cy / sy) + 0.027
    return cx, cy
end
if dragging then
    -- this is the screen position 
    local intx, inty = GetCursor()
    local deltaMove = {
        ['x'] = intx-previousMousePosition.x,
        ['y'] = inty-previousMousePosition.y
    }
    local deltaRotationQuaternion = Quaternion.Euler(deltaMove.y * 40, deltaMove.x * 40, 0)
    local x,y,z,w = GetEntityQuaternion(curObject)
    local quatNew = deltaRotationQuaternion.__mul(Quaternion.New(x,y,z,w), deltaRotationQuaternion)
    local valX, valY, valZ, valW = quatNew.x, quatNew.y, quatNew.z, quatNew.w
    SetEntityQuaternion(curObject, valX, valY, valZ, valW)

    --cube.quaternion.multiplyQuaternions(deltaRotationQuaternion, cube.quaternion);
    previousMousePosition.x = intx
    previousMousePosition.y = inty
else
    previousMousePosition = {
        ['x'] = 0,
        ['y'] = 0
    }
end
4

0 回答 0