I fixed my previous issue, but now I need help with something painful. I'm making it display a map of the waypoints, but it's scaling it down way too far. Here's the code:
Code:
Graphics g = Graphics.FromImage(bm);
float XLow, YLow, XHigh, YHigh;
XLow = 0;
YLow = 0;
XHigh = 0;
YHigh = 0;
int index = 0;
XLow = m_parent.wm.waypoints[0].X;
YLow = m_parent.wm.waypoints[0].Y;
foreach (Location loc in m_parent.wm.waypoints)
{
if (XLow > loc.X)
XLow = loc.X;
if (YLow > loc.Y)
YLow = loc.Y;
if (YHigh < loc.Y)
YHigh = loc.Y;
if (XHigh < loc.X)
XHigh = loc.X;
}
List<Point> offsets = new List<Point>();
foreach (Location loc in m_parent.wm.waypoints)
{
offsets.Add(new Point(Convert.ToInt32(loc.X - XLow), Convert.ToInt32(loc.Y - YLow)));
}
float scaleX = XHigh - XLow;
if (scaleX < 0)
scaleX = scaleX * (-1);
float scaleY = YHigh - YLow;
if (scaleY < 0)
scaleY = scaleY * (-1);
scaleX = (pictureBox1.Width / 2) / scaleX;
scaleY = (pictureBox1.Height / 2) / scaleY;
foreach (Point p in offsets)
{
float newX = p.X * scaleX;
float newY = p.Y * scaleY;
newX = (pictureBox1.Width / 2) + newX;
newY = (pictureBox1.Height / 2) + newY;
wps.Add(new Point(Convert.ToInt32(newX), Convert.ToInt32(newY)));
}
foreach (Point pt in wps)
{
bm.SetPixel(pt.X, pt.Y, Color.Red);
g.DrawEllipse(new Pen(Brushes.Blue, 1), new Rectangle(pt.X - 5, pt.Y - 5, 10, 10));
}
while ((index + 1) <= (m_parent.wm.waypoints.Count - 1))
{
g.DrawLine(new Pen(Brushes.Green, 1f), wps[index], wps[index + 1]);
index++;
}
I was hoping on some advice to improve this. I want it so that it will display any size of map, that's why I have the center of my picturebox being in the origin, but I think that may be my issue. I guess it's a possibility that I have to rewrite my code, but I'd rather not. Any suggestions?(BTW Apoc, I hope you don't think this is someone else's code as well, because I just wrote it tonight... Not to mention you're probably the only one here to help)