Jump to content

Rendertarget-Radar Problem


Karuzo

Recommended Posts

Hey Guys,

so i tried to rotate my radar using rendertargets, but that just doesn't want to be how i want it.

It rotates really awkward and i don't know why.

Looks like this:

8pW7ZIT.png

I want that it just rotates normally between the rendertarget.

  
  
--Created rendertarget 
  
  
    addEventHandler("onClientRender",root, 
        function( ) 
            showPlayerHudComponent( "all", false ) 
            showPlayerHudComponent("crosshair", true) 
            local px ,py, pz = getElementPosition( localPlayer ) 
            local playerZone =  getZoneName( px ,py, pz )     
            local mapX = px / ( 6000 / 6000 ) + ( 6000 / 2 ) - ( width  / 2 ) 
            local mapY = py / ( -6000 / 6000 ) + ( 6000 / 2 ) - ( height  / 2 ) 
            local cx,cy,cz,tx,ty,tz = getCameraMatrix( ) 
            local rotation = findRotation( cx,cy,tx,ty ) 
            if rendertar then 
            dxSetRenderTarget(rendertar) 
            dxDrawImageSection( 0, 0, width, height, mapX, mapY, width , height , "map.jpg", rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ) 
            dxSetRenderTarget() 
            else 
                outputChatBox(rendertar) 
            end 
            dxDrawImage(posX, screeny - posY, width, height, rendertar) 
            dxDrawImage( posX + width / 2, screeny - posY + height / 2, 10, 10, "files/me.png" ) 
  
    function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) 
    if t < 0 then 
        t = t + 360 
    end 
    return t 
end 
  
end) 

Regards,

KRZO

Link to comment

Try to use something like this. (not tested)

alse use .png's for transparency.

         
 local function getCameraRotation () 
        px, py, pz, lx, ly, lz = getCameraMatrix() 
        local rotz = 6.2831853071796 - math.atan2 ( ( lx - px ), ( ly - py ) ) % 6.2831853071796 
        local rotx = math.atan2 ( lz - pz, getDistanceBetweenPoints2D ( lx, ly, px, py ) ) 
        --Convert to degrees 
        rotx = math.deg(rotx) 
        rotz = math.deg(rotz)       
        return rotz 
    end 
      
    --Created rendertarget 
      
      
        addEventHandler("onClientRender",root, 
            function( ) 
                showPlayerHudComponent( "all", false ) 
                showPlayerHudComponent("crosshair", true) 
                local px ,py, pz = getElementPosition( localPlayer ) 
                local playerZone =  getZoneName( px ,py, pz )     
                local mapX = px / ( 6000 / 6000 ) + ( 6000 / 2 ) - ( width  / 2 ) 
                local mapY = py / ( -6000 / 6000 ) + ( 6000 / 2 ) - ( height  / 2 ) 
                local rotation = getCameraRotation() 
                if rendertar then 
                dxSetRenderTarget(rendertar) 
                dxDrawImageSection( 0, 0, width, height, mapX, mapY, width , height , "map.jpg", rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ) 
                dxSetRenderTarget() 
                else 
                    outputChatBox(rendertar) 
                end 
                dxDrawImage(posX, screeny - posY, width, height, rendertar) 
                dxDrawImage( posX + width / 2, screeny - posY + height / 2, 10, 10, "files/me.png" ) 
      
        function findRotation( x1, y1, x2, y2 ) 
        local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) 
        if t < 0 then 
            t = t + 360 
        end 
        return t 
    end 
      
    end) 

Link to comment

Uh, i don't think so, as i didn't set the color of the rendertarget

//edit:

Just setted the 3rd argument (withAlpha) to true, and the black corners are gone.

But the maps are now overlapped as you can see in the first post too.

Way to solve this ?

Link to comment

It is "only rotating in the square", your problem is that your are using dxDrawImageSection as big as the render target, so when you rotate it you dont draw on the whole render target. To fix this, make the dxDrawImageSection draw a bigger section than the render target that you are drawing on (render target will take care of the slicing, so you dont have to care about that).

Link to comment
Why not ?

I'm not sure what you are using it for, but render target + image section is redundant if you only want to keep the map picture radar sized, since it can't get out of the rendertarget anyway.

You could just use dxDrawImage full size.

Link to comment
  • Moderators

KRZO: Just use your initial script but just set usize and vsize twice the radar size but in this case, we have to adjust the u and v (arg names from the wiki page)

dxDrawImageSection( 0, 0, width, height, mapX-(width/2), mapY-(height/2), width*2 , height*2 , "map.jpg", rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ) 

And it should be good.

Link to comment
  • Moderators

Ok so this: (I'm doing the same on width and height too)

dxDrawImageSection( 0-(width/2), 0-(height/2), width-2, height*2, mapX-(width/2), mapY-(height/2), width*2 , height*2 , "map.jpg", rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ) 

Link to comment

- setRenderTarget

- dxdrawImage your map

You will probably have to change the positioning but imo its much easier than drawing a section.

Don't know about performance, but I tried so much weird things onClientRender already, ever experienced any lags.

Link to comment
  • Moderators

EDIT: Oh just spoted a typo I did here:

width-2 

it's

width*2 

Try again with that fix above.

Original post

huh,

not that what i wanted :D

QdId0Li.png

WTF ?! I really don't get the result you got. Try using dxDrawImage like Bonsai suggested to check something. If it's doing the same shitty corners, then we can't do it with the render target I guess, we will use a mask instead.

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