Jump to content

Rotating to face a point


darhal

Recommended Posts

Posted

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 
) 
  

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

OMG no one know this calculation Guys I need helpp ! the image dont rotate

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

show me an example at least

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted
  
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 !

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

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 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
  
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 

CiTLh.png
Posted
  
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 :D

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...