Beispiel #1
0
        public BoundingBoxD Transform(ref MatrixD m)
        {
            var bb = BoundingBoxD.CreateInvalid();

            Transform(ref m, ref bb);
            return(bb);
        }
Beispiel #2
0
        public BoundingBoxD GetAABB()
        {
            BoundingBoxD     box     = BoundingBoxD.CreateInvalid();
            BoundingFrustumD frustum = ConvertToFrustum();

            box.Include(ref frustum);
            return(box);
        }
        public void OverlapAllLineSegment <T>(ref LineD line, List <MyLineSegmentOverlapResult <T> > elementsList, uint requiredFlags)
        {
            elementsList.Clear();

            if (_root == NullNode)
            {
                return;
            }

            using (m_rwLock.AcquireSharedUsing())
            {
                Stack <int> stack = GetStack();
                stack.Push(_root);

                BoundingBoxD bbox = BoundingBoxD.CreateInvalid();
                bbox.Include(ref line);

                var ray = new RayD(line.From, line.Direction);

                while (stack.Count > 0)
                {
                    int nodeId = stack.Pop();
                    if (nodeId == NullNode)
                    {
                        continue;
                    }

                    DynamicTreeNode node = _nodes[nodeId];

                    if (node.Aabb.Intersects(bbox))
                    {
                        double?distance = node.Aabb.Intersects(ray);
                        if (distance.HasValue && distance.Value <= line.Length && distance.Value >= 0)
                        {
                            if (node.IsLeaf())
                            {
                                uint flags = GetUserFlag(nodeId);
                                if ((flags & requiredFlags) == requiredFlags)
                                {
                                    elementsList.Add(new MyLineSegmentOverlapResult <T>
                                    {
                                        Element  = GetUserData <T>(nodeId),
                                        Distance = distance.Value
                                    });
                                }
                            }
                            else
                            {
                                stack.Push(node.Child1);
                                stack.Push(node.Child2);
                            }
                        }
                    }
                }

                PushStack(stack);
            }
        }
Beispiel #4
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix    = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
        public BoundingBoxD GetAABB()
        {
            if (m_cornersTmp == null)
            {
                m_cornersTmp = new Vector3D[8];
            }
            this.GetCorners(m_cornersTmp, 0);
            BoundingBoxD xd = BoundingBoxD.CreateInvalid();

            for (int i = 0; i < 8; i++)
            {
                xd.Include(m_cornersTmp[i]);
            }
            return(xd);
        }
Beispiel #6
0
        public unsafe BoundingBoxD Transform(ref MatrixD worldMatrix)
        {
            BoundingBoxD oobb = BoundingBoxD.CreateInvalid();

            Vector3 *temporaryCorners = stackalloc Vector3[8];

            GetCornersUnsafe((Vector3 *)temporaryCorners);

            for (int i = 0; i < 8; i++)
            {
                Vector3D vctTransformed = Vector3.Transform(temporaryCorners[i], worldMatrix);
                oobb = oobb.Include(ref vctTransformed);
            }

            return(oobb);
        }