private void DrawEquationOverScren(List <Vector2> curEquation, string expression) { int gridSize = 50; if (!AdvancedMath.ContainsNewCons(expression, 'y')) { int width = (int)Math.Round(Window.ClientBounds.Width * camera.Zoom / gridSize, MidpointRounding.AwayFromZero); width = (int)Math.Round(Math.Abs(camera.ScreenToWorldSpace(new Vector2(Window.ClientBounds.Width, 0)).X) / gridSize, MidpointRounding.AwayFromZero); //int width = (AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2(0, Window.ClientBounds.Height)).Y), gridSize) + gridSize) - AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2()).X), gridSize); //if (camera.CameraPos().X > 0) //{ // //width = (AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2(0, Window.ClientBounds.Height)).Y), gridSize) + gridSize) + AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2()).X), gridSize); // width = AdvancedMath.GetNearestMultiple(50 * Window.ClientBounds.Width, gridSize); //} int start = ((int)Math.Round(camera.ScreenToWorldSpace(new Vector2(0, 0)).X / gridSize, MidpointRounding.AwayFromZero)); float timeStep = (float)(-Math.Pow(camera.Zoom, 1.7f) / 23f + 0.7f); if (expression.Contains("tan")) { timeStep = Math.Clamp(timeStep, 0.01f, 0.04f); } SetEquation(curEquation, start - 50, Math.Abs(width - start) + 50 * 2, expression, timeStep); } else { //int height = (AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2(Window.ClientBounds.Width, 0)).X), gridSize) + gridSize) - AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2()).X), gridSize); //int height = AdvancedMath.GetNearestMultiple(50 * Window.ClientBounds.Height, gridSize); //int height = Window.ClientBounds.Height / gridSize; //SetEquation(curEquation, AdvancedMath.GetNearestMultiple((int)Math.Round(camera.ScreenToWorldSpace(new Vector2()).X), gridSize) / gridSize, height / gridSize, expression); int height = (int)Math.Round(Math.Abs(camera.ScreenToWorldSpace(new Vector2(0, Window.ClientBounds.Height)).Y) / gridSize, MidpointRounding.AwayFromZero); int start = ((int)Math.Round(camera.ScreenToWorldSpace(new Vector2(0, 0)).Y / gridSize, MidpointRounding.AwayFromZero)); SetEquation(curEquation, start - 50, Math.Abs(height - start) + 50 * 2, expression); } }
private void SetEquation(List <Vector2> curEquation, int start, int iterations, string expression, float timeSteps) { curEquation.Clear(); int width = 50; iterations += start; if (!AdvancedMath.ContainsNewCons(expression, 'y')) { for (float x = start; x <= iterations; x += timeSteps) { string newExpress = AdvancedMath.ReplaceXWithConstant(expression, x, "x"); curEquation.Add(new Vector2(x * width, -((float)AdvancedMath.Eval(newExpress) * width))); } } else { try { for (float y = start; y <= iterations; y += timeSteps) { string newExpress = AdvancedMath.ReplaceXWithConstant(expression, y, "y"); curEquation.Add(new Vector2(((float)AdvancedMath.Eval(newExpress) * width), -y * width)); } AdvancedMath.ResetX(); } catch (Exception) { AdvancedMath.ResetX(); throw; } } }