[SNIPPET] Convert 3D position to 2d Radar screen pos

Function:

0AB1: @POSITION_TO_RADAR 7 XYZ 0.0 0.0 0.0 RADAR_POS 400 400 DISTANCE_MULTIPLIER 1.5 MAX_DISTANCE 300.0 _STORE_TO 1@ 2@

This function converts 3D position to 2D Radar position like on the Minimap.

You can make things like this:

http://i.san-mp.de/i/26CEA9.webm

Source:

Code:
{$CLEO .cs}

0000:

REPEAT

    WAIT 0

UNTIL 0AFA:  SAMP_IS_READY

0B6D: 5@ = create_font "Arial" height 10 flags 0x4

0BFC: SET_VAR "MadeByOpcodeXe" = 5@

WHILE TRUE

    WAIT 0

    FOR 31@ = 0 TO 1000

        IF

        0B23:  samp is_player_connected 31@

        THEN

            IF

            0B20: samp 30@ = actor_handle_by_samp_player_id 31@

            THEN

                0AB1: @GET_BONE_POS 2 FROM_ACTOR $PLAYER_ACTOR BONE 6 _STORE_TO 5@ 6@ 7@  // HEAD

                04C4: store_coords_to 8@ 9@ 10@ from_actor 30@ with_offset 0.0 0.0 0.0               

                0B55: convert_3D_coords 5@ 6@ 7@ to_screen 5@ 6@

                0AB1: @POSITION_TO_RADAR 7 XYZ 8@ 9@ 10@ RADAR_POS 5@ 6@ DISTANCE_MULTIPLIER 1.5 MAX_DISTANCE 300.0 _STORE_TO 13@ 14@

                0B70: draw_polygon_pos 5@ 6@ size 7 7 corners 7 rotation 0 color 0xFFFFFFFF

                0B70: draw_polygon_pos 13@ 14@ size 5 5 corners 5 rotation 90 color 0xFFFFFFFF                                 

                0B36: samp 15@ = get_player_nickname 31@

                0B37: samp 16@ = get_player_color 31@

                0BFD: 5@ = get_global_var "MadeByOpcodeXe"

                0B6B: 6@ = font 5@ draw_text 15@ length

                0B6C: 7@ = font 5@ draw_height

                7@ += 5

                6@ /= 2

                0062: 13@ -= 6@  // (int)

                0062: 14@ -= 7@  // (int)

                0B6F: render font 5@ draw_text 15@ pos 13@ 14@ color 16@

            END

        END

    END

END

//0AB1: @GET_BONE_POS 2 FROM_ACTOR $PLAYER_ACTOR BONE 6 _STORE_TO 1@ 2@ 3@  // HEAD

:GET_BONE_POS

0085: 10@ = 0@ // (int)

0085: 15@ = 1@ // (int)

1@ = 0.0 // X offset

2@ = 0.0 // Y offset {THX TO: WESSER}

3@ = 0.0 // Z offset

0A96: 0@ = actor 10@ struct

0AC7: 4@ = var 1@ offset

0AA6: call_method 0x5E01C0 struct 0@ num_params 3 pop 0 bIncludeAnim 1 iBoneID 15@ vOffset 4@ // CPed__getBonePositionWithOffset

0AB2: retn 3 1@ 2@ 3@

//0AB1: @POSITION_TO_RADAR 7 XYZ 0.0 0.0 0.0 RADAR_POS 400 400 DISTANCE_MULTIPLIER 1.5 MAX_DISTANCE 300.0 _STORE_TO 1@ 2@

:POSITION_TO_RADAR

04C4: 10@ 11@ 12@ = XYZ $PLAYER_ACTOR 0.0 0.0 0.0

050A: 13@ = distance_between_XYZ 0@ 1@ 2@ and_XYZ 10@ 11@ 12@

006B: 13@ *= 5@

IF

0025:  13@ > 6@

THEN

0087: 13@ = 6@ // (float)

END

0AB1: @getZAngleBetweenPoints 4 from_XY 10@ 11@ and_XY 0@ 1@ store_to 14@

14@ *= -1.0

0AB1: @getCameraFacingAngle 0 15@

005B: 14@ += 15@

0093: 3@ = integer 3@ to_float

0093: 4@ = integer 4@ to_float

0AB1: @makeCordinate 6 3@ 4@ 0.0 Z_Angle 14@ 0.0 Distance 13@ STORE_TO 16@ 17@

0092: 16@ = float 16@ to_integer

0092: 17@ = float 17@ to_integer

0AB2: 2 16@ 17@

:makeCordinate

3@ *= -1.0

02F6: 6@ = sine 3@

006B: 6@ *= 5@

005B: 0@ += 6@

02F7: 6@ = cosine 3@

006B: 6@ *= 5@

005B: 1@ += 6@

02F7: 6@ = cosine 4@

0073: 5@ /= 6@

02F6: 6@ = sine 4@

006B: 5@ *= 6@

005B: 2@ += 5@

0AB2: 2 0@ 1@

:getCameraFacingAngle

00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@

0AA6: call_method 0x514970 struct 0xB6F028 num_params 6 pop 0 0xA49994 0xA499A0 3@ 2@ 1@ 20.0

0AB1: call_scm_func @getZAngleBetweenPoints 4 from_XY $13 $14 and_XY 1@ 2@ store_to 4@

0AB2: 1 4@

:getZAngleBetweenPoints

0063: 0@ -= 2@

0063: 1@ -= 3@

0604: get_Z_angle_for_point 0@ 1@ store_to 4@

0AB2: 1 4@

Function code:

Code:
//0AB1: @POSITION_TO_RADAR 7 XYZ 0.0 0.0 0.0 RADAR_POS 400 400 DISTANCE_MULTIPLIER 1.5 MAX_DISTANCE 300.0 _STORE_TO 1@ 2@

:POSITION_TO_RADAR

04C4: 10@ 11@ 12@ = XYZ $PLAYER_ACTOR 0.0 0.0 0.0

050A: 13@ = distance_between_XYZ 0@ 1@ 2@ and_XYZ 10@ 11@ 12@

006B: 13@ *= 5@

IF

0025:  13@ > 6@

THEN

0087: 13@ = 6@ // (float)

END

0AB1: @getZAngleBetweenPoints 4 from_XY 10@ 11@ and_XY 0@ 1@ store_to 14@

14@ *= -1.0

0AB1: @getCameraFacingAngle 0 15@

005B: 14@ += 15@

0093: 3@ = integer 3@ to_float

0093: 4@ = integer 4@ to_float

0AB1: @makeCordinate 6 3@ 4@ 0.0 Z_Angle 14@ 0.0 Distance 13@ STORE_TO 16@ 17@

0092: 16@ = float 16@ to_integer

0092: 17@ = float 17@ to_integer

0AB2: 2 16@ 17@

:makeCordinate

3@ *= -1.0

02F6: 6@ = sine 3@

006B: 6@ *= 5@

005B: 0@ += 6@

02F7: 6@ = cosine 3@

006B: 6@ *= 5@

005B: 1@ += 6@

02F7: 6@ = cosine 4@

0073: 5@ /= 6@

02F6: 6@ = sine 4@

006B: 5@ *= 6@

005B: 2@ += 5@

0AB2: 2 0@ 1@

:getCameraFacingAngle

00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@

0AA6: call_method 0x514970 struct 0xB6F028 num_params 6 pop 0 0xA49994 0xA499A0 3@ 2@ 1@ 20.0

0AB1: call_scm_func @getZAngleBetweenPoints 4 from_XY $13 $14 and_XY 1@ 2@ store_to 4@

0AB2: 1 4@

:getZAngleBetweenPoints

0063: 0@ -= 2@

0063: 1@ -= 3@

0604: get_Z_angle_for_point 0@ 1@ store_to 4@

0AB2: 1 4@
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Re: Convert 3D position to 2d Radar screen pos

Code:
//0AB1: @POSITION_TO_RADAR 7 XYZ 0.0 0.0 0.0 RADAR_POS 400 400 DISTANCE_MULTIPLIER 1.5 MAX_DISTANCE 300.0 _STORE_TO 1@ 2@
:POSITION_TO_RADAR
04C4: 10@ 11@ 12@ = XYZ $PLAYER_ACTOR 0.0 0.0 0.0
050A: 13@ = distance_between_XYZ 0@ 1@ 2@ and_XYZ 10@ 11@ 12@
006B: 13@ *= 5@
IF
0025:  13@ > 6@
THEN
0087: 13@ = 6@ // (float)
END         
0AB1: @getZAngleBetweenPoints 4 from_XY 10@ 11@ and_XY 0@ 1@ store_to 14@
14@ *= -1.0
0AB1: @getCameraFacingAngle 0 15@
005B: 14@ += 15@
0093: 3@ = integer 3@ to_float
0093: 4@ = integer 4@ to_float
0AB1: @makeCordinate 4 posXY 3@ 4@ Z_Angle 14@ Distance 13@ STORE_TO 16@ 17@
0092: 16@ = float 16@ to_integer
0092: 17@ = float 17@ to_integer
0AB2: 2 16@ 17@

:makeCordinate
//0@ = radar pos X
//1@ = radar pos Y
//2@ = z_angle
//3@ = Distance
//10@ = new variable
2@ *= -1.0
//x adjustment
02F6: 10@ = sine 2@
006B: 10@ *= 3@
005B: 0@ += 10@

//y adjustment
02F7: 10@ = cosine 2@
006B: 10@ *= 3@
0017: 10@ /= 640.0
0013: 10@ *= 480.0
005B: 1@ += 10@

0AB2: 2 0@ 1@

:getCameraFacingAngle
00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@
0AA6: call_method 0x514970 struct 0xB6F028 num_params 6 pop 0 0xA49994 0xA499A0 3@ 2@ 1@ 20.0
0AB1: call_scm_func @getZAngleBetweenPoints 4 from_XY $13 $14 and_XY 1@ 2@ store_to 4@
0AB2: 1 4@

:getZAngleBetweenPoints
0063: 0@ -= 2@
0063: 1@ -= 3@
0604: get_Z_angle_for_point 0@ 1@ store_to 4@
0AB2: 1 4@

I edited the code a bit, it was giving elliptical results instead of circular because there was no adjusment for x/y ratio 640/480

Edit: btw it's better to use 0509: 13@ = distance_between_XY 0@ 1@ and_XY 10@ 11@ instead (otherwise radar position if something is above/under you)
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Convert 3D position to 2d Radar screen pos

Is it possible to check the radar autozoom ? (the map zom/unzoom at different car's speed), so that the point stay at the good position on the minimap independent of the speed ?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Re: Convert 3D position to 2d Radar screen pos

Grubitsh link said:
Is it possible to check the radar autozoom ? (the map zom/unzoom at different car's speed), so that the point stay at the good position on the minimap independent of the speed ?

http://www.gtagarage.com/mods/show.php?id=23763 it contains the source code, check it.
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Convert 3D position to 2d Radar screen pos

Thanks I will try it
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Convert 3D position to 2d Radar screen pos

If you wanna make it for the RADAR, get the center of your radar pos, then adjust the DISTANCE MUTLTIPLIER without moving.
Then adjust the velocity compensation (zoom/unzoom map) with this code


CODE BY MONDAY
Code:
06AC: 21@ = actor $PLAYER_ACTOR movement_speed
    if 0021:   21@ > 50.0
    then
    21@ = 50.0
    end
006B: 21@ *= 21@ 
17@ = -0.514 //by adjusting this you change how big is compensation of the position due to speed
0017: 17@ /= 2500.0
006B: 17@ *= 21@ 
000B: 17@ += 1.0 // DISTANCE MUTLTIPLIER without moving

//17@ = distance multiplier
CODE BY MONDAY
 

polat65

New member
Joined
Feb 21, 2015
Messages
2
Reaction score
0
Re: Convert 3D position to 2d Radar screen pos

hey can i get a code with sampfunks sb data, which alows me to see player icons on the mini map?
 

Valiuks

Active member
Joined
Sep 9, 2018
Messages
25
Reaction score
4
if i have fixed coordinates and I am too far "assuming MAX_DISTANCE 300.0 meter" will it try to display on radar even i am out of reach or not? regardless, tyvm
 
Top