コード例 #1
0
        public bool Intersect(IPanel panel)
        {
            var panelBox = new AxisAlignedBox3d(new Vector3d(), panel.SizeX / 2.0, panel.SizeY / 2.0, panel.SizeZ / 2.0);
            var toolBox  = this.GetBound();

            return(panelBox.Intersects(toolBox));
        }
コード例 #2
0
        public static void test_AxisAlignedBox3()
        {
            Random r = new Random(31337);

            for (int iter = 0; iter < 10000; ++iter)
            {
                Vector3d[] pts = TestUtil.RandomPoints3(100, r, Vector3d.Zero, 100);
                for (int j = 0; j < pts.Length; j += 2)
                {
                    AxisAlignedBox3d box1 = new AxisAlignedBox3d(pts[j], 10.0);
                    AxisAlignedBox3d box2 = new AxisAlignedBox3d(pts[j + 1], 20);

                    double dist_sqr = box1.DistanceSquared(ref box2);
                    if (box1.Intersects(box2))
                    {
                        Util.gDevAssert(dist_sqr == 0);
                    }
                    else
                    {
                        Util.gDevAssert(dist_sqr > 0);
                    }

                    dist_sqr -= MathUtil.ZeroTolerance;  // numericals
                    for (int k = 0; k < 8; ++k)
                    {
                        Vector3d p0 = box1.Corner(k);
                        Util.gDevAssert(dist_sqr < p0.DistanceSquared(box2.Center));
                        for (int i = 0; i < 8; ++i)
                        {
                            Util.gDevAssert(dist_sqr <= p0.DistanceSquared(box2.Corner(i)));
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void OnRoutToolMoveMessage(RoutToolMoveMessage msg)
        {
            if (_stepObserver.Direction == StepExecutionDirection.Back)
            {
                return;
            }

            var tool  = ImplicitToolFactory.Create(msg.Position, msg.Direction, msg.Length, msg.Radius);
            var panel = new AxisAlignedBox3d(new Vector3d(_cornerX, _cornerY, _cornerZ), new Vector3d(_cornerX + SizeX, _cornerY + SizeY, _cornerZ + SizeZ));

            //DispatcherHelper.CheckBeginInvokeOnUI(() =>
            //{
            //    var builder = new MeshBuilder();

            //    builder.AddSphere(msg.Position, 10);
            //    PanelModel.Children.Add(new GeometryModel3D() { Geometry = builder.ToMesh(), Material = MaterialHelper.CreateMaterial(Colors.Yellow) });
            //});

            Task.Run(() =>
            {
                var toolBound = tool.Bounds();

                if (panel.Intersects(toolBound))
                {
                    var routing = _lastRoutings.GetOrAdd(msg.ToolId, (id) => ImplicitRoutingFactory.Create(id, msg.Direction.ToVector3d(), msg.Length, msg.Radius));
                    var pt      = msg.Position.ToVector3d();
                    var box     = routing.Add(ref pt);

                    var intersect = panel.Intersect(box);
                    var xMinIndex = GetSectionIndex(intersect.Min.x, panel.Min.x, panel.Max.x, _nxSection);
                    var xMaxIndex = GetSectionIndex(intersect.Max.x, panel.Min.x, panel.Max.x, _nxSection);
                    var yMinIndex = GetSectionIndex(intersect.Min.y, panel.Min.y, panel.Max.y, _nySection);
                    var yMaxIndex = GetSectionIndex(intersect.Max.y, panel.Min.y, panel.Max.y, _nySection);

                    if (xMinIndex < 0)
                    {
                        xMinIndex = 0;
                    }
                    if (yMinIndex < 0)
                    {
                        yMinIndex = 0;
                    }

                    for (int i = xMinIndex; i <= xMaxIndex; i++)
                    {
                        for (int j = yMinIndex; j <= yMaxIndex; j++)
                        {
                            MessengerInstance.Send(new SectionRoutToolMoveMessage()
                            {
                                XSectionIndex = i, YSectionIndex = j, Rout = routing
                            });
                        }
                    }
                }
                else
                {
                    _lastRoutings.TryRemove(msg.ToolId, out ImplicitRouting ir);
                }
            });
        }
コード例 #4
0
        // Gets
        public List <TerrainIndexMapping> GetVertsInBrush(Vector3 position)
        {
            List <TerrainIndexMapping> tim = new List <TerrainIndexMapping>();

            Vector3d         v3d      = Convert.ToV3d(position);
            AxisAlignedBox3d pointBox = new AxisAlignedBox3d(v3d, brushRadius.GetValue());

            pointBox.Min += new Vector3d(0, -1000f, 0); pointBox.Max += new Vector3d(0, 1000f, 0); //adjust box to always find neighboring chunks.

            foreach (TerrainChunk t in terrainChunks)
            {
                if (pointBox.Intersects(t.dMeshAABB.Bounds))
                {
                    foreach (int v in t.dMesh.VertexIndices())
                    {
                        Vector3 vert = Convert.ToV3(t.dMesh.GetVertex(v));

                        if (Vector3.Distance(vert, position) <= brushRadius.GetValue())
                        {
                            tim.Add(new TerrainIndexMapping(v, t.arrayX, t.arrayY));
                        }
                    }
                }
            }
            return(tim);
        }
コード例 #5
0
        private void OnToolMoveMessage(ToolMoveMessage msg)
        {
            if (_stepObserver.Direction == StepExecutionDirection.Back)
            {
                return;
            }

            //var position = PanelModel.Transform.Inverse.Transform(msg.Position);
            //var tool = ImplicitToolFactory.Create(position.ToVector3d(), msg.Direction.ToVector3d(), msg.Length, msg.Radius);
            var tool  = ImplicitToolFactory.Create(msg.Position, msg.Direction, msg.Length, msg.Radius);
            var panel = new AxisAlignedBox3d(new Vector3d(_cornerX, _cornerY, _cornerZ), new Vector3d(_cornerX + SizeX, _cornerY + SizeY, _cornerZ + SizeZ));

            tool.Index = _stepObserver.Index;
            //{
            //    var builder = new MeshBuilder();

            //    builder.AddSphere(msg.Position, 10);
            //    PanelModel.Children.Add(new GeometryModel3D() { Geometry = builder.ToMesh(), Material = MaterialHelper.CreateMaterial(Colors.Yellow) });
            //}

            Task.Run(() =>
            {
                var toolBound = tool.Bounds();

                if (panel.Intersects(toolBound))
                {
                    var intersect = panel.Intersect(toolBound);
                    var xMinIndex = GetSectionIndex(intersect.Min.x, panel.Min.x, panel.Max.x, _nxSection);
                    var xMaxIndex = GetSectionIndex(intersect.Max.x, panel.Min.x, panel.Max.x, _nxSection);
                    var yMinIndex = GetSectionIndex(intersect.Min.y, panel.Min.y, panel.Max.y, _nySection);
                    var yMaxIndex = GetSectionIndex(intersect.Max.y, panel.Min.y, panel.Max.y, _nySection);

                    if (xMinIndex < 0)
                    {
                        xMinIndex = 0;
                    }
                    if (yMinIndex < 0)
                    {
                        yMinIndex = 0;
                    }

                    for (int i = xMinIndex; i <= xMaxIndex; i++)
                    {
                        for (int j = yMinIndex; j <= yMaxIndex; j++)
                        {
                            MessengerInstance.Send(new SectionToolMoveMessage()
                            {
                                XSectionIndex = i, YSectionIndex = j, Tool = tool
                            });
                        }
                    }
                }
            });
        }