[Snippet] Covert 3D Coords to 2D

Ninja FTW

Well-Known Member
Joined
Aug 11, 2017
Messages
61
Likes
0
Points
6
Location
Saturn
#1
Took some time but manage to make it:

Code:
// Take target actor or anyone position and set their x,y,z coords with [email protected],[email protected] and [email protected] variable
0073: [email protected] /= [email protected]
0073: [email protected] /= [email protected]     // negative value
0AD1: "%f %f" 2000 [email protected] [email protected]
wait 2000
0092: [email protected] = float [email protected] to_integer 
04AF: [email protected] = [email protected]
0A8F: [email protected] = [email protected] - [email protected] // empty
0A8F: [email protected] = [email protected] - [email protected]
0093: [email protected] = integer [email protected] to_float 
0AD1: "%f %f" 2000 [email protected] [email protected]
Example is included:

It first declare some coords from actor ([email protected], [email protected], [email protected]). Now for converting it in 2d coords, we shall divide [email protected], [email protected] coords from actor Z coord. 0AD1 will exactly show the actor coords into 2d screen coords. 
Now one problem is that Y Coord of actor ([email protected]) is negative which is out of screen. Generally, if you are making a text draw then it will not show on screen because [email protected] is out of screen. Now for converting [email protected] into positive we shall apply some basic mathematical techniques. I changed the [email protected] coord into integer because 0A8F do not accept float and there is only one 0A8F which unfortunately, accept integer but fortune, for integer users. So, that is why we are changing it. [email protected] coord contain original of [email protected] coord value which is [email protected] after changing float to integer. Now we will subtract the [email protected] coord with [email protected] so, the [email protected] will contain empty which will come in handy. Now subtract the [email protected] (which is empty) with [email protected] (which contain original value of [email protected]). Since, [email protected] is empty with no operator sign (e.g: +, -, /, x) then it will subtract nothing with [email protected] but it will change operator sign because we all know that " negative negative = positive" so, [email protected] value is negative. Now it will change [email protected]  into [email protected] which is [email protected], originally. Covert [email protected] into [email protected] and you are done. 

and.. I know, I know, that there is already a opcode to change the 3d coords to 2d but this one do not require SAMPFUNCS. ^_^
 

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
919
Likes
4
Points
18
#3
3d world to 2d on screen conversion doesn't work like that... You'd have to take the camera position and its angle into consideration, there's internal GTA function for that. Let's take a look at what it actually does:
-it divides x by z
-it divides y by z
-it makes the result of the above y/z division absolute

Opcode.eXe posted snippet which uses the internal function here: http://ugbase.eu/Thread-SNIPPET-Convert-3D-position-to-2D-screencords
 
Top