Karuzo Posted March 8, 2014 Share Posted March 8, 2014 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: 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
h4x7o0r Posted March 8, 2014 Share Posted March 8, 2014 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
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 The Rotation offset gotta be the the center of the render target, not the current center of the image, since it moves around. Just get the distance between center of image and center of render target and use those as offsets. Link to comment
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 Thank you all. The black corners are just ugly, i know i have to use pngs but those were so big. Is there another way ? Link to comment
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 Ohhhh, should have read more careful Do you create a transparent render target? Link to comment
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 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
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 You also have to clear the rendertarget on every frame. There is an argument when setting a rendertarget. Link to comment
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 How should i clear it ? And wouldn't that lag a little bit ? Link to comment
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 It doesn't lag for me. dxSetRenderTarget(rendertar, true) Link to comment
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 Yeah now it doesn't overlap, thank you very much. But it looks a little bit awkward. How can i make it just to rotate in the square. Link to comment
arezu Posted March 8, 2014 Share Posted March 8, 2014 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
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 Like that? dxDrawImageSection( 0, 0, width, height, mapX, mapY, width+100 , height+100 , "map.jpg", rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ) Now the calculations is wrong Link to comment
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 Why do you use dxDrawImageSection anyway? Link to comment
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 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 Citizen Posted March 8, 2014 Moderators Share Posted March 8, 2014 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
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 Hey Citizen, Still have the same problem with the corners. Link to comment
Moderators Citizen Posted March 8, 2014 Moderators Share Posted March 8, 2014 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
Karuzo Posted March 8, 2014 Author Share Posted March 8, 2014 huh, not that what i wanted Link to comment
Bonsai Posted March 8, 2014 Share Posted March 8, 2014 - 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 Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 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 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now