Moderators IIYAMA Posted September 23, 2015 Moderators Posted September 23, 2015 (edited) This tutorial is not for beginners. This code will successfully find the player scaling factor, to convert the 3D world units to 2D pixels on your monitor. The factor 0.622388530006 is probably a standard, but you never know. Image1 Image2 Image3 Image4 The function that finds this factor. local screenX,screenY = guiGetScreenSize() local scaleFactorBuffer = nil function findScaleFactor () if scaleFactorBuffer then return scaleFactorBuffer else local startX,startY,startZ = getWorldFromScreenPosition ( 0,0, 1 ) local endX,endY,endZ = getWorldFromScreenPosition ( screenX,screenY, 1 ) if startX and endX then scaleFactorBuffer = 1/getDistanceBetweenPoints3D(startX,startY,startZ,endX,endY,endZ) return scaleFactorBuffer end end return false end The set up for the example below: -- the set up -- local imagePosX,imagePosY,imagePosZ = -21.38184, 5.24524, 3.10965 local imageResolution = 1000 ---------------- The example on how to use: addEventHandler("onClientRender",root, function () local scaleFactor = findScaleFactor () if scaleFactor then dxDrawText("scaleFactor: " .. scaleFactor,300,300) -- The scale factor is circa 0.622388530006 (units). local rectangleCenterX,rectangleCenterY = getScreenFromWorldPosition(imagePosX,imagePosY,imagePosZ) if rectangleCenterX and rectangleCenterY then local playerX,playerY,playerZ = getElementPosition(getCamera()) local size = (imageResolution*scaleFactor)/getDistanceBetweenPoints3D(playerX,playerY,playerZ,imagePosX,imagePosY,imagePosZ) dxDrawText("size: " .. size,300,320) dxDrawRectangle(rectangleCenterX+size/2,rectangleCenterY+size/2,size,size,tocolor(0,0,200)) end end end) Edited October 9, 2015 by Guest 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Moderators Citizen Posted October 6, 2015 Moderators Posted October 6, 2015 Can you add screenshots or a gif or a video to see this code in action ? The rEvolution is coming ...
Moderators IIYAMA Posted October 6, 2015 Author Moderators Posted October 6, 2015 Can you add screenshots or a gif or a video to see this code in action ? Sure thing! Image1 Image2 Image3 Image4 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Moderators Citizen Posted October 6, 2015 Moderators Posted October 6, 2015 Nice great job. The rEvolution is coming ...
Moderators IIYAMA Posted October 8, 2015 Author Moderators Posted October 8, 2015 local playerX,playerY,playerZ = getElementPosition(localPlayer) local playerX,playerY,playerZ = getElementPosition(getCamera()) I just saw a little mistake in it or well, it might be more a visual. In the code on top, I took the position of the localPlayer, but the result would be better when you use the position of the camera. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Moderators Citizen Posted October 9, 2015 Moderators Posted October 9, 2015 Replace it in the original post then, people who will come here to get your code will just copy and paste from there and probably won't see your fix above. The rEvolution is coming ...
Moderators IIYAMA Posted October 9, 2015 Author Moderators Posted October 9, 2015 Ah yea, I was worried about losing the votes. But it seems it remains correct. Thx for the reminder. =) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
spoty Posted May 26, 2016 Posted May 26, 2016 do you mayby also know something like this but then for costum map objects?
Moderators IIYAMA Posted May 27, 2016 Author Moderators Posted May 27, 2016 do you mayby also know something like this but then for costum map objects? You have to scale custom objects in you model editor. MTA can't scale Collisions. But if you do not care about collisions, this might help you: https://wiki.multitheftauto.com/wiki/Ge ... oundingBox Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts