[Include] Screen to World vice versa
#21

Quote:
Originally Posted by adri1
Посмотреть сообщение
ScreenToWorld not works!
If my code isn't working for you for any reason I can't image because it does for me try Vinnyy's code

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
I should take a look into it once again if I got some time left
Reply
#22

Good job and it's really useful
Reply
#23

Quote:
Originally Posted by kvann
Посмотреть сообщение
Aww... This is so great. I already have an use for this.
And just remake and claimed its your on scripted in your rp server? Like Furniture system preview.
Reply
#24

I use this:
pawn Код:
public OnCursorPositionChange(NewX, NewY)
{
    if(var == 1)
    {
        new Float:p[3];
        new Float:MX = (floatdiv(NewX, ScreenWidth) * 640.0);
        new Float:MY = (floatdiv(NewY, ScreenHeight) * 448.0);
        ScreenToWorld(0, MX, MY, p[0], p[1], p[2]);
        new Float:pp[3];
        //GetObjectPos(obj, pp[0], pp[1], pp[2]);
        SetObjectPos(obj, p[0], p[1], p[2]);
        //printf("%f, %f, %f", p[0], p[1], p[2]);
    }
    return 1;
}
and return this:
pawn Код:
[23:33:39] 0.114388, -1.017790, 0.300795
[23:33:39] 0.116575, -1.017659, 0.298849
[23:33:39] 0.119490, -1.017521, 0.296903
[23:33:39] 0.121676, -1.017390, 0.294958
[23:33:40] 0.120220, -1.017570, 0.297876
[23:33:40] 0.118034, -1.017812, 0.301767
[23:33:40] 0.117305, -1.017819, 0.301767
...
...

EDIT:

Example::

pawn Код:
ScreenToWorld(0, 600, 200, p[0], p[1], p[2]);

returns: 0.998540, -0.610018, -0.094856
Player ID 0 it's connected!.
Reply
#25

I never stated it but ScreenToWorld actully returns a vector (returning a position would need a distance parameter)
Since I use the front vector as base, it also starts at the camera pos

pawn Код:
// I think NewX and NewY are normal textdraw coordinates ?
// Than they need to be float and we just insert them directly in StW
public OnCursorPositionChange(Float: NewX, Float: NewY)
{
    if(var == 1)
    {
        const playerid = 0;

        new pos[6];
        GetPlayerCameraPos(playerid, p[0], p[1], p[2]);
        ScreenToWorld(playerid, NewX, NewY, p[3], p[4], p[5]);

        const Float: distance = 25.0;

        p[0] += p[3] * distance;
        p[1] += p[4] * distance;
        p[2] += p[5] * distance;

        SetObjectPos(obj, p[0], p[1], p[2]);

        printf("%f, %f, %f", p[0], p[1], p[2]);
    }
}
Reply
#26

It's possible only for X, Y object position? Z using MapAndreas.
Reply
#27

Quote:
Originally Posted by adri1
Посмотреть сообщение
It's possible only for X, Y object position? Z using MapAndreas.
It converts X, Y and Z in game position into X and Y of the screen (WorldToScreen)
And X and Y of the screen in an vector (starting at the camera pos) with X, Y and Z (ScreenToWorld)
Reply
#28

Can you make an example? please.
Reply
#29

Nhhh... Was better to post this filter and Include, not at all useful.
Reply
#30

Quote:
Originally Posted by adri1
Посмотреть сообщение
Can you make an example? please.
First ScreenToWorld and how to calculate the position with a specific distance
Afterwards WorldToScreen which just takes a position in 3d and returns the x and y of the screen
pawn Код:
const
    Float: distance = 25.0
;
new
    Float: TextDrawX = 400.0,
    Float: TextDrawY = 300.0,
    Float: cameraX,
    Float: cameraY,
    Float: cameraZ,
    Float: vectorX,
    Float: vectorY,
    Float: vectorZ
;
// ScreenToWorld
GetPlayerCameraPos(playerid, cameraX, cameraY, cameraZ);
ScreenToWorld(playerid, TextDrawX, TextDrawY, vectorX, vectorY, vectorZ);

cameraX += vectorX * distance;
cameraY += vectorY * distance;
cameraZ += vectorZ * distance;

printf("%f %f %f", cameraX, cameraY, cameraZ);
// WorldToScreen
WorldToScreen(playerid, cameraX, cameraY, cameraZ, TextDrawX, TextDrawY);

printf("%f %f", TextDrawX, TextDrawY);
Reply
#31

What about this feature? ColWorldSnapShot ?

It generates a bitmap file of the collision world of san andreas.

The main drawback of this function is, it can only generate the image in the server files.
This is why I need, client side plugins.




It's quite messed up but I am finding a way to to this. Though, you can guess which location is this .


EDIT: Close.



EDIT2:
New Image
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)