Add method for generating a rotated triangle at a cartesian coordinate.
This commit is contained in:
parent
16845e14af
commit
f4d7165f4c
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -66,69 +67,19 @@ namespace MW2_Ultimate_Hacks
|
||||
Bitmap old = new Bitmap(Map);
|
||||
g = Graphics.FromImage(Map);
|
||||
Pen player = new Pen(Color.Black);
|
||||
int x = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F418C);
|
||||
|
||||
var x = ProcessManager.ReadFloatRelative((IntPtr)0x3F418C);
|
||||
var y = ProcessManager.ReadFloatRelative((IntPtr)0x3F4188);
|
||||
var azimuth = ProcessManager.ReadFloatRelative((IntPtr)0x3F41B0) + 180;
|
||||
|
||||
// Scale to fit.
|
||||
x = x / 10;
|
||||
int y = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F4188);
|
||||
y += 2000;
|
||||
y = y / 10;
|
||||
//g.DrawEllipse(player, new Rectangle(x, y, 5, 5));
|
||||
//g.FillEllipse(Brushes.Black, new Rectangle(x, y, 5, 5));
|
||||
y = (y + 2000) / 10;
|
||||
|
||||
// calculate polygone points
|
||||
int h = 20;
|
||||
int triangleAngle = 30;
|
||||
double azimuth = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F41B0) +180;
|
||||
double angle = azimuth - (triangleAngle / 2);
|
||||
angle = (angle / 360) * (2 * Math.PI);
|
||||
|
||||
int dx = (int)(Math.Cos(angle) * h);
|
||||
int dy = (int)(Math.Sin(angle) * h);
|
||||
|
||||
int x1, x2, y1, y2;
|
||||
|
||||
if(angle < 90)
|
||||
{
|
||||
x1 = x + dx;
|
||||
y1 = y - dy;
|
||||
x2 = x - dy;
|
||||
y2 = y - dx;
|
||||
Debug.WriteLine("Case 1: (" + x + "," + y + ")(" + x1 +"," + y1 + ")(" + x2 + "," + y2 + ")");
|
||||
}
|
||||
else if(angle < 180)
|
||||
{
|
||||
x1 = x + dx;
|
||||
y1 = y + dy;
|
||||
x2 = x + dy;
|
||||
y2 = y + dx;
|
||||
Debug.WriteLine("Case 2: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
|
||||
}
|
||||
else if(angle < 270)
|
||||
{
|
||||
x1 = x - dx;
|
||||
y1 = y + dy;
|
||||
x2 = x - dy;
|
||||
y2 = y + dx;
|
||||
Debug.WriteLine("Case 3: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x - dx;
|
||||
y1 = y - dy;
|
||||
x2 = x - dy;
|
||||
y2 = y - dx;
|
||||
Debug.WriteLine("Case 4: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
|
||||
|
||||
}
|
||||
|
||||
Point[] triangle =
|
||||
{
|
||||
new Point(x,y),
|
||||
new Point(x1, y1),
|
||||
new Point(x2,y2)
|
||||
};
|
||||
var triangle = GenerateTriangle(x, y, azimuth);
|
||||
g.DrawPolygon(player, triangle);
|
||||
|
||||
Map.RotateFlip(RotateFlipType.RotateNoneFlipXY);
|
||||
pbMap.Image = Map;
|
||||
Map = old;
|
||||
g.Dispose();
|
||||
@ -138,5 +89,29 @@ namespace MW2_Ultimate_Hacks
|
||||
{
|
||||
UpdatePlayerStats();
|
||||
}
|
||||
|
||||
private Point[] GenerateTriangle(float x, float y, float angle)
|
||||
{
|
||||
var width = 20;
|
||||
var height = 50;
|
||||
|
||||
// Verticies of a triangle around origin.
|
||||
var triangle = new Point[]
|
||||
{
|
||||
new Point(-width/2, height/2),
|
||||
new Point(width/2, height/2),
|
||||
new Point(0, -height/2)
|
||||
};
|
||||
|
||||
var rotationMatrix = new Matrix();
|
||||
rotationMatrix.Rotate(-angle);
|
||||
rotationMatrix.TransformPoints(triangle);
|
||||
|
||||
var translationMatrix = new Matrix();
|
||||
translationMatrix.Translate(x, y);
|
||||
translationMatrix.TransformPoints(triangle);
|
||||
|
||||
return triangle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user