Gaimo Posted June 16, 2022 Share Posted June 16, 2022 I have the following problem, I need the blip to be stuck to the edge of the radar. Spoiler Spoiler function drawBlip(posX, posY, size, texture, color, visibleDistance) -- @description: Draw a blip -- @implementation version: Alpha -- @param: {posX} (Float) Blip X position. -- @param: {posY} (Float) Blip Y position. -- @param: {size} (Int) Blip size. -- @param: {texture} (Texture) Blip texture. -- @param: {color} (Color) Blip color. -- @param: {visibleDistance} (Float) Maximum distance the blip should be rendered. -- @return: No return. -- @example: createCustomBlip(50,0, 10, nil, tocolor(0,255,0,255), 300) local distance = getDistanceBetweenPoints2D(posX, posY, playerPosition.x, playerPosition.y) --Avoid rendering blips that are not in the player's view. if distance > visibleDistance then return end local radarCenter = getRadarCenter() local radarFix = 2.5 local blipDistance = Vector2((posX - playerPosition.x), (posY - playerPosition.y)) local x,y = ( blipDistance.x / radarFix), ( blipDistance.y / radarFix ) local position = Vector2( radarCenter.x - (size/2) + x, radarCenter.y - (size/2) - y ) dxDrawImage(position.x, position.y, size, size, texture, camRot, -x, y, color) end I know I need to do some sort of math.clump, to prevent the blip from rendering outside of the minimap's border function math.clamp( _in, low, high ) return math.min( math.max( _in, low ), high ) end I performed some tests and almost succeeded, however, I'm not sure if the way I implemented to position the blips was the most efficient. How does the radar work? It is based on shader_hud_mask, and it is rendered like this: Spoiler local radar = { currentShape = "circle", zoom = 8, arrowSize = 16, } radar.square = {} radar.square.size = Vector2(300, 200) radar.square.position = Vector2(10, SH - radar.square.size.y - 10) radar.circle = {} radar.circle.size = Vector2(300, 300) radar.circle.position = Vector2(10, SH - radar.circle.size.y - 10) function drawMinimap() playerPosition = Vector2(getElementPosition(localPlayer)) _,_,camRot = getElementRotation(getCamera()) _,_,playerRot = getElementRotation(localPlayer) -- Transform world x,y into -0.5 to 0.5 local x,y = playerPosition.x, playerPosition.y x = ( x ) / 6000 y = ( y ) / -6000 dxSetShaderValue( SHADER_MASK, "gUVPosition", x,y ) local radarCenter = getRadarCenter() if radar.currentShape == "circle" then dxSetShaderValue( SHADER_MASK, "gUVScale", 1/radar.zoom, 1/radar.zoom ) dxDrawImage( radar.circle.position.x, radar.circle.position.y, radar.circle.size.x, radar.circle.size.y, SHADER_MASK, camRot,0,0) drawBlips() dxDrawImage(radar.circle.position.x, radar.circle.position.y, radar.circle.size.x, radar.circle.size.y, TEXTURE_OUTLINE_CIRCLE) dxDrawImage(radarCenter.x - (radar.arrowSize/2), radarCenter.y - (radar.arrowSize/2), radar.arrowSize, radar.arrowSize, TEXTURE_ARROW, camRot - playerRot) else -- Square dxSetShaderValue( SHADER_MASK, "gUVScale", 1/radar.zoom, 0.667/radar.zoom ) dxSetShaderValue( SHADER_MASK, "gUVRotAngle", math.rad(-camRot) ) dxDrawImage(radar.square.position.x, radar.square.position.y, radar.square.size.x, radar.square.size.y, SHADER_MASK, 0,0,0) drawBlips() dxDrawImage(radar.square.position.x, radar.square.position.y, radar.square.size.x, radar.square.size.y, TEXTURE_OUTLINE_SQUARE) dxDrawImage(radarCenter.x - (radar.arrowSize/2), radarCenter.y - (radar.arrowSize/2), radar.arrowSize, radar.arrowSize, TEXTURE_ARROW, camRot - playerRot) end end Any idea how I can do this? 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