Well I was never a prodigy at math, and I need help with the conversion from World to Screen based of the following concepts that I will elaborate on below.
According to my tests for the FPS game that i'm hacking, the middle of the resolution of the game for a game whose resolution is 800x600 is 400x300. Corresponding to the middle of the screen is ALSO the players position. With this fact in hand I was able to formulate this picture (the player is at the origin):
1.jpg
I was then able to understand that your player will always be the center of the screen. Wherever you move, your field of view shifts to the right if you moved to the right or to the left if you moved to the left. Your players position doesn't move. It remains as the origin of the screen. You feel a sense of movement when your field of view shifts according to your movements and you're able to see objects which you weren't able to see in your previous field of view. With that in mind, if you drew a circle in the middle of the resolution it will always remain tagged on the players crosshairs which represents his position.
Now, my problem was to determine the 2D coordinates based of the 3D coordinates I place in. In the next picture, I will include enemies.
2.jpg
IN this picture, you have two enemies. One is a bit to your right and the other is a bit to your left. My theory is that if your player is the origin of the screen regardless of where he moves and his 3D coordinates translate to the middle of the resolution, then its safe to say that since his coordinates are 400x300. Because of that, we can apply ratios to determine the 2D coordinates of enemy #1 and enemy #2 assuming that you have that information.
So lets say that enemy #1 is located at a position in the game which was 3000, 2000 not including the z axis. WE can that the ratio of the difference between the enemy X and the player X must be the same ratio of the enemy screen X to player screeen X respectively.
So assuming your player is located at 1000, 1500 in the game, the difference between the enemies X and the players X would be 2000. That ratio is 2X greater than the origin. We found that number with the following calculation:
( EnemyX - playerX ) / playerX = Ratio of how far the enemy is from us.
Applying that ratio to our screen coordinates, we can then find our the enemies position based of the ratio with the following calculation:
float Ratio = ( EnemyX - playerX ) / playerX;
400 + ( 400 * Ratio ) = EnemyScreenX;
After completing the calculation your enemy #1 position should according to my theory be at 600.
The same process applies with Enemy #2 in determining his X position, and the same concept appies for solving 'y'.
However, my coordinates never match up in game.
Can you guys point out my mistakes? Thanks