View previous topic :: View next topic |
Author |
Message |
LongBeardedLion Expert Cheater Reputation: 0
Joined: 10 Apr 2020 Posts: 172
|
Posted: Tue Nov 16, 2021 1:45 pm Post subject: How can I find coordinates to screen in a map? |
|
|
Im working with medieval total war 2. And im trying to understand what tells the cities to be rendered in the specific pixel coordinate in my screen.
I have the city coordinates. But what i really want is the coordinates in my screen of the city.
How should i do this?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Tue Nov 16, 2021 1:53 pm Post subject: |
|
|
Search for "view matrix"
You should know basic linear algebra and 3d computer graphics.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
LongBeardedLion Expert Cheater Reputation: 0
Joined: 10 Apr 2020 Posts: 172
|
Posted: Wed Nov 17, 2021 1:14 am Post subject: |
|
|
That seems to be my view coordinates, x, y, and z. What im trying to catch is the coordinates of a city in my screen.
So for example. The coordinates of the city in my map are x109, y147.
That stays the same always.
But i need to find out the pixel in my screen where the city is being rendered, when the city is being render. Because sometimes, if i move my map to the corner for example, the city will not show up.
So when the city is in the center of my screen it should be on the pixel x960, that is 1920 (my screen x size) / 2.
Is there a way to detect this?
Or thats not so easy?
I can also calculate manually.
For example i get the map size, 200x, 200y.
And i get my screen coordinates 1920, 1080.
Then i get my current map coordinates constantly.
Then i get the coordinates of the city 109, 147.
Then i check if the city is showing in my view matrix.
If it is, then calculate where it is.
Is this the way to go? Looks like reinventing the wheel?
|
|
Back to top |
|
|
blueberrypie How do I cheat? Reputation: 0
Joined: 11 Nov 2021 Posts: 5
|
Posted: Wed Nov 17, 2021 5:19 am Post subject: |
|
|
Not sure if I understand what you are trying to do, but it sounds like you want to calculate world to screen coordinates. Like ParkourPenguin said, it involves finding your view matrix. Then you need to multiply the indexes with each other (in either row or column major order).
It's too much for me to explain in a single comment, but there are lots of guides on that, so google ahead. It's not super easy tho if you are new to that stuff.
ESPs use this technique (to render ESP boxes of e.g. NPCs in the world to the screen), so you can use those hacks for reference when you Google this.
|
|
Back to top |
|
|
LongBeardedLion Expert Cheater Reputation: 0
Joined: 10 Apr 2020 Posts: 172
|
Posted: Wed Nov 17, 2021 7:30 am Post subject: |
|
|
I see now. Thank you. That will take time. Will get there someday. But now i know its not as simple as i thought.
EDIT:
Actually it seems this is even harder. There are no examples around that apply to a game like Medieval Total War 2.
The camera in this case is not like the FPS. So i dont think it just turns around like that.
I could only find the zoom variable and the x and the y variable.
I dont think i can turn around like in an FPS, but it would be so cool if it was possible.
|
|
Back to top |
|
|
blueberrypie How do I cheat? Reputation: 0
Joined: 11 Nov 2021 Posts: 5
|
Posted: Fri Nov 19, 2021 5:55 am Post subject: |
|
|
I don't think it matters in this case. I haven't played Medieval Total War 2, but looking at screenshots it looks like it's basically 3d, just with a top down camera view depending on what screen you are in.
All games need to render to the screen, and as far as I know they do this by using different matrices and combining them. When you do world to screen calculations, you don't need to worry about any of them except for the final MVP matrix (model-view projection) matrix. That has all the calculations done by the game for you already, and that's the one you are looking for. Then you just do your world to screen calculations on that to get your final results.
The flow basically looks something like this:
1. Find the view matrix (aka MVP matrix). This is the hard part since it's hard to know/test if you got the right one. It's essentially a trial and error process.
2. Calculate clip coordinates by multiplying the position of your target (i.e. the city) with your matrix.
3. Do perspective division on the clip coordinates to turn them into NDC coordinates (normalized device coordinates).
4. Finally, transform your calculated NDC coordinates to window coordinates that you can render on the screen.
This process should be just about the same for all games, although I'm not expert and I have only done this for FPS games.
|
|
Back to top |
|
|
|