Jump to content

dxDrawImage rotation problem


Xwad

Recommended Posts

Hi i made a script whitch creates a dxDrawImage. this dxDrawImage will rotate to that position where the tanks turret is looking at. my problem is that the image is always rotating to the opposite side.. The other problem is that its creating 2 images.. One image is rotating and the other image is just staying and i want to remove that. here are some pictures. I hope you understand me and you can help me.. Thanks.

client.lua

  
function renderDisplay ( ) 
    dxDrawImage ( screenWidth/2 + 480, screenWidth/2 - 130, 100, 160, 'body.png', 0, 0 ) 
    local vehicles = getElementsByType ( "vehicle" ) 
    for vehicleKey, veh in ipairs(vehicles) do 
     local x, y = getVehicleTurretPosition ( veh )  
    x = math.deg ( x ) 
    y = math.deg ( y ) 
    dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 ) 
end 
end 
  
  
  
function show() 
local vehicle = getPedOccupiedVehicle(localPlayer) 
local id = getElementModel ( vehicle ) 
if id == 432 then 
addEventHandler("onClientRender", root, renderDisplay) 
end 
end 
addEventHandler("onClientVehicleEnter", root, show) 
  
function hide() 
local vehicle = getPedOccupiedVehicle(localPlayer) 
local id = getElementModel ( vehicle ) 
if id == 432 then 
removeEventHandler("onClientRender", root, renderDisplay) 
end 
end                                                                     
addEventHandler("onClientVehicleExit", root, hide) 
  

OPOEN THE PICTURES TO SEE FULL RESOLUTION

http://imgur.com/G3jkTnD

G3jkTnD.jpg

http://imgur.com/0nSjdkE

0nSjdkE.jpg

Edited by Guest
Link to comment
  • Moderators

Wow this looks pretty cool, would like to see it when it's done :)

For the rotation I guess calculating the degree rotation of the opposite radian rotation would do the trick. (so x = math.deg( -x ) or using -x in dxDrawImage):

(I renamed x to rx just to avoid confusion)

function renderDisplay ( ) 
    dxDrawImage ( screenWidth/2 + 480, screenWidth/2 - 130, 100, 160, 'body.png', 0, 0 ) 
    local vehicles = getElementsByType ( "vehicle" ) 
    for vehicleKey, veh in ipairs(vehicles) do 
        local rx, _ = getVehicleTurretPosition ( veh ) 
        rx = math.deg ( -rx ) -- Here i'm calculating the oposite by doing '-rx' 
        dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 ) 
    end 
end 

For the rotation pivot, edit the turret.png so the center of the entire image is placed where you want the rotation pivot to be.

For the duplicated turret image, I guess that body.png does have the turret already which have to be removed using photoshop or something.

If not, can send us both images so I can test it on my side ?

Link to comment
function renderDisplay ( )

dxDrawImage ( screenWidth/2 + 480, screenWidth/2 - 130, 100, 160, 'body.png', 0, 0 )

local vehicles = getElementsByType ( "vehicle" )

for vehicleKey, veh in ipairs(vehicles) do

local rx, _ = getVehicleTurretPosition ( veh )

rx = math.deg ( -rx ) -- Here i'm calculating the oposite by doing '-rx'

dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 )

end

end

Your code is working!:D Now the image is rotating to the right direction. Thanks!

For the rotation pivot, edit the turret.png so the center of the entire image is placed where you want the rotation pivot to be.

Yeah i already did that, and its working.

For the duplicated turret image, I guess that body.png does have the turret already which have to be removed using photoshop or something.

If not, can send us both images so I can test it on my side ?

No there's no problem in the image file. It seems that the problem is maybe in the code..:/ So the turret.png is still duplicated:// Any ideas?

Link to comment
  • Moderators

If you only have the exact code you pasted, then that's impossible that there is a duplicate.

So maybe you did another test somewhere else in the resource or another resource test. Maybe you tried a guiCreateStaticImage somewhere ?

Try to stop the resource where this code is, if it's still there, then you know you have to search in another (test ?) resource. If it disapears, then you know you can focus on files from that resource only.

It's time to investigate : p

Link to comment

Then it's probably because of this for loop;

for vehicleKey, veh in ipairs(vehicles) do 
     local x, y = getVehicleTurretPosition ( veh ) 
    x = math.deg ( x ) 
    y = math.deg ( y ) 
    dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 ) 
end 

Link to comment
  • Moderators
Then it's probably because of this for loop;
for vehicleKey, veh in ipairs(vehicles) do 
     local x, y = getVehicleTurretPosition ( veh ) 
    x = math.deg ( x ) 
    y = math.deg ( y ) 
    dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 ) 
end 

OMG ! How did I miss that >< You are totally right, I litteraly didn't see the loop ...

function renderDisplay ( ) 
    dxDrawImage ( screenWidth/2 + 480, screenWidth/2 - 130, 100, 160, 'body.png', 0, 0 ) 
    local veh = getPedOccupiedVehicle( localPlayer ) 
    local rx, _ = getVehicleTurretPosition ( veh ) 
    rx = math.deg ( -rx ) 
    dxDrawImage ( screenWidth/2 + 504, screenWidth/2 - 155, 50, 130, 'turret.png', x, 0 ) 
end 

Here you go, thanks Dealman :wink:

Link to comment
  • Moderators

You are already checking it before doing the addEventHandler so if the image is drawn, then it means that you already passed that check. By the way if you do the check in the renderDisplay() function, then you don't even need the show() and add() functions anymore.

Link to comment

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...