[Snippet] Covert 3D Coords to 2D

Took some time but manage to make it:

Code:
// Take target actor or anyone position and set their x,y,z coords with 1@,2@ and 3@ variable
0073: 1@ /= 3@
0073: 2@ /= 3@     // negative value
0AD1: "%f %f" 2000 1@ 2@
wait 2000
0092: 21@ = float 2@ to_integer 
04AF: 5@ = 21@
0A8F: 6@ = 21@ - 21@ // empty
0A8F: 7@ = 6@ - 5@
0093: 22@ = integer 7@ to_float 
0AD1: "%f %f" 2000 1@ 22@

Example is included:

It first declare some coords from actor (1@, 2@, 3@). Now for converting it in 2d coords, we shall divide 1@, 2@ 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 (2@) is negative which is out of screen. Generally, if you are making a text draw then it will not show on screen because 2@ is out of screen. Now for converting 2@ into positive we shall apply some basic mathematical techniques. I changed the 2@ 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. 5@ coord contain original of 2@ coord value which is 12@ after changing float to integer. Now we will subtract the 21@ coord with 21@ so, the 6@ will contain empty which will come in handy. Now subtract the 6@ (which is empty) with 5@ (which contain original value of 2@). Since, 6@ is empty with no operator sign (e.g: +, -, /, x) then it will subtract nothing with 5@ but it will change operator sign because we all know that " negative negative = positive" so, 5@ value is negative. Now it will change 5@  into 22@ which is 6@, originally. Covert 7@ into 22@ 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

Expert
Joined
Jun 23, 2014
Messages
1,126
Reaction score
154
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