private void _Init() { _glPanel3D = new GLPanel3D(Colors.Black); _glPanel3D.RotationSensitivity = 0.2f; GD_3D.Children.Add(_glPanel3D); _meshModel = new GLMeshModel3D() { Mode = GLPrimitiveMode.GL_TRIANGLES }; _meshModel.AddMaterial(new DiffuseMaterial() { Color = Colors.White }, MaterialOption.Front); _meshModel.AddMaterial(new SpecularMaterial() { Color = Colors.White, SpecularPower = 128 }, MaterialOption.Front); _visual3D = new GLVisual3D(); _visual3D.Model = _meshModel; _glPanel3D.AddVisual(_visual3D); _glPanel3D.AddLight(new AmbientLight(Colors.White, 0.2f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(1, 0, 0), 0.15f, 0.1f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(-1, 0, 0), 0.15f, 0.1f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(0, 1, 0), 0.15f, 0.1f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(0, -1, 0), 0.15f, 0.1f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(0, 0, 1), 0.15f, 0.1f)); _glPanel3D.AddLight(new DirectionLight(Colors.White, new Vector3F(0, 0, -1), 0.15f, 0.1f)); }
public virtual void Dispose() { _model?.Dispose(); Model = null; _viewport = null; Clean(); }
public static RectF Transform(Rect3F rect, GLPanel3D viewport) { if (rect.IsEmpty) { return(RectF.Empty); } var p1 = rect.Location; var p2 = p1 + new Vector3F(rect.SizeX, 0, 0); var p3 = p1 + new Vector3F(0, rect.SizeY, 0); var p4 = p1 + new Vector3F(0, 0, rect.SizeZ); var p5 = p1 + new Vector3F(rect.SizeX, rect.SizeY, 0); var p6 = p1 + new Vector3F(rect.SizeX, 0, rect.SizeZ); var p7 = p1 + new Vector3F(0, rect.SizeY, rect.SizeZ); var p8 = p1 + new Vector3F(rect.SizeX, rect.SizeY, rect.SizeZ); var ret = RectF.Empty; ret.Union(viewport.Point3DToPointInWpf(p1)); ret.Union(viewport.Point3DToPointInWpf(p2)); ret.Union(viewport.Point3DToPointInWpf(p3)); ret.Union(viewport.Point3DToPointInWpf(p4)); ret.Union(viewport.Point3DToPointInWpf(p5)); ret.Union(viewport.Point3DToPointInWpf(p6)); ret.Union(viewport.Point3DToPointInWpf(p7)); ret.Union(viewport.Point3DToPointInWpf(p8)); return(ret); }
internal Camera(GLPanel3D viewPort, CameraType type , float width, float height, float nearPlaneDistance, float farPlaneDistance , Point3F position, Vector3F lookDirection, Vector3F upDirection) { _viewPort = viewPort; _type = type; SetOrthographicParameters(width, height, nearPlaneDistance, farPlaneDistance); SetPerspectiveParameters(45, width / height, nearPlaneDistance, farPlaneDistance); SetViewParameters(position, lookDirection, upDirection); }
public MainWindow() { InitializeComponent(); Loaded += OnLoaded; _glPanel = new GLPanel(new PointF(0, 0), Colors.Black, 60, YOpenGL.RenderMode.Async, ResourceMode.Normal); _glPanel3D = new GLPanel3D(Colors.Black); GD_2D.Children.Add(_glPanel); GD_3D.Children.Add(_glPanel3D); _InitModel(); WindowState = WindowState.Normal; }
internal static IEnumerable <HitResult> HitTest(GLPanel3D viewport, PointF pointInWpf, float sensitive) { var results = new List <HitResult>(); if (!viewport.Camera.TotalTransformReverse.HasValue) { return(results); } foreach (var visusl in viewport.Visuals.Where(v => v.IsVisible && v.IsHitTestVisible && v.Model != null)) { _HitTest(viewport, pointInWpf, sensitive, results, visusl.Model); } return(results.OrderBy(ret => ret.ZDepth)); }
public static IEnumerable <HitResult> HitTest(GLPanel3D viewport, PointF pointInWpf, IEnumerable <IHitTestSource> models, float sensitive = 5) { var results = new List <HitResult>(); if (!viewport.Camera.TotalTransformReverse.HasValue) { return(results); } foreach (var model in models) { _HitTest(viewport, pointInWpf, sensitive, results, model); } return(results.OrderBy(ret => ret.ZDepth)); }
public RectSelector(GLPanel3D viewport) { _viewport = viewport; _fill = new RectFill(); _wireframe = new RectWireframe(); _selectorVisual = new GLVisual3D() { IsHitTestVisible = false }; var group = new GLModel3DGroup(); group.AddChild(_wireframe); group.AddChild(_fill); _selectorVisual.Model = group; }
internal static IEnumerable <RectHitResult> HitTest(GLPanel3D viewport, RectF rectInWpf, RectHitTestMode hitTestMode) { var results = new List <RectHitResult>(); if (!viewport.Camera.TotalTransformReverse.HasValue) { return(results); } var isFullContain = hitTestMode == RectHitTestMode.FullContain; foreach (var visusl in viewport.Visuals.Where(v => v.IsVisible && v.IsHitTestVisible && v.Model != null)) { _HitTest(viewport, rectInWpf, visusl.Model, results, isFullContain); } return(results); }
public static IEnumerable <RectHitResult> HitTest(GLPanel3D viewport, IEnumerable <IHitTestSource> models, RectF rectInWpf, RectHitTestMode hitTestMode) { var results = new List <RectHitResult>(); if (!viewport.Camera.TotalTransformReverse.HasValue) { return(results); } var isFullContain = hitTestMode == RectHitTestMode.FullContain; foreach (var model in models) { _HitTest(viewport, rectInWpf, model, results, isFullContain); } return(results); }
public virtual void Dispose() { Clean(); _materials = null; _viewport = null; }
private static bool _HitTest(GLPanel3D viewport, PointF pointInWpf, float sensitive, List <HitResult> results, IHitTestSource model) { if (model is GLModel3DGroup) { var group = model as GLModel3DGroup; foreach (var child in group.Children) { if (_HitTest(viewport, pointInWpf, sensitive, results, child)) { return(true); } } return(false); } else { //var meshModel = model as GLMeshModel3D; var bounds3D = model.Bounds; var bounds2D = Math3DHelper.Transform(bounds3D, viewport); var sensity = sensitive; switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_LOOP: case GLPrimitiveMode.GL_LINE_STRIP: if (!bounds2D.IsEmpty) { sensity += model.Mode == GLPrimitiveMode.GL_POINTS ? model.PointSize / 2 : model.LineWidth / 2; bounds2D.Extents(sensity); } break; case GLPrimitiveMode.GL_TRIANGLES: case GLPrimitiveMode.GL_TRIANGLE_STRIP: case GLPrimitiveMode.GL_TRIANGLE_FAN: break; } if (!bounds2D.Contains(pointInWpf)) { return(false); } var points = model.GetHitTestPoints().ToArray(); var pointsTransformed = new LazyArray <Point3F, Point3F>(points, p => viewport.Point3DToPointInWpfWithZDpeth(p)); switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: { if (model.Pairs == null) { if (_HitTestPointResult(model, new DataPair(0, points.Length), points, pointsTransformed, results, pointInWpf, sensity)) { return(true); } } else { foreach (var pair in model.Pairs) { if (_HitTestPointResult(model, pair, points, pointsTransformed, results, pointInWpf, sensity)) { return(true); } } } } break; case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_STRIP: case GLPrimitiveMode.GL_LINE_LOOP: { if (model.Pairs == null) { if (_HitTestLinesResult(model, new DataPair(0, points.Length), points, pointsTransformed, results, pointInWpf, sensity)) { return(true); } } else { foreach (var pair in model.Pairs) { if (_HitTestLinesResult(model, pair, points, pointsTransformed, results, pointInWpf, sensity)) { return(true); } } } } break; case GLPrimitiveMode.GL_TRIANGLES: case GLPrimitiveMode.GL_TRIANGLE_STRIP: { if (model.Pairs == null) { if (_HitTestTrianglesResult(model, new DataPair(0, points.Length), points, pointsTransformed, results, pointInWpf)) { return(true); } } else { foreach (var pair in model.Pairs) { if (_HitTestTrianglesResult(model, pair, points, pointsTransformed, results, pointInWpf)) { return(true); } } } } break; case GLPrimitiveMode.GL_TRIANGLE_FAN: { if (model.Pairs == null) { if (_HitTestTriangleFansResult(model, new DataPair(0, points.Length), points, pointsTransformed, results, pointInWpf)) { return(true); } } else { foreach (var pair in model.Pairs) { if (_HitTestTriangleFansResult(model, pair, points, pointsTransformed, results, pointInWpf)) { return(true); } } } } break; } return(false); } }
private static bool _HitTest(GLPanel3D viewport, RectF rectInWpf, IHitTestSource model, List <RectHitResult> results, bool isFullContain) { if (model is GLModel3DGroup) { var group = model as GLModel3DGroup; if (isFullContain) { foreach (var child in group.Children) { if (!_HitTest(viewport, rectInWpf, child, results, isFullContain)) { return(false); } } if (model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } else { foreach (var child in group.Children) { if (_HitTest(viewport, rectInWpf, child, results, isFullContain)) { return(true); } } return(false); } } else { //var meshModel = model as GLMeshModel3D; var bounds3D = model.Bounds; var bounds2D = Math3DHelper.Transform(bounds3D, viewport); var sensity = model.Mode == GLPrimitiveMode.GL_POINTS ? model.PointSize / 2 : model.LineWidth; switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_LOOP: case GLPrimitiveMode.GL_LINE_STRIP: if (!bounds2D.IsEmpty) { bounds2D.Extents(sensity); } break; } if ((isFullContain && bounds2D.IsEmpty) || rectInWpf.Contains(bounds2D)) { if (!isFullContain || model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } else { if (!rectInWpf.IntersectsWith(bounds2D)) { return(false); } var flag1 = false; var flag2 = true; var pointsTransformed = new LazyArray <Point3F, PointF>(model.GetHitTestPoints(), p => viewport.Point3DToPointInWpf(p)); switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: { if (model.Pairs == null) { _HitTestPointResult(new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestPointResult(pair, pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_LOOP: case GLPrimitiveMode.GL_LINE_STRIP: { if (model.Pairs == null) { _HitTestLinesResult(model, new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestLinesResult(model, pair, pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_TRIANGLES: case GLPrimitiveMode.GL_TRIANGLE_STRIP: { if (model.Pairs == null) { _HitTestTrianglesResult(model, new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestTrianglesResult(model, pair, pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_TRIANGLE_FAN: { if (model.Pairs == null) { _HitTestTriangleFansResult(new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestTriangleFansResult(pair, pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2)) { break; } } } } break; } if (flag1 && !isFullContain) { results.Add(new RectHitResult(model)); return(true); } else if (flag2 && isFullContain) { if (model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } return(false); } } }
public void Dispose() { _viewPort = null; }
public void Dispose() { _DetachEvents(); _panel = null; _relativeTo = null; }
internal MouseEventHandler(GLPanel3D panel) { _panel = panel; }