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;
}
}