protected void TiltedRectangle(float cx, float cy, float w, float h, float angle) { double da = Arith.DegreeToRadian(angle); double sina = Math.Sin(da); double cosa = Math.Cos(da); double dw = 0.5 * w; double dh = 0.5 * h; double dax = dw * cosa + dh * sina; double day = -dw * sina + dh * cosa; double dbx = -dw * cosa + dh * sina; double dby = dw * sina + dh * cosa; // A, B, -A, -B path.Reset(); path.AddLine((float)(cx + dax), (float)(cy + day), (float)(cx + dbx), (float)(cy + dby)); path.AddLine((float)(cx - dax), (float)(cy - day), (float)(cx - dbx), (float)(cy - dby)); path.AddLine((float)(cx + dax), (float)(cy + day), (float)(cx + dbx), (float)(cy + dby)); }
protected void FillSlice(Graphics g, Color c, float angle, float width) { Brush b = new SolidBrush(c); GraphicsPath p = new GraphicsPath(); p.AddArc(xy1, xy1, size1, size1, angle, width); double sina = Math.Sin(Arith.DegreeToRadian(angle + width)); double cosa = Math.Cos(Arith.DegreeToRadian(angle + width)); p.AddLine((float)(cxy + r1 * cosa), (float)(cxy + r1 * sina), (float)(cxy + r2 * cosa), (float)(cxy + r2 * sina)); p.AddArc(xy2, xy2, size2, size2, angle + width, -width); p.CloseFigure(); g.FillPath(b, p); }
/// <summary> /// Update rendering/trackball parameters. /// </summary> /// <param name="param">User-provided parameter string.</param> public void UpdateRenderingParams(Dictionary <string, string> p) { // Input params. if (p.Count == 0) { return; } // Trackball: zoom limits. float minZoom = tb.MinZoom; float maxZoom = tb.MaxZoom; if (Util.TryParse(p, "minZoom", ref minZoom)) { tb.MinZoom = Math.Max(1.0e-4f, maxZoom); } if (Util.TryParse(p, "maxZoom", ref maxZoom)) { tb.MaxZoom = Arith.Clamp(maxZoom, minZoom, 1.0e6f); } // Trackball: zoom. float zoom = tb.Zoom; if (Util.TryParse(p, "zoom", ref zoom)) { tb.Zoom = Arith.Clamp(zoom, tb.MinZoom, tb.MaxZoom); } // Rendering: perspective/orthographic projection. bool perspective = tb.UsePerspective; if (Util.TryParse(p, "perspective", ref perspective)) { tb.UsePerspective = perspective; } // Rendering: vertical field-of-view. float fov = tb.Fov; if (Util.TryParse(p, "fov", ref fov)) { fov = (float)Arith.DegreeToRadian(Arith.Clamp(fov, 0.001f, 170.0f)); if (fov != tb.Fov) { tb.Fov = fov; tb.GLsetupViewport( glControl1.Width, glControl1.Height, gr.near, gr.far); } } // Rendering: background color. Vector3 col = Vector3.Zero; if (Geometry.TryParse(p, "backgr", ref col)) { GL.ClearColor(col.X, col.Y, col.Z, 1.0f); } // Rendering: line width. fov = 1.0f; if (Util.TryParse(p, "line", ref fov)) { GL.LineWidth(Math.Max(0.0f, fov)); } // Shading: light source direction => position. if (Geometry.TryParse(p, "light", ref style.lightDirection)) { if (style.lightDirection.Length < 1.0e-3f) { style.lightDirection = new Vector3(-2, 1, 1); } style.SetLight(tb.Eye.Z * 0.5f, ref style.lightDirection); } // Shading: global material color. if (Geometry.TryParse(p, "color", ref style.matAmbient)) { style.matDiffuse = style.matAmbient; } // Shading: global ambient coeff. fov = 0.2f; if (Util.TryParse(p, "Ka", ref fov)) { style.globalAmbient.X = style.globalAmbient.Y = style.globalAmbient.Z = Util.Clamp(fov, 0.0f, 1.0f); } // Shading: shininess. if (!Util.TryParse(p, "shininess", ref style.matShininess)) { style.matShininess = Arith.Clamp(style.matShininess, 1.0f, 1.0e4f); } }