Jump to content

dxDrawImage rotation problem


Xwad

Recommended Posts

Posted (edited)

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
  • Moderators
Posted

Images are broken, can you reupload them somewhere like gyazo or imgur ? (Well, somewhere where it's actually working ?)

  • Moderators
Posted

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 ?

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

  • Moderators
Posted

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

Posted

Then could you upload the body.png and turret.png? It looks to me like the body.png already has the turret on it, thus it looks like it's duplicating.

To change the pivot point, look at dxDrawImage. You'll want to change rotationCenterOffsetX and rotationCenterOffsetY to find the pivot point you want.

Posted

I already found the pivot point. And no, i already said: the problem is not with the image. I replaced all images with another images and its still duplicated. So im 100% sure that the problem is not with the image

Posted

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 

  • Moderators
Posted
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:

Posted

Dealman you are right! now its working! i added replaced the for, loop with getPedOccupiedVehicle and getElementModel. Thanks Citizen and Dealman now my script is totaly working:D

Posted

ohh i just see your post now citizen. I made it very similar, i just added getElementModel becaouse i want that the image will only appear if the player enters the rhino:D

  • Moderators
Posted

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.

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