Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static float[] ReadMatrix(long Address)
- {
- byte[] numArray = new byte[64];
- numArray = Program.CorrM.MemLib.readBytes(Address.ToString("X"), numArray.Length);
- return ConvertToFloatArray(numArray);
- }
- public static float[] ConvertToFloatArray(byte[] bytes)
- {
- if ((bytes.Length % 4) > 0) throw new ArgumentException();
- float[] numArray = new float[bytes.Length / 4];
- for (int index = 0; index < numArray.Length; ++index)
- {
- numArray[index] = BitConverter.ToSingle(bytes, index * 4);
- }
- return numArray;
- }
- bool WorldToScreenCpp(Vector3 position, out Vector2 Screen)
- {
- Screen = new Vector2();
- GetWindowRect(EmulatorRenderBox, out Vector2 ScreenSize);
- float[] viewMatrix = ReadMatrix(AddressSaver.Matrix);
- double x = (position.X * viewMatrix[0] + position.Y * viewMatrix[4] + position.Z * viewMatrix[8]) + viewMatrix[12];
- double y = (position.X * viewMatrix[1] + position.Y * viewMatrix[5] + position.Z * viewMatrix[9]) + viewMatrix[13];
- double w = (position.X * viewMatrix[3] + position.Y * viewMatrix[7] + position.Z * viewMatrix[11]) + viewMatrix[15];
- if (w < 0.100000001490116)
- return false;
- int width = (int)ScreenSize.X;
- int height = (int)ScreenSize.Y;
- x /= w;
- y /= w;
- float halfW = width / 2;
- float halfH = height / 2;
- Screen.X = (float)(halfW * x + (x + halfW));
- Screen.Y = (float)(-(halfH * y) + (y + halfH));
- return true;
- }
- bool WorldToScreenCpp2(Vector3 pos, out Vector2 screen)
- {
- screen = new Vector2(0, 0);
- float[] matrixF = ReadMatrix(AddressSaver.Matrix);
- // NOT inversed matrix.
- Vector3 clipCoords = new Vector3
- {
- X = pos.X * matrixF[0] + pos.Z * matrixF[4] + pos.Y * matrixF[8] + matrixF[12],
- Y = pos.X * matrixF[1] + pos.Z * matrixF[5] + pos.Y * matrixF[9] + matrixF[13],
- Z = pos.X * matrixF[3] + pos.Z * matrixF[7] + pos.Y * matrixF[11] + matrixF[15]
- };
- if (clipCoords.Z < 0.100000001490116)
- return false;
- Vector3 SP = new Vector3
- {
- X = clipCoords.X / clipCoords.Z,
- Y = clipCoords.Y / clipCoords.Z
- };
- GetWindowRect(EmulatorRenderBox, out Vector2 ScreenSize);
- screen.X = (ScreenSize.X / 2 * SP.X) + (SP.X + ScreenSize.X / 2);
- screen.Y = -(ScreenSize.Y / 2 * SP.Y) + (SP.Y + ScreenSize.Y / 2);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement