public static (float x, float z) ConvertCoordsForControlOrthographicView(float x, float y, float z) { x = Config.MapGraphics.MapViewEnablePuView ? x : (float)PuUtilities.GetRelativeCoordinate(x); y = Config.MapGraphics.MapViewEnablePuView ? y : (float)PuUtilities.GetRelativeCoordinate(y); z = Config.MapGraphics.MapViewEnablePuView ? z : (float)PuUtilities.GetRelativeCoordinate(z); float xOffset = x - Config.MapGraphics.MapViewCenterXValue; float yOffset = y - Config.MapGraphics.MapViewCenterYValue; float zOffset = z - Config.MapGraphics.MapViewCenterZValue; double angleRadians = MoreMath.AngleUnitsToRadians(Config.MapGraphics.MapViewYawValue); float hOffset = (float)(Math.Sin(angleRadians) * zOffset - Math.Cos(angleRadians) * xOffset); (double x0, double y0, double z0, double t0) = MoreMath.GetPlaneLineIntersection( Config.MapGraphics.MapViewCenterXValue, Config.MapGraphics.MapViewCenterYValue, Config.MapGraphics.MapViewCenterZValue, Config.MapGraphics.MapViewYawValue, Config.MapGraphics.MapViewPitchValue, x, y, z, Config.MapGraphics.MapViewYawValue, Config.MapGraphics.MapViewPitchValue); double rightYaw = MoreMath.RotateAngleCW( Config.MapGraphics.MapViewYawValue, 16384); (double x1, double y1, double z1, double t1) = MoreMath.GetPlaneLineIntersection( x0, y0, z0, rightYaw, 0, Config.MapGraphics.MapViewCenterXValue, Config.MapGraphics.MapViewCenterYValue, Config.MapGraphics.MapViewCenterZValue, rightYaw, 0); double hDiff = MoreMath.GetDistanceBetween(x1, z1, x0, z0); double yDiff = y1 - y0; double yDiffSign = Math.Sign(yDiff); double vOffsetMagnitude = MoreMath.GetHypotenuse(hDiff, yDiff); float vOffset = (float)(vOffsetMagnitude * yDiffSign); float hOffsetPixels = hOffset * Config.MapGraphics.MapViewScaleValue; float vOffsetPixels = vOffset * Config.MapGraphics.MapViewScaleValue; float centerH = Config.MapGui.GLControlMap2D.Width / 2 + hOffsetPixels; float centerV = Config.MapGui.GLControlMap2D.Height / 2 + vOffsetPixels; return(centerH, centerV); }
/** Takes in in-game coordinates, outputs control coordinates. */ public static (float x, float z) ConvertCoordsForControlTopDownView(float x, float z) { x = Config.MapGraphics.MapViewEnablePuView ? x : (float)PuUtilities.GetRelativeCoordinate(x); z = Config.MapGraphics.MapViewEnablePuView ? z : (float)PuUtilities.GetRelativeCoordinate(z); float xOffset = x - Config.MapGraphics.MapViewCenterXValue; float zOffset = z - Config.MapGraphics.MapViewCenterZValue; (float xOffsetRotated, float zOffsetRotated) = ((float, float))MoreMath.RotatePointAboutPointAnAngularDistance( xOffset, zOffset, 0, 0, -1 * Config.MapGraphics.MapViewYawValue); float xOffsetPixels = xOffsetRotated * Config.MapGraphics.MapViewScaleValue; float zOffsetPixels = zOffsetRotated * Config.MapGraphics.MapViewScaleValue; float centerX = Config.MapGui.GLControlMap2D.Width / 2 + xOffsetPixels; float centerZ = Config.MapGui.GLControlMap2D.Height / 2 + zOffsetPixels; return(centerX, centerZ); }
public static (float x, float z) ConvertCoordsForControlOrthographicView(float rawX, float rawY, float rawZ, bool useRelativeCoordinates) { float x = rawX; float y = rawY; float z = rawZ; if (useRelativeCoordinates) { x = (float)PuUtilities.GetRelativeCoordinate(rawX); y = (float)PuUtilities.GetRelativeCoordinate(rawY); z = (float)PuUtilities.GetRelativeCoordinate(rawZ); } float xOffset = x - Config.CurrentMapGraphics.MapViewCenterXValue; float yOffset = y - Config.CurrentMapGraphics.MapViewCenterYValue; float zOffset = z - Config.CurrentMapGraphics.MapViewCenterZValue; double angleRadians = MoreMath.AngleUnitsToRadians(Config.CurrentMapGraphics.MapViewYawValue); float hOffset = (float)(Math.Sin(angleRadians) * zOffset - Math.Cos(angleRadians) * xOffset); (double x0, double y0, double z0, double t0) = MoreMath.GetPlaneLineIntersection( Config.CurrentMapGraphics.MapViewCenterXValue, Config.CurrentMapGraphics.MapViewCenterYValue, Config.CurrentMapGraphics.MapViewCenterZValue, Config.CurrentMapGraphics.MapViewYawValue, Config.CurrentMapGraphics.MapViewPitchValue, x, y, z, Config.CurrentMapGraphics.MapViewYawValue, Config.CurrentMapGraphics.MapViewPitchValue); double rightYaw = MoreMath.RotateAngleCW( Config.CurrentMapGraphics.MapViewYawValue, 16384); (double x1, double y1, double z1, double t1) = MoreMath.GetPlaneLineIntersection( x0, y0, z0, rightYaw, 0, Config.CurrentMapGraphics.MapViewCenterXValue, Config.CurrentMapGraphics.MapViewCenterYValue, Config.CurrentMapGraphics.MapViewCenterZValue, rightYaw, 0); double hDiff = MoreMath.GetDistanceBetween(x1, z1, x0, z0); double yDiff = y1 - y0; double yDiffSign = yDiff >= 0 ? 1 : -1; double vOffsetMagnitude = MoreMath.GetHypotenuse(hDiff, yDiff); float vOffset = (float)(vOffsetMagnitude * yDiffSign); float hOffsetPixels = hOffset * Config.CurrentMapGraphics.MapViewScaleValue; float vOffsetPixels = vOffset * Config.CurrentMapGraphics.MapViewScaleValue; float centerH = Config.MapGui.CurrentControl.Width / 2 + hOffsetPixels; float centerV = Config.MapGui.CurrentControl.Height / 2 + vOffsetPixels; if (Config.CurrentMapGraphics.MapViewPitchValue == 0 && float.IsInfinity(rawX)) { float yOffsetPixels = yOffset * Config.CurrentMapGraphics.MapViewScaleValue; float centerY = Config.MapGui.CurrentControl.Height / 2 - yOffsetPixels; if (float.IsNegativeInfinity(rawX)) { return(0, centerY); } else { return(Config.MapGui.CurrentControl.Width, centerY); } } return(centerH, centerV); }