-
Member
Does CGWorldFrame::GetScreenCoordinates no longer exist in Retail?
I matched a lot of binary files and found CGWorldFrame::GetScreenCoordinates in 6.x x64 but not found in the binary file in 9.x version,
and NDCToDDC is only called by one function.
If don’t have this function, only use camera?
-
Contributor
Originally Posted by
34D
I matched a lot of binary files and found CGWorldFrame::GetScreenCoordinates in 6.x x64 but not found in the binary file in 9.x version,
and NDCToDDC is only called by one function.
If don’t have this function, only use camera?
I use d3d and it's like 3 function calls and adapts to the games built in aspect ratio as the window size changes and all that.
I've noticed a lot of methods are becoming inlined I do not know if this was one of them, I never cared to search for it.
-
Member
At present, I have obtained the screen coordinates normally through the camera offset and the camera matrix.
if (screenPos.x < 0 || screenPos.y < 0 || screenPos.x > rect.right || screenPos.y > rect.bottom)
return CVector2{ 0,0 };
If this part of the algorithm exceeds the window range, it will display 0,0
Currently I want to return the coordinates outside the window normally
In the game, the screen coordinates of the unit and the end coordinates of the 40 yards away from the direction of the unit are obtained.
If the coordinates of the start point or the end point are on the screen, then the start coordinates of the cut line segment within the window will be intercepted.
I am not very proficient in mathematics. How should this algorithm be designed? Hope someone can help
-
Member
I think it is still there and I've been using it like before. Offset Rebased 0x23DEA90
-
Post Thanks / Like - 1 Thanks
34D (1 members gave Thanks to hjalplos for this useful post)
-
Active Member
Originally Posted by
hjalplos
I think it is still there and I've been using it like before. Offset Rebased 0x23DEA90
Are you sure that offset is correct? It leads to the middle of a function for me on 2.5.2.40045
-
Member
This thread was about Retail? TBC should be: 0x1BAA030 latest update. Haven't tried it.
-
Member
Originally Posted by
hjalplos
I think it is still there and I've been using it like before. Offset Rebased 0x23DEA90
thanks. Does DDCToNDC exist? I found NDCToDDC and DDCToNDCHeight DDCToNDCWidth. But I didn’t find DDCToNDC around them.
Last edited by 34D; 09-08-2021 at 09:21 PM.
-
Member
Haven't used those. I do divide with the "fovy" and fovx" from the camera on the Vector2 from the Call to CGWorldFrame::GetScreenCoordinates. I might call those two wrong? It works with all aspects atleast.
Code:
float fovy;
fovy = *(float*)(CamAddr+0x19c-4);
float fovx;
fovx = *(float*)(CamAddr+0x19c);
With those two floats I do the rest in Lua in game. (X * GetScreenWidth() for example)
But most people probably don't use LibDraw?
-
Active Member
Originally Posted by
hjalplos
Haven't used those. I do divide with the "fovy" and fovx" from the camera on the Vector2 from the Call to CGWorldFrame::GetScreenCoordinates. I might call those two wrong? It works with all aspects atleast.
Code:
float fovy;
fovy = *(float*)(CamAddr+0x19c-4);
float fovx;
fovx = *(float*)(CamAddr+0x19c);
With those two floats I do the rest in Lua in game. (X * GetScreenWidth() for example)
But most people probably don't use LibDraw?
Ah yes, I was talking about tbcc, not retail. What fov values/offsets would you use to get this working in tbcc? Seems like I can't just do x * screenwidth to get the correct location on my screen.
-
Member
I use the same offsets from Camera Address for TBC. Let's say you have your Vector2 from getscreencoords function then just divide the .X with fovx and vice versa.
Should be good. I read the CameraBase Ptr to get the CamAddr.
-
Active Member
Originally Posted by
hjalplos
I use the same offsets from Camera Address for TBC. Let's say you have your Vector2 from getscreencoords function then just divide the .X with fovx and vice versa.
Should be good. I read the CameraBase Ptr to get the CamAddr.
huh interesting. +19c is giving me a value of 0.0f. Are you getting the camera pointer from worldframe+0x38e0?
-
Banned
My code,convert from C++ from somewhere
Code:
public float[] WorldToScreen(float[] position)
{
const float deg2rad = 0.01745329251f;
var unitPosition = new Vector3(position[0], position[1], position[2]);
var camera = GetCamera();
var cameraPostion = new Vector3(Memory.Read<float>(camera + 0x10), Memory.Read<float>(camera + 0x14), Memory.Read<float>(camera + 0x18));
var diffPosition = unitPosition - cameraPostion;
Matrix3x3 matrix = Memory.Read<Matrix3x3>(camera + 0x1C);
float product = diffPosition.X * matrix.M11 + diffPosition.Y * matrix.M12 + diffPosition.Z * matrix.M13;
var fov = Memory.Read<float>(camera + 0x40);
if (product < 0) return new float[] { 0, 0 };
matrix.Invert();
var view = new Vector3(
matrix.M11 * diffPosition.X + matrix.M21 * diffPosition.Y + matrix.M31 * diffPosition.Z,
matrix.M12 * diffPosition.X + matrix.M22 * diffPosition.Y + matrix.M32 * diffPosition.Z,
matrix.M13 * diffPosition.X + matrix.M23 * diffPosition.Y + matrix.M33 * diffPosition.Z
);
var cameraView = new Vector3(-view.Y, -view.Z, view.X);
RECT WindowRect = new RECT();
GetWindowRect(Memory.Process.MainWindowHandle, ref WindowRect);
var gameScreen = new float[] { (WindowRect.Right - WindowRect.Left) / 2, (WindowRect.Bottom - WindowRect.Top) / 2 };
var aspect = new double[] { gameScreen[0] / Math.Tan((fov * 55.0f / 2.0f) * deg2rad), gameScreen[1] / Math.Tan(((fov * 35.0f) / 2.0f) * deg2rad) };
float[] screenPos = new float[] {
gameScreen[0] + cameraView.X * (float)aspect[0] / cameraView.Z,
gameScreen[1] + cameraView.Y * (float)aspect[1] / cameraView.Z};
if (gameScreen[0] < 0 || gameScreen[1] < 0 || gameScreen[0] > WindowRect.Right || gameScreen[1] > WindowRect.Bottom) return new float[] { 0, 0 };
return screenPos;
}
Retail&Classic share same code.(Camera struct is same)
-
Member
Originally Posted by
scimmy
huh interesting. +19c is giving me a value of 0.0f. Are you getting the camera pointer from worldframe+0x38e0?
My CamBase Ptr is actually the same as CurrentWorldFrame Ptr so I might have mixed things up. still should work for you too. So try the +19c from the current world frame instead.