❓ [Coding] World to Screen Projection doesn't work
Hey all,
im trying to transform world space XYZ to screen XY but somehow the results are not how they should be (different values from what they should be).
Here my code (yes it's hazardedits approach):
Code:
The output when looking right at the enemys head:
//this is the matrix
0.715753
0.22405
-2.44487e-09
-498.291
0.0297045
-0.0948945
1.32962
-158.703
-0.297975
0.951914
0.0745947
-405.814
-0.297901
0.951679
0.0745763
-398.714
//output
screenX: 1056.77
screenY: -79.9052
w (if>0 = onscreen; if=<0 not onscreen): -459.501
whats wrong? i also tried offsetting the viewmatrix by 0x4 bytes but the results were not good aswell.
Some additional info:
im playing in windowed mode on a resolution of 1920 by 1080
im trying to transform world space XYZ to screen XY but somehow the results are not how they should be (different values from what they should be).
Here my code (yes it's hazardedits approach):
Code:
Code:
float viewMatrix[4][4];
ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dwViewMatrix), &viewMatrix, sizeof(viewMatrix), 0);
//its shortened, so structures dont make any sense but those are the basic code snippets
void world_to_screen() {
//screenX = info.viewMatrix[0][0] * ent.bones.y + info.viewMatrix[1][0] * ent.bones.z + info.viewMatrix[2][0] * ent.bones.x + info.viewMatrix[3][0];
//screenY = info.viewMatrix[0][1] * ent.bones.y + info.viewMatrix[1][1] * ent.bones.z + info.viewMatrix[2][1] * ent.bones.x + info.viewMatrix[3][1];
//W = info.viewMatrix[0][3] * ent.bones.y + info.viewMatrix[1][3] * ent.bones.z + info.viewMatrix[2][3] * ent.bones.x + info.viewMatrix[3][3];
screenX = info.viewMatrix[0][0] * ent.bones.y + info.viewMatrix[0][1] * ent.bones.z + info.viewMatrix[0][2] * ent.bones.x + info.viewMatrix[0][3];
screenY = info.viewMatrix[1][0] * ent.bones.y + info.viewMatrix[1][1] * ent.bones.z + info.viewMatrix[1][2] * ent.bones.x + info.viewMatrix[1][3];
W = info.viewMatrix[3][0] * ent.bones.y + info.viewMatrix[3][1] * ent.bones.z + info.viewMatrix[3][2] * ent.bones.x + info.viewMatrix[3][3];
W_Old = W;
screenX *= 1 / W;
screenY *= 1 / W;
screenX = (1920 / 2) + 0.5 * screenX * 1920 + 0.5;
screenY = (1080 / 2) + 0.5 * screenY * 1080 + 0.5;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
cout << info.viewMatrix[i][j] << endl;
}
}
The output when looking right at the enemys head:
//this is the matrix
0.715753
0.22405
-2.44487e-09
-498.291
0.0297045
-0.0948945
1.32962
-158.703
-0.297975
0.951914
0.0745947
-405.814
-0.297901
0.951679
0.0745763
-398.714
//output
screenX: 1056.77
screenY: -79.9052
w (if>0 = onscreen; if=<0 not onscreen): -459.501
whats wrong? i also tried offsetting the viewmatrix by 0x4 bytes but the results were not good aswell.
Some additional info:
im playing in windowed mode on a resolution of 1920 by 1080