[Include] Screen to World vice versa
#1

[Include] ScreenToWorld (Alpha)

Welcome, to another useless release

Today I present the ScreenToWorld and WorldToScreen Include

Since there is nothing to explain two screens of each
  • ScreenToWorld(playerid, Float: screenX, Float: screenY, & Float: vX, & Float: vY, & Float: vZ);
I enter in my debug mode screenX and screenY which is marked by the red dot, the basketball should appear behind it

  • WorldToScreen(playerid, Float: x, Float: y, Float: z, & Float: screenX, & Float: screenY);
Here I enter x, y and z relative to my position to make it easier for me, the first shows 5 to the right, 20 to the front and 5 up in the height

If the coordinates aren't on the screen nothing will happen in ScreenToWorld (return 0)
But in WorldToScreen it always returns the screen x and y even if these are out of the visible grid

Download

https://github.com/Shiska/screentoworld

How to use

http://forum.sa-mp.com/showpost.php?...4&postcount=30
Reply
#2

I have no idea what I could use this for, but maybe I will need it for something in future, nice release.
Reply
#3

haha, good job )
did you opened matrix mathematics to direct mathematics?
Reply
#4

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
I have no idea what I could use this for, but maybe I will need it for something in future, nice release.
Are you crazy? This is insane! This can be used to detect if vehicles are on a player's screen and stuff, this is a well needed feature in sa-mp! Holy shit!

Example in a TDM or something, if a playerb is on the screen of playera, they can create a textdraw using getScreenFromWorldPosition to point on playerb on playera's screen from playerb's position!

This is awesome!

Thank you Nero_3D
Reply
#5

I hope it syncs well

It's not useless tho, but I don't understand the basic function (yes i uber n00b)
Reply
#6

This is actually amazing that someone converted it to PAWN. WorldToScreen and ScreenToWorld is what the SA:MP client uses to determines nametag positions. Of course with a reversed address for the WorldToScreen to be completely functional but seeing this in PAWN is really something. We can actually make our own nametags if we wanted to.

+1 mate.
Reply
#7

Aww... This is so great. I already have an use for this.
Reply
#8

The object can follow the player screen?
Reply
#9

What about the widescreen setting in display options?
Reply
#10

this is example of world to screen projection:
https://www.youtube.com/watch?v=E7nDgCleeWU

and script: http://pastebin.com/YQjzqD5G
with wide screen settings
Reply
#11

Nice release, but could you explain how it works and calculates for higher resolutions?

Regards
Reply
#12

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Nice release, but could you explain how it works and calculates for higher resolutions?

Regards
There is no higher resolution...
samp in-game resolution is always constantly 640x480 or smth like that
Reply
#13

Amazing, will use to detect if players, objects, and vehicles are seen in the player's screen!
Reply
#14

Quote:
Originally Posted by Slice
Посмотреть сообщение
What about the widescreen setting in display options?
pawn Код:
/// These values were gathered by assumption of the size of the screen

#if 1 // change this to 0 if you use widescreen - or create an player array and let the player decide
    const
        Float: cInGameX = 0.7,
        Float: cInGameY = 0.525,
        Float: cOnScreenX = 640.0,
        Float: cOnScreenY = 447.0
    ;
#else
    const // Widescreen
        Float: cInGameX = 0.7,
        Float: cInGameY = 0.4,
        Float: cOnScreenX = 640.0,
        Float: cOnScreenY = 447.0
    ;
#endif
OT: Nice release,very interesting ...
Reply
#15

Good release. It might get handy.
Reply
#16

This is a VERY nice release! I'm surely going to run some tests later on and experiment with this.

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Nice release, but could you explain how it works and calculates for higher resolutions?

Regards
It uses the "GetPlayerCameraFrontVector" function, which automatically gets the player's front camera vector according to their resolution, AFAIK (not sure about widescreen).
Reply
#17

Quote:
Originally Posted by Vinnyy
Посмотреть сообщение
haha, good job )
did you opened matrix mathematics to direct mathematics?
Just basic vector addition, substraction and multiplication, actually nothing special
Quote:
Originally Posted by Vinnyy
Посмотреть сообщение
this is example of world to screen projection:
https://www.youtube.com/watch?v=E7nDgCleeWU

and script: http://pastebin.com/YQjzqD5G
with wide screen settings
Did you made that script ?, it looks pretty good
First I wanted to let it work over angles but well I got a problem with representing it on the screen

Wordering about
pawn Код:
new Float:fPitch = acos(fCamLookAt[2]) + 270.0; // shouldn't that be asin ?
// five lines after
fPitch = 0.0;
Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Nice release, but could you explain how it works and calculates for higher resolutions?

Regards
Like Vinnyy said, resolution doesn't matter because the 680x480 canvas are always the same and the range you see in game doesn't change with it
Reply
#18

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Did you made that script ?, it looks pretty good
First I wanted to let it work over angles but well I got a problem with representing it on the screen

Wordering about
pawn Код:
new Float:fPitch = acos(fCamLookAt[2]) + 270.0; // shouldn't that be asin ?
// five lines after
fPitch = 0.0;
yep, it was me.

Код:
fYaw = 90.0;
    fPitch = 0.0;
       
        fCamPos[0] = -0.1;
        fCamPos[1] = 0.0;
        fCamPos[2] = fHeight;
delete these lines )
it I used for debugging
next, change fZFar to bigger value(for example, 6000.0)

good luck
Reply
#19

This is awesome! Exactly what I needed! Great include.
Reply
#20

ScreenToWorld not works!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)