Screen to World vice versa -
Nero_3D - 09.12.2013
[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
![](http://i176.photobucket.com/albums/w187/Nero_3D/Jpeg/Big/th_sa-mp-008.png)
- 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
![](http://i176.photobucket.com/albums/w187/Nero_3D/Jpeg/Big/th_sa-mp-010.png)
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
Re: Screen to World vice versa - Patrick - 09.12.2013
I have no idea what I could use this for, but maybe I will need it for something in future, nice release.
Re: Screen to World vice versa -
Vinnyy - 10.12.2013
haha, good job )
did you opened matrix mathematics to direct mathematics?
Re: Screen to World vice versa -
Kar - 10.12.2013
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
Re: Screen to World vice versa -
Sublime - 10.12.2013
I hope it syncs well
It's not useless tho, but I don't understand the basic function (yes i uber n00b)
Re: Screen to World vice versa -
ViruZz - 10.12.2013
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.
Re: Screen to World vice versa -
kristo - 10.12.2013
Aww... This is so great. I already have an use for this.
Re: Screen to World vice versa -
iJumbo - 10.12.2013
The object can follow the player screen?
Re: Screen to World vice versa -
Slice - 10.12.2013
What about the widescreen setting in display options?
Re: Screen to World vice versa -
Vinnyy - 10.12.2013
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
Re: Screen to World vice versa -
Kyle - 10.12.2013
Nice release, but could you explain how it works and calculates for higher resolutions?
Regards
Re: Screen to World vice versa -
Vinnyy - 11.12.2013
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
Re: Screen to World vice versa -
SkittlesAreFalling - 11.12.2013
Amazing, will use to detect if players, objects, and vehicles are seen in the player's screen!
Re: Screen to World vice versa -
Kaperstone - 11.12.2013
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 ...
Re: Screen to World vice versa -
iZN - 11.12.2013
Good release. It might get handy.
Re: Screen to World vice versa - Emmet_ - 11.12.2013
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).
AW: Re: Screen to World vice versa -
Nero_3D - 11.12.2013
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
|
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
Re: AW: Re: Screen to World vice versa -
Vinnyy - 12.12.2013
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
AW: Screen to World vice versa -
LeBoyce - 12.12.2013
This is awesome! Exactly what I needed!
![Cheesy](images/smilies/biggrin.png)
Great include.
Respuesta: Screen to World vice versa -
adri1 - 14.06.2014
ScreenToWorld not works!