Reynolds_ Posted December 29, 2014 Share Posted December 29, 2014 I'm trying to make a simple radar which is rectangular and looks like the one from Grand Theft Auto V. I've managed to do most of the work and did a couple of edits from other resources when I needed to. My problem is that the 'map rotation' & the 'blip rotation' doesn't quite match up and sometimes I end up being at four different positions depending on how I rotate my mouse. Pictures: http://imagerz.com/QBVAX0tvAwMMUltEQAVQ http://imagerz.com/QBVAX0tvAwMMUltEQwVQ http://imagerz.com/QBVAX0tvAwMMUltEQgVQ http://imagerz.com/QBVAX0tvAwMMUltERQVQ The corresponding renderer: function updateHUD1 ( ) if not guiGetVisible(Radar.Frame) then return end local hp = getElementHealth ( getLocalPlayer() ) if hp > 100 then hp = 100 end local armor = getPedArmor ( getLocalPlayer() ) if armor > 100 then armor = 100 end guiSetSize ( Radar.Armor, 0.465*armor*0.01, 0.056, true ) guiSetSize ( Radar.Health, 0.465*hp*0.01, 0.056, true ) dxSetShaderValue( Radar.maskFX, "sMaskTexture", Radar.maskTexture ) local x,y = getElementPosition( localPlayer ) local zoom = 13 x = ( x ) / 6000 y = ( y ) / -6000 dxSetShaderValue( Radar.maskFX, "gUVPosition", x,y ) dxSetShaderValue( Radar.maskFX, "gUVScale", 1/zoom, 1/zoom ) local _, _, c_Rot = getElementRotation( getCamera()); local _, _, p_Rot = getElementRotation( localPlayer ) dxSetShaderValue( Radar.maskFX, "gUVRotAngle", math.rad( -c_Rot )) dxDrawImage(70*sW, 562*sH, 0.64*265*sW, 0.83*135*sH, Radar.maskFX, 0,0,0, tocolor(255,255,255,210)) dxDrawImage(149.5*sW, 618.025*sH, 10*sW, 10*sH, "map/img/radar_player.png", -p_Rot+c_Rot, 0, 0, tocolor(255, 255, 255, 255)) end addEventHandler( "onClientRender", root, updateHUD1) The masking shader: // // Example shader - hud_mask.fx // #include "fx/matrix.fx" /////////////////////////////////////////////////////////////////////////////// // Global variables /////////////////////////////////////////////////////////////////////////////// texture sPicTexture; texture sMaskTexture; float2 gUVPrePosition = float2( 0, 0 ); float2 gUVScale = float( 1 ); // UV scale float2 gUVScaleCenter = float2( 0.5, 0.5 ); float gUVRotAngle = float( 0 ); // UV Rotation float2 gUVRotCenter = float2( 0.5, 0.5 ); float2 gUVPosition = float2( 0, 0 ); // UV position /////////////////////////////////////////////////////////////////////////////// // Functions /////////////////////////////////////////////////////////////////////////////// //------------------------------------------- // Returns UV transform using external settings //------------------------------------------- float3x3 getTextureTransform() { return makeTextureTransform( gUVPrePosition, gUVScale, gUVScaleCenter, gUVRotAngle, gUVRotCenter, gUVPosition ); } /////////////////////////////////////////////////////////////////////////////// // Techniques /////////////////////////////////////////////////////////////////////////////// technique hello { pass P0 { // Set up texture stage 0 Texture[0] = sPicTexture; TextureTransform[0] = getTextureTransform(); TextureTransformFlags[0] = Count2; AddressU[0] = Clamp; AddressV[0] = Clamp; // Color mix texture and diffuse ColorOp[0] = Modulate; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; // Alpha mix texture and diffuse AlphaOp[0] = Modulate; AlphaArg1[0] = Texture; AlphaArg2[0] = Diffuse; // Set up texture stage 1 Texture[1] = sMaskTexture; TexCoordIndex[1] = 0; AddressU[1] = Clamp; AddressV[1] = Clamp; // Color pass through from stage 0 ColorOp[1] = SelectArg1; ColorArg1[1] = Current; // Alpha modulate mask texture with stage 0 AlphaOp[1] = Modulate; AlphaArg1[1] = Current; AlphaArg2[1] = Texture; // Disable texture stage 2 ColorOp[2] = Disable; AlphaOp[2] = Disable; } } Link to comment
MTA Team botder Posted December 29, 2014 MTA Team Share Posted December 29, 2014 Looks like you rotate the map at the middle of the map center (0.5, 0.5) and not where your player is located. Link to comment
Reynolds_ Posted December 29, 2014 Author Share Posted December 29, 2014 If I change gUVRotCenter to the (x,y) position normalized to the map's size, it will have a "globe effect" instead of the effect I want. To be honest, low-level graphics manipulation has never been my thing. Could you recommend a way to make this work properly using the shader I posted? e.1.: btw this problem appeared first when I resized the map from the resource I edited. The rotation was completely fine with the original width/height params. Link to comment
rtx Posted December 30, 2014 Share Posted December 30, 2014 Make sure you're taking the cursor's relative position and width/height into attention. Link to comment
.:HyPeX:. Posted December 30, 2014 Share Posted December 30, 2014 Probably just coincidence, but it just looks extremly similar to another radar.. viewtopic.php?f=91&t=81689 Link to comment
Reynolds_ Posted December 30, 2014 Author Share Posted December 30, 2014 You should read what I've originally posted. I've never claimed that that particular part of the script was mine, the renderer was from another resource, but I did the radar frame itself, I resized the whole radar to fit my particular GUI and I edited a lot of other stuff on it. It is just the case that the part from the other resource (which I had to use because I am a noob when it comes to graphics rendering) is the very reason the script does not work properly. Anyways, how would I set about taking the cursor's relative position & w/h into consideration? As I said, the whole thing is a black spot for me, so I would appreciate it if someone could give me some help as to how I should begin editing the script. Another thing is that the problem happened when I edited the script originally found in the resource you posted, to be exact, when I resized the original map to fit my radar frame. The cursor's size was not the problem, resizing the map was. I did resize the cursor but it didn't affect anything, however, as soon as I changed the dimensions of the map, even if I scaled it down instead of changing the whole w/h ratio, it screwed up and didn't rotate properly. Link to comment
Addlibs Posted December 30, 2014 Share Posted December 30, 2014 I think it would be easier making a render-target and drawing the map with dxDrawImage on calculated positions and rotation, then drawing the render-target onto the screen - that's how I did my GTAV radar. 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