void generate_grid_lines(LineSet lines, Vector3f axis1, Vector3f axis2, int nExtentCount1, int nExtentCount2, float stepSize) { Vector2f minPos = stepSize * new Vector2f(-nExtentCount1, -nExtentCount2); Vector2f maxPos = stepSize * new Vector2f(nExtentCount1, nExtentCount2); int n1 = 2 * nExtentCount1, n2 = 2 * nExtentCount2; int start1 = (IncludeEnds) ? 0 : 1, end1 = (IncludeEnds) ? n1 : n1 - 1; for (int i1 = start1; i1 <= end1; i1++) { float t = (float)i1 / (float)n1; float tx = MathUtil.Lerp(minPos.x, maxPos.x, t); Vector3f p0 = tx * axis1 + minPos.y * axis2; Vector3f p1 = tx * axis1 + maxPos.y * axis2; lines.Segments.Add(new Segment3d(p0, p1)); } int start2 = (IncludeEnds) ? 0 : 1, end2 = (IncludeEnds) ? n2 : n2 - 1; for (int i2 = start2; i2 <= end2; i2++) { float t = (float)i2 / (float)n2; float ty = MathUtil.Lerp(minPos.y, maxPos.y, t); Vector3f p0 = minPos.x * axis1 + ty * axis2; Vector3f p1 = maxPos.x * axis1 + ty * axis2; lines.Segments.Add(new Segment3d(p0, p1)); } }
void enable_circle_indicator(bool enable) { if (enable == false && circle_indicator == null) { return; } if (enable && circle_indicator == null) { LineSet lines = new LineSet(); lines.UseFixedNormal = true; lines.FixedNormal = Vector3f.AxisY; DCurve3 curve = new DCurve3(Polygon2d.MakeCircle(gizmoInitialRadius, 64), 0, 2); lines.Curves.Add(curve); lines.Width = 1.0f; lines.WidthType = LineWidthType.Pixel; lines.Segments.Add( new Segment3d(Vector3d.Zero, gizmoInitialRadius * diagonals[nRotationAxis])); lines.Color = Colorf.DimGrey; circle_indicator = new fLineSetGameObject(new GameObject(), lines, "circle"); circle_indicator.SetLayer(FPlatform.WidgetOverlayLayer, true); circle_indicator.SetLocalRotation(Quaternionf.FromTo(Vector3f.AxisY, Frame3f.Identity.GetAxis(nRotationAxis))); RootGameObject.AddChild(circle_indicator, false); } circle_indicator.SetVisible(enable); }
void draw_lines(LineSet lines, Vector3f cameraPos) { GL.Begin(GL.LINES); GL.Color(lines.Color); int NS = lines.Segments.Count; for (int k = 0; k < NS; ++k) { Segment3d seg = lines.Segments[k]; GL.Vertex((Vector3)seg.P0); GL.Vertex((Vector3)seg.P1); } GL.End(); int NC = lines.Curves.Count; for (int k = 0; k < NC; ++k) { DCurve3 c = lines.Curves[k]; GL.Begin(GL.LINE_STRIP); GL.Color(lines.Color); int NV = c.VertexCount; for (int i = 0; i < NV; ++i) { GL.Vertex((Vector3)c[i]); } if (c.Closed) { GL.Vertex((Vector3)c[0]); } GL.End(); } }
public fLineSetGameObject(GameObject baseGO, LineSet lines, string name = "line") : base(baseGO, FGOFlags.EnablePreRender) { SetName(name); this.lines = lines; LineRenderingManager.AddLineSet(this); }
void draw_quads(LineSet lines, Vector3f cameraPos) { GL.Begin(GL.QUADS); GL.Color(lines.Color); int NS = lines.Segments.Count; for (int k = 0; k < NS; ++k) { Segment3d seg = lines.Segments[k]; Vector3f start = (Vector3f)seg.P0, end = (Vector3f)seg.P1; if (lines.UseFixedNormal) { draw_quad_fixednormal(ref start, ref end, ref lines.FixedNormal, lines.Width); } else { draw_quad_viewalign(ref start, ref end, ref cameraPos, lines.Width); } } int NC = lines.Curves.Count; for (int k = 0; k < NC; ++k) { DCurve3 c = lines.Curves[k]; int NV = c.VertexCount; Vector3f prev = (Vector3f)c[0]; for (int i = 1; i < NV; ++i) { Vector3f cur = (Vector3f)c[i]; if (lines.UseFixedNormal) { draw_quad_fixednormal(ref prev, ref cur, ref lines.FixedNormal, lines.Width); } else { draw_quad_viewalign(ref prev, ref cur, ref cameraPos, lines.Width); } prev = cur; } if (c.Closed) { Vector3f cur = (Vector3f)c[0]; if (lines.UseFixedNormal) { draw_quad_fixednormal(ref prev, ref cur, ref lines.FixedNormal, lines.Width); } else { draw_quad_viewalign(ref prev, ref cur, ref cameraPos, lines.Width); } } } GL.End(); }
void draw_lines(bool depth_test) { foreach (var go_set in Sets) { fGameObject go = go_set.Key; if (go.IsDestroyed) { continue; } LineSet lines = go_set.Value; if (go.IsVisible() == false) { continue; } if (lines.DepthTest != depth_test) { continue; } GL.PushMatrix(); try { Transform transform = ((GameObject)go).transform; GL.MultMatrix(transform.localToWorldMatrix); Vector3f localCam = transform.InverseTransformPoint(CurrentCameraPos); if (lines.WidthType == LineWidthType.Pixel) { if (lines.Width == 1) { draw_lines(lines, localCam); } else { draw_quads(lines, localCam); } } else { draw_quads(lines, localCam); } } catch { throw; } finally { GL.PopMatrix(); } } }
void enable_snap_indicator(bool enable) { if (enable == false && snap_indicator == null) { return; } if (enable && snap_indicator == null) { LineSet lines = new LineSet(); lines.UseFixedNormal = true; lines.FixedNormal = Vector3f.AxisY; int n = 360 / (int)SnapIncrementDeg; int n45 = 45 / (int)SnapIncrementDeg; int n90 = 90 / (int)SnapIncrementDeg; double r = gizmoInitialRadius; double r2 = gizmoInitialRadius * 1.05; double r45 = gizmoInitialRadius * 1.10; double r90 = gizmoInitialRadius * 1.175; for (int k = 0; k < n; ++k) { float angle = ((float)k / (float)n) * MathUtil.TwoPIf; double x = Math.Cos(angle), y = Math.Sin(angle); Vector3d v = new Vector3d(x, 0, y); v.Normalize(); double far_r = ((k + n45) % n90) == 0 ? r90 : (((k + n45) % n45) == 0 ? r45 : r2); lines.Segments.Add(new Segment3d(r * v, far_r * v)); } lines.Width = 1.0f; lines.WidthType = LineWidthType.Pixel; lines.Color = Colorf.DimGrey; snap_indicator = new fLineSetGameObject(new GameObject(), lines, "indicator"); snap_indicator.SetLayer(FPlatform.WidgetOverlayLayer, true); RootGameObject.AddChild(snap_indicator, false); } snap_indicator.SetVisible(enable); }
public void AddLineSet(fGameObject source, LineSet set) { Util.gDevAssert(Sets.ContainsKey(source) == false); Sets[source] = set; }