void IOpenGLDrawable.Draw() { // Draw the tool location as a cone Vector3 position = GetPosition(); GL.Color3(Color.Silver); Polyhedra.DrawCone(position + new Vector3(0, 0, router.ToolDiameter), position, router.ToolDiameter / 2.0f); // Draw the past positions & velocity graph float lastTime = 0; Vector3 lastPos = new Vector3(0, 0, 0); float lastVel = 0; bool lastIsGood = false; GL.Disable(EnableCap.Lighting); lock (previousPoints) { Vector3 lastpoint = new Vector3(0, 0, 0); for (int i = 0; i < previousPoints.Count(); i++) { PreviousPoint point = previousPoints[i]; float age_delta = point.createTime - lastTime; float time = age_delta / 1000.0f; // Age is microseconds, time is seconds float pos_delta = (point.location - lastPos).Length; float vel = pos_delta / time; // Inches per second Vector3 atpoint = new Vector3(point.location.X * 1000, point.location.Y * 1000, point.location.Z * 1000); if (lastIsGood) { GL.LineWidth(1); GL.Begin(PrimitiveType.Lines); GL.Color3(Color.LightGray); for (int j = 0; j < 5; j++) { GL.Vertex3(lastpoint + new Vector3(0, 0, j * 10)); GL.Vertex3(lastpoint + new Vector3(0, 0, j * 10 + 10)); GL.Vertex3(lastpoint + new Vector3(0, 0, j * 10)); GL.Vertex3(atpoint + new Vector3(0, 0, j * 10)); } GL.End(); GL.LineWidth(2); GL.Begin(PrimitiveType.Lines); GL.Color3(Color.Orange); GL.Vertex3(lastpoint + new Vector3(0, 0, lastVel * lastVel * 200)); GL.Vertex3(atpoint + new Vector3(0, 0, vel * vel * 200)); GL.End(); } lastVel = vel; lastpoint = atpoint; lastPos = point.location; lastTime = point.createTime; lastIsGood = true; } } GL.Enable(EnableCap.Lighting); GL.LineWidth(1); }
public void Draw() { GL.PushMatrix(); GL.Translate(locationOffset); if (mouseHovering) { var ticks = DateTime.Now.Ticks; int alpha = (int)(100 * (Math.Sin(((double)(ticks / 10000)) / 300.0d) + 1)); Vector3 location = hoveredPoint; GL.Color4(Color.FromArgb(alpha, Color.Green)); if (selectedTabIndex >= 0) { location = tabLocations[selectedTabIndex]; GL.Color3(Color.Blue); } Polyhedra.DrawCylinderWireMesh(location, location + new Vector3(0, 0, tabHeight), this.tabRadius); } GL.Color3(Color.Orange); if (drawSliceDisplayList > 0) { GL.CallList(drawSliceDisplayList); } else { if (useDisplayLists) { drawSliceDisplayList = GL.GenLists(1); GL.NewList(drawSliceDisplayList, ListMode.CompileAndExecute); } GL.Begin(PrimitiveType.Triangles); GL.Normal3(drawSlice.Plane.Normal); foreach (var triangle in drawSlice.Triangles()) { foreach (var point in triangle.Vertices) { GL.Vertex3(point); } } GL.End(); if (useDisplayLists) { GL.EndList(); } } if (tabLocations.Count == 0) { GL.Color3(Color.DarkRed); if (obliterateIndicateDisplayList > 0) { GL.CallList(obliterateIndicateDisplayList); } else { Slice s = new Slice(Boundary); s.Subtract(drawSlice); obliterateIndicateDisplayList = GL.GenLists(1); GL.NewList(obliterateIndicateDisplayList, ListMode.CompileAndExecute); GL.Begin(PrimitiveType.Triangles); GL.Normal3(s.Plane.Normal); foreach (var triangle in s.Triangles()) { foreach (var point in triangle.Vertices) { GL.Vertex3(point); } } GL.End(); GL.EndList(); } } GL.Color3(Color.DarkOrange); int i = 0; foreach (var tab in tabLocations) { if (!selectedTabDraggedOff || i != selectedTabIndex) { Polyhedra.DrawCylinder(tab + new Vector3(0, 0, .001f), tab + new Vector3(0, 0, tabHeight), this.tabRadius); } i++; } GL.PopMatrix(); }