I have this code:
sx, sy = guiGetScreenSize()
movedClip = false
testAngle = 0
function math.rotVecToEular(x, y, z, rot) -- explained on mta wiki
local rotx = math.deg( math.atan2 ( z, (x^2+y^2)^0.5 ) ) % 360
local rotz = math.deg( math.atan2( x, y ) ) % 360
return rotx, rot, rotz
end
addEventHandler("onClientRender", root, function ()
local relX, relY = getCursorPosition()
local cursorX, cursorY = relX * sx, relY * sy
local camX, camY, camZ = getCameraMatrix()
local cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ = getWorldFromScreenPosition(cursorX, cursorY, 20)
hit, hitX, hitY, hitZ, hitElement, normalX, normalY, normalZ = processLineOfSight(camX, camY, camZ, cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ, true, false, false, true, false, true, false, true)
if hit then
testAngle = (testAngle + 1) % 360
angleVectorX, angleVectorY, angleVectorZ = math.rotVecToEular(normalX, normalY, normalZ, testAngle)
angleVectorX = angleVectorX - 90 -- cone look "up" when testAngle = 0
hitX = normalX*0.2 + hitX -- a bit up from a plane
hitY = normalY*0.2 + hitY -- a bit up from a plane
hitZ = normalZ*0.2 + hitZ -- a bit up from a plane
if isElement(movedClip) then
destroyElement(movedClip)
end
movedClip = createObject(1238, hitX, hitY, hitZ, angleVectorX, angleVectorY, angleVectorZ, true)
end
end)
But i need rotation in other axis, like so:
- Need rotation in "Z" axis with ZYX Euler coordinate system.
Script doing that in MTA:
And in blender "X" axis in XYZ Euler angles:
I tried set setElementRotation with 5 argument "ZYX" but it didn't work, like it's swap X and Z angles, not a different coordinate system:
local angX = 0
local angY = 0
local angZ = 0
local modelToRotate = false
sx, sy = guiGetScreenSize()
addEventHandler("onClientRender", root,
function ()
if isCursorShowing() then
if getKeyState("4") then angX = (angX + 1) % 360 end
if getKeyState("5") then angY = (angY + 1) % 360 end
if getKeyState("6") then angZ = (angZ + 1) % 360 end
dxDrawText("X:" .. angX .. " Y:" .. angY .. " Z:" .. angZ, 300, 60)
local relX, relY = getCursorPosition()
local cursorX, cursorY = relX * sx, relY * sy
local camX, camY, camZ = getCameraMatrix()
local cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ = getWorldFromScreenPosition(cursorX, cursorY, 20)
local hit, hitX, hitY, hitZ, hitElement, normalX, normalY, normalZ = processLineOfSight(camX, camY, camZ, cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ, true, false, false, true, false, true, false, true)
if isElement(modelToRotate) then
destroyElement(modelToRotate)
end
modelToRotate = createObject(1238, hitX, hitY, hitZ, 0, 0, 0, true)
setElementRotation(modelToRotate, angX, angY, angZ, "ZYX")
end
end
)
keys 4, 5, 6 for rotation in X, Y, Z axis.
How to rotate a object in Z axis, but to a normal vector from processLineOfSight, like in first attached video?