darhal Posted May 13, 2015 Share Posted May 13, 2015 Hi as the title said I want the picture to face the cursor here is my code showCursor(true) angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) x, y, _, _, _= getCursorPosition ( ) --local angle = math.deg (math.atan2 ((x), (y))) angle = math.atan2(y - 100/2, x - 100/2) angle = math.deg(angle) if(angle < 0) then angle = 360 - (-angle) end outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle+90, 0, 0, tocolor(255, 255, 255, 255), true) end ) Link to comment
darhal Posted May 14, 2015 Author Share Posted May 14, 2015 OMG no one know this calculation Guys I need helpp ! the image dont rotate Link to comment
MTA Team botder Posted May 14, 2015 MTA Team Share Posted May 14, 2015 You have to calculate the angle for the pictures, not the cursor. Link to comment
darhal Posted May 15, 2015 Author Share Posted May 15, 2015 show me an example at least Link to comment
MTA Team botder Posted May 15, 2015 MTA Team Share Posted May 15, 2015 https://wiki.multitheftauto.com/wiki/FindRotation angle = findRotation(cursorX, cursorY, imageX, imageY) Link to comment
darhal Posted May 15, 2015 Author Share Posted May 15, 2015 showCursor(true) angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) x, y, _, _, _= getCursorPosition ( ) angle = findRotation(x, y, 358, 276) outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle, 0, 0, tocolor(255, 255, 255, 255), true) end ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end Dont even rotate ! Link to comment
Walid Posted May 15, 2015 Share Posted May 15, 2015 Try this untested function findPictureAngle(picX,picY) local cursor = isCursorShowing () if cursor then local screenx, screeny, worldx, worldy, worldz = getCursorPosition() local imageRot = math.atan2 (( worldx - screenx ), (worldy - screeny)) local X = picX - screenx local Y = picY - screeny local Z = math.atan2(X,Y) local angle = Z - imageRot return math.deg(angle) end return false end Link to comment
TAPL Posted May 15, 2015 Share Posted May 15, 2015 showCursor(true) angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) x, y, _, _, _= getCursorPosition ( ) angle = findRotation(x, y, 358, 276) outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle, 0, 0, tocolor(255, 255, 255, 255), true) end ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end Dont even rotate ! It because getCursorPosition return the position in relative (from 0 to 1). Try this: showCursor(true) local sx, sy = guiGetScreenSize() angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) local x, y = getCursorPosition() angle = findRotation(x*sx, y*sy, 358, 276) outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle, 0, 0, tocolor(255, 255, 255, 255), true) end ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end Link to comment
darhal Posted May 15, 2015 Author Share Posted May 15, 2015 showCursor(true) angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) x, y, _, _, _= getCursorPosition ( ) angle = findRotation(x, y, 358, 276) outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle, 0, 0, tocolor(255, 255, 255, 255), true) end ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end Dont even rotate ! It because getCursorPosition return the position in relative (from 0 to 1). Try this: showCursor(true) local sx, sy = guiGetScreenSize() angle = 0 addEventHandler("onClientRender", root, function() --showCursor(true) local x, y = getCursorPosition() angle = findRotation(x*sx, y*sy, 358, 276) outputChatBox(angle) dxDrawImage(358, 100, 100, 100, ":CUPvehicles/files/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawImage(140, 276, 100, 100, ":CUPvehicles/files/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(537, 276, 100, 100, ":CUPvehicles/files/lights.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(358, 276, 100, 100, ":CUPvehicles/files/switch.png", angle, 0, 0, tocolor(255, 255, 255, 255), true) end ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end WOW thx a lot TAPL Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now