Jump to content

qustion


Kenix

Recommended Posts

he wants to create "3D" image that has the same size regardless to distance ftom the player

to create this illusion you need to scale (change size) the image based on the distance from the player, the formila is:

size = (some constant number)/distance

Link to comment
he wants to create "3D" image that has the same size regardless to distance ftom the player

to create this illusion you need to scale (change size) the image based on the distance from the player, the formila is:

size = (some constant number)/distance

no i need that image does not change the size of not depending on the distances.

Link to comment

assuming you using dxDrawImage function, if your image is a square

width = size

height = size

if its a rectangle than for exemple:

width = size*2

height = size

to calculate size you need a constant number (for exemple 50) this number is a size of the imahe, when you are next to it, you will need to experiment with it

wo calculate the distance you need:

x,y,z = world position of the image (get position of the thing the image is attached to)

px,py,pz = getElementPosition(getLocalPlayer())

distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz)

so the formula will be:

size = 50/distance

(you may need to change 50 to something else)

Link to comment
assuming you using dxDrawImage function, if your image is a square

width = size

height = size

if its a rectangle than for exemple:

width = size*2

height = size

to calculate size you need a constant number (for exemple 50) this number is a size of the imahe, when you are next to it, you will need to experiment with it

wo calculate the distance you need:

x,y,z = world position of the image (get position of the thing the image is attached to)

px,py,pz = getElementPosition(getLocalPlayer())

distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz)

so the formula will be:

size = 50/distance

(you may need to change 50 to something else)

  
addEventHandler( "onClientRender", root, 
    function( ) 
    for _, plr in ipairs( getElementsByType( "ped" ) ) do 
        if (getElementData (plr, "zombie") == true and getElementData(plr, "status" ) ~= "dead")  then 
            local Px,Py,Pz = getElementPosition( getLocalPlayer() ) 
            local Zx,Zy,Zz = getElementPosition( plr ) 
            local distance = (getDistanceBetweenPoints3D (Px, Py, Pz, Zx, Zy, Zz)) 
            if (distance < 45) and (distance > 2) then    
                local x, y, z = getPedBonePosition( plr, 8 ) 
                local sX, sY,sZ = getScreenFromWorldPosition( x, y, z+0.7 ) 
                local cx, cy, cz = getCameraMatrix() 
                local ht,hX,hY,hZ,hE  = processLineOfSight(cx, cy, cz,x, y,z,true,true, true, true, true, true,true,true,plr)                                
                if not ht then 
                    if sX then 
                        sizeImg = 20/distance 
                         
                        if getElementData( plr ,"zClass") == 6 then 
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"w.png") 
                    elseif getElementData( plr ,"zClass") == 1 then  
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"wg.png") 
                    elseif getElementData( plr ,"zClass") == 2 then 
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"g.png") 
                    elseif getElementData( plr ,"zClass") == 3 then 
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"y.png") 
                    elseif getElementData( plr ,"zClass") == 4 then 
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"r.png")  
                    elseif getElementData( plr ,"zClass") == 5 then 
                            dxDrawImage(sX,sY,sizeImg,sizeImg,"b.png") 
                            end 
                        end 
                   end 
              end 
          end 
      end 
   end 
) 
  

Link to comment
addEventHandler( "onClientRender", root, 
function() 
    for _, plr in ipairs(getElementsByType("ped", root, true)) do 
    -- first, it's better to loop only through streamed-in elements, not all of them. 
    -- because you can't see other elements anyway. so: getElementsByType("ped", root, true) 
        if (getElementData (plr, "zombie") and getElementData(plr, "status" ) ~= "dead")  then 
            -- local Px,Py,Pz = getElementPosition( getLocalPlayer() ) -- i dont think you need this 
            -- it more logical to use camera position, not player's 
            local cx, cy, cz = getCameraMatrix() 
            local Zx, Zy, Zz = getElementPosition( plr ) 
            local distance = getDistanceBetweenPoints3D (cx, cy, cz, Zx, Zy, Zz) 
            if (distance < 45) and (distance > 2) then    
                local x, y, z = getPedBonePosition( plr, 8 ) 
                local sX, sY = getScreenFromWorldPosition(x, y, z+0.7, 100) -- better add some edge tolerance 
                -- also getScreenFromWorldPosition() returns 2 values, X an Y, no Z 
                if sX then -- check if element is on screen BEFORE checking the line of sight 
                    -- and i dont think you need processLineOfSight, since you're not using 
                    -- any of the data it returns, except to check if something was hit. 
                    -- and there's a lighter function just for that: isLineOfSightClear 
                    if isLineOfSightClear(cx, cy, cz, x, y, z, true, false, false) then 
                    -- also it's better to ignore peds/vehicles, imo 
                        local sizeImg = 20/distance 
                        -- let's say distance is 44, 20/44 is 0.45 which is half a pixel 
                        -- so at that distance your image wont be visible already 
                        -- of course maybe that is what you want 
                        local zClass = getElementData( plr ,"zClass")  
                        -- instead of calling the same function with same parameters 6 times 
                        -- it's better to call it once and store the result, imo 
                        local image = false 
                        -- also if you're only changing the image, i'd put in a variable 
                        -- and use only 1 dxDrawImage (will be easier to edit later) 
                        -- actually, i'd make some table like {[1]="wg.png", [2]="g.png", etc} 
                        if zClass == 6 then image = "w.png" 
                        elseif zClass == 1 then image = "wg.png" 
                        elseif zClass == 2 then image = "g.png" 
                        elseif zClass == 3 then image = "y.png" 
                        elseif zClass == 4 then image = "r.png" 
                        elseif zClass == 5 then image = "b.png" 
                        end 
                        if image then dxDrawImage(sX-sizeImg/2,sY-sizeImg/2,sizeImg,sizeImg, image) end  
                        -- subtract half of the image size from its position to center it at its point 
                    end 
                end 
            end 
        end 
    end 
end     
) 

Link to comment
i need no change resize image in distance(any distance).

I want to size was always the same.

change

local sizeImg = 20/distance 

to size in pixels you want:

local sizeImg = 32 

how hard can that be

Link to comment
i need no change resize image in distance(any distance).

I want to size was always the same.

change

local sizeImg = 20/distance 

to size in pixels you want:

local sizeImg = 32 

how hard can that be

now expanding size I do not know what to do ...

Link to comment

do you understand the difference between 2D and 3D?

on your screens image size doesnt change at all.

you dont want it to scale down to distance, you dont want it to be fixed size, what is it you want?

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