Exemple #1
0
        public override Task <Tuple <bool, double> > CheckPanelIntersectionAsync(bool targetLinkState, Vector3D linkDirection)
        {
            if (targetLinkState)
            {
                var ptPanel = ColliderExtensions.GetPanel();

                if (ptPanel.HasValue)
                {
                    if (Points.Count > 0)
                    {
                        var zDir       = GetPanelFaceDirectionForLinkImpact(linkDirection);
                        var retPanel   = ptPanel.Value;
                        var panelMin   = retPanel.Location.ToVector3();
                        var panelMax   = panelMin + new Vector3((float)retPanel.SizeX, (float)retPanel.SizeY, (float)retPanel.SizeZ);
                        var panel      = new Box3(panelMin, panelMax);
                        var tt         = TotalTransformation.Value;
                        var planePoint = panelMax;
                        var tasks      = new List <Task <Tuple <bool, double> > >();

                        foreach (var p in Points)
                        {
                            var point = p;

                            tasks.Add(Task.Run(() =>
                            {
                                var pp  = tt.Transform(point);
                                var ray = new Ray3D(pp.ToVector3(), linkDirection.ToVector3());

                                if (ray.PlaneIntersection(planePoint, zDir.ToVector3(), out Vector3 intersect) &&
                                    panel.Intersects(new Sphere3(intersect, 0.001f)))
                                {
                                    var pi             = intersect.ToPoint3D();
                                    var intersectValue = Vector3D.DotProduct(pi - pp, linkDirection);
                                    return(new Tuple <bool, double>(true, intersectValue));
                                }
                                else
                                {
                                    return(new Tuple <bool, double>(false, 0.0));
                                }
                            }));
                        }

                        return(Task.WhenAll(tasks).ContinueWith((t) => t.Result.FirstOrDefault(r => r.Item1) ?? new Tuple <bool, double>(false, 0.0)));
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("The number of points of collider must be greater than 0!");
                    }
                }
            }

            return(Task.FromResult(new Tuple <bool, double>(false, 0.0)));
        }
Exemple #2
0
        /// <summary>
        /// Finds the bounding box of the viewport.
        /// </summary>
        /// <param name="viewport">The viewport.</param>
        /// <returns>The bounding box.</returns>
        public static Rect3D FindBounds(this Viewport3DX viewport)
        {
            var bounds = new global::SharpDX.BoundingBox();

            foreach (var element in viewport.Items)
            {
                var model = element as IBoundable;
                if (model != null)
                {
                    if (model.Visibility != Visibility.Collapsed)
                    {
                        bounds = global::SharpDX.BoundingBox.Merge(bounds, model.Bounds);
                    }
                }
            }
            return(new Rect3D(bounds.Minimum.ToPoint3D(), (bounds.Maximum - bounds.Minimum).ToSize3D()));
        }
Exemple #3
0
        /// <summary>
        /// Finds the bounding box of the viewport.
        /// </summary>
        /// <param name="viewport">The viewport.</param>
        /// <returns>The bounding box.</returns>
        public static Rect3D FindBounds(this Viewport3DX viewport)
        {
            var bounds = new global::SharpDX.BoundingBox();

            foreach (var element in viewport.Renderables)
            {
                var model = element as GeometryModel3D;
                if (model != null)
                {
                    if (model.Visibility != Visibility.Collapsed && model.GeometryValid)
                    {
                        model.Geometry.UpdateBounds();
                        bounds = global::SharpDX.BoundingBox.Merge(bounds, model.Bounds);
                    }
                }
            }
            return(new Rect3D(bounds.Minimum.ToPoint3D(), (bounds.Maximum - bounds.Minimum).ToSize3D()));
        }
Exemple #4
0
        /// <summary>
        /// Returns a line geometry of the axis-aligned bounding-box of the given mesh.
        /// </summary>
        /// <param name="mesh">Input mesh for the computation of the b-box</param>
        /// <returns></returns>
        public static LineGeometry3D GenerateBoundingBox(global::SharpDX.BoundingBox bb)
        {
            var cc = bb.GetCorners();
            var ll = new LineBuilder();

            ll.AddLine(cc[0], cc[1]);
            ll.AddLine(cc[1], cc[2]);
            ll.AddLine(cc[2], cc[3]);
            ll.AddLine(cc[3], cc[0]);

            ll.AddLine(cc[4], cc[5]);
            ll.AddLine(cc[5], cc[6]);
            ll.AddLine(cc[6], cc[7]);
            ll.AddLine(cc[7], cc[4]);

            ll.AddLine(cc[0], cc[4]);
            ll.AddLine(cc[1], cc[5]);
            ll.AddLine(cc[2], cc[6]);
            ll.AddLine(cc[3], cc[7]);
            return(ll.ToLineGeometry3D());
        }
Exemple #5
0
        public override Tuple <bool, double> CheckPanelIntersection(bool targetLinkState, Vector3D linkDirection)
        {
            bool   result         = false;
            double intersectValue = 0.0;
            var    zDir           = new Vector3D(0.0, 0.0, 1.0);

            if (targetLinkState)
            {
                var ptPanel = ColliderExtensions.GetPanel();

                if (ptPanel.HasValue)
                {
                    var retPanel   = ptPanel.Value;
                    var panelMin   = retPanel.Location.ToVector3();
                    var panelMax   = panelMin + new Vector3((float)retPanel.SizeX, (float)retPanel.SizeY, (float)retPanel.SizeZ);
                    var panel      = new Box3(panelMin, panelMax);
                    var tt         = TotalTransformation.Value;
                    var planePoint = panelMax;

                    foreach (var p in Points)
                    {
                        var pp  = tt.Transform(p);
                        var ray = new Ray3D(pp.ToVector3(), linkDirection.ToVector3());

                        if (ray.PlaneIntersection(planePoint, zDir.ToVector3(), out Vector3 intersect) &&
                            panel.Intersects(new Sphere3(intersect, 0.001f)))
                        {
                            var pi = intersect.ToPoint3D();
                            result         = true;
                            intersectValue = Vector3D.DotProduct(pi - pp, linkDirection);
                            break;
                        }
                    }
                }
            }

            return(new Tuple <bool, double>(result, intersectValue));
        }
 /// <summary>
 /// Finds the bounding box of the viewport.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 /// <returns>The bounding box.</returns>
 public static Rect3D FindBounds(this Viewport3DX viewport)
 {
     var bounds = new global::SharpDX.BoundingBox();
     foreach (var element in viewport.Items)
     {
         var model = element as IBoundable;
         if (model != null)
         {
             if (model.Visibility != Visibility.Collapsed)
             {
                 bounds = global::SharpDX.BoundingBox.Merge(bounds, model.Bounds);
             }
         }
     }
     return new Rect3D(bounds.Minimum.ToPoint3D(), (bounds.Maximum - bounds.Minimum).ToSize3D());
 }