public void RenderGdi(Graphics graphics, RectangleD cameraBounds)
{
// Update position and rotation given the parent's motion
double currentRotation = (_parent.Pitch - _initialRotation) + _rotationOffset;
DVector2 rotationNormal = DVector2.FromAngle(currentRotation);
Position = _parent.Position + rotationNormal * _initialDistance;
var bounds = new RectangleD(Position.X - Width * 0.5, Position.Y - Height * 0.5, Width, Height);
// Not in range easy return
if (!cameraBounds.IntersectsWith(bounds))
{
return;
}
RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position, cameraBounds, Width, Height);
// Saftey
if (screenBounds.Width > RenderUtils.ScreenWidth * 500) return;
double drawingRotation = currentRotation + Math.PI * 0.5;
var offset = new PointF(screenBounds.X + screenBounds.Width * 0.5f,
screenBounds.Y + screenBounds.Height * 0.5f);
graphics.TranslateTransform(offset.X, offset.Y);
graphics.RotateTransform((float)(drawingRotation * 180 / Math.PI));
graphics.TranslateTransform(-offset.X, -offset.Y);
graphics.DrawImage(_texture, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height);
graphics.ResetTransform();
double visibility = Visibility(cameraBounds);
if (visibility < 1)
{
PointF iconPoint = RenderUtils.WorldToScreen(Position, cameraBounds);
var iconBounds = new RectangleF(iconPoint.X - 5, iconPoint.Y - 5, 10, 10);
var iconColor = Color.FromArgb((int)((1 - visibility) * 255), IconColor.R, IconColor.G, IconColor.B);
graphics.FillEllipse(new SolidBrush(iconColor), iconBounds);
}
}