-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculate.cs
More file actions
59 lines (53 loc) · 2.17 KB
/
Calculate.cs
File metadata and controls
59 lines (53 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Numerics;
using Swed64;
namespace FutaZone
{
public static class Calculate
{
public static Vector2 WorldToScreen(float[] matrix, Vector3 position, Vector2 screenSize)
{
//calculate screenwidth
float screenWidth = (matrix[12] * position.X) + (matrix[13] * position.Y) + (matrix[14] * position.Z) + matrix[15];
//if entity is in front of us
if (screenWidth > 0.001f)
{
//calculate screen X and Y
float screenX = (matrix[0] * position.X) + (matrix[1] * position.Y) + (matrix[2] * position.Z) + matrix[3];
float screenY = (matrix[4] * position.X) + (matrix[5] * position.Y) + (matrix[6] * position.Z) + matrix[7];
//perform perspective division
float X = (screenSize.X / 2) + (screenSize.X / 2) * (screenX / screenWidth);
float Y = (screenSize.Y / 2) - (screenSize.Y / 2) * (screenY / screenWidth);
return new Vector2(X, Y);
}
else
{
//enemy is behind us, return offscreen coordinates
return new Vector2(-99, -99);
}
}
public static List<Vector3> ReadBones(IntPtr boneAddress, Swed swed)
{
byte[] boneBytes = swed.ReadBytes(boneAddress, 30 * 32 + 16);
List<Vector3> bones = new List<Vector3>();
for (int i = 0; i < 30; i++)
{
float x = BitConverter.ToSingle(boneBytes, i * 32 + 0);
float y = BitConverter.ToSingle(boneBytes, i * 32 + 4);
float z = BitConverter.ToSingle(boneBytes, i * 32 + 8);
bones.Add(new Vector3(x, y, z));
}
return bones;
}
public static List<Vector2> ReadBones2D(List<Vector3> bones, float[] viewMatrix, Vector2 screenSize)
{
List<Vector2> bones2d = new List<Vector2>();
foreach (var bone in bones)
{
bones2d.Add(WorldToScreen(viewMatrix, bone, screenSize));
}
return bones2d;
}
}
}