private void OnMouseAnyEvent(MouseEventArgs e)
        {
            APlotVM viewModel = ViewModel;

            if (viewModel == null)
            {
                return;
            }

            Viewport3D        viewPort      = this.GetViewport();
            Point             mousePosition = e.GetPosition(this);
            Ray3D             ray           = viewPort.GetRay(mousePosition);
            IList <HitResult> hitResult     = viewPort.FindHits(mousePosition);

            Model3D[] hits = new Model3D[hitResult.Count];
            for (int i = 0; i < hitResult.Count; i++)
            {
                hits[i] = hitResult[i].Model;
            }

            MouseInput mouseInput = new MouseInput(e.LeftButton, e.MiddleButton, e.RightButton,
                                                   ray.PlaneIntersection(new Point3D(), new Vector3D(0, 0, 1)),
                                                   hits);

            viewModel.UserInput(mouseInput);
        }
        public Point3D intersectAndTestAllWalls(Ray3D ray)
        {
            Point3D wallPoint;

            foreach (Plane3D wall in calcRoomModel.wallList)
            {
                if (ray.PlaneIntersection(wall.Position, wall.Normal, out wallPoint))
                {
                    wallPoint.X = Math.Round(wallPoint.X, 7);
                    wallPoint.Y = Math.Round(wallPoint.Y, 7);
                    wallPoint.Z = Math.Round(wallPoint.Z, 7);

                    // check if point is within room
                    if ((calcRoomModel.width >= wallPoint.X && wallPoint.X >= 0
                         &&
                         calcRoomModel.height >= wallPoint.Y && wallPoint.Y >= 0
                         &&
                         calcRoomModel.depth >= wallPoint.Z && wallPoint.Z >= 0) == true)
                    {
                        return(wallPoint);
                    }
                }
            }

            wallPoint = new Point3D(float.NaN, float.NaN, float.NaN);

            return(wallPoint);
        }
Exemple #3
0
        public void PlaneIntersection_RayInPlane()
        {
            var     ray = new Ray3D(new Point3D(0, 0, 0), new Vector3D(1, 0, 0));
            Point3D p;

            Assert.IsFalse(ray.PlaneIntersection(ray.Origin, ray.Direction.FindAnyPerpendicular(), out p));
        }
        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 panel      = ptPanel.Value;
                    var tt         = TotalTransformation.Value;
                    var planePoint = panel.Location + zDir * panel.SizeZ;

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

                        var pi = ray.PlaneIntersection(planePoint, zDir);

                        if (pi.HasValue && panel.Contains(pi.Value))
                        {
                            result         = true;
                            intersectValue = Vector3D.DotProduct(pi.Value - pp, linkDirection);
                            break;
                        }
                    }
                }
            }

            return(new Tuple <bool, double>(result, intersectValue));
        }
Exemple #5
0
 public void PlaneIntersection_PlaneInOriginOfRay()
 {
     var ray = new Ray3D(new Point3D(0, 0, 0), new Vector3D(1, 2, 3));
     Point3D p;
     Assert.IsTrue(ray.PlaneIntersection(ray.Origin, ray.Direction, out p));
     Assert.AreEqual(0, ray.Origin.DistanceTo(p), 1e-12);
 }
Exemple #6
0
        public void PlaneIntersection_PlaneInOriginOfRay()
        {
            var     ray = new Ray3D(new Point3D(0, 0, 0), new Vector3D(1, 2, 3));
            Point3D p;

            Assert.IsTrue(ray.PlaneIntersection(ray.Origin, ray.Direction, out p));
            Assert.AreEqual(0, ray.Origin.DistanceTo(p), 1e-12);
        }
Exemple #7
0
 public void PlaneIntersection_RayThroughPlaneOrigin()
 {
     var ray = new Ray3D(new Point3D(1, 2, 3), new Vector3D(-1, -2, -3));
     Point3D p;
     Assert.IsTrue(ray.PlaneIntersection(new Point3D(0, 0, 0), new Vector3D(1, 1, 1), out p));
     var pe = new Point3D(0, 0, 0);
     Assert.AreEqual(0, pe.DistanceTo(p), 1e-12);
 }
Exemple #8
0
        public void PlaneIntersection_RayThroughPlaneOrigin()
        {
            var     ray = new Ray3D(new Point3D(1, 2, 3), new Vector3D(-1, -2, -3));
            Point3D p;

            Assert.IsTrue(ray.PlaneIntersection(new Point3D(0, 0, 0), new Vector3D(1, 1, 1), out p));
            var pe = new Point3D(0, 0, 0);

            Assert.AreEqual(0, pe.DistanceTo(p), 1e-12);
        }
        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 = new Vector3D(0.0, 0.0, 1.0);
                        var zDir  = GetPanelFaceDirectionForLinkImpact(linkDirection);
                        var panel = ptPanel.Value;
                        var tt    = TotalTransformation.Value;
                        //var planePoint = panel.Location + zDir * panel.SizeZ;
                        var panelSize  = GetPanelSizeForLinkImpact(panel, linkDirection);
                        var planePoint = panel.Location + zDir * panelSize;
                        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, linkDirection);
                                var pi  = ray.PlaneIntersection(planePoint, zDir);

                                if (pi.HasValue && panel.Contains(pi.Value))
                                {
                                    var intersectValue = Vector3D.DotProduct(pi.Value - 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 #10
0
 public void PlaneIntersection_RayInPlane()
 {
     var ray = new Ray3D(new Point3D(0, 0, 0), new Vector3D(1, 0, 0));
     Point3D p;
     Assert.IsFalse(ray.PlaneIntersection(ray.Origin, ray.Direction.FindAnyPerpendicular(), out p));
 }