コード例 #1
0
        public AABB GetAndTryUpdateFramingBoundingBox()
        {
            List <BoundBase> boundingBoxes = GetBoundingBoxes();

            // Update framing bounding box only if transformation of component has changed
            if (bBoundingBoxesTransformDirty)
            {
                var   max = boundingBoxes[0].GetMax();
                var   min = boundingBoxes[0].GetMin();
                float minX = min.X, minY = min.Y, minZ = min.Z, maxX = max.X, maxY = max.Y, maxZ = max.Z;
                for (Int32 i = 1; i < boundingBoxes.Count; i++)
                {
                    var localMax = boundingBoxes[i].GetMax();
                    var localMin = boundingBoxes[i].GetMin();
                    maxX = Math.Max(maxX, localMax.X);
                    maxY = Math.Max(maxY, localMax.Y);
                    maxZ = Math.Max(maxZ, localMax.Z);
                    minX = Math.Min(minX, localMin.X);
                    minY = Math.Min(minY, localMin.Y);
                    minZ = Math.Min(minZ, localMin.Z);
                }

                framingBoundBox = AABB.CreateFromMinMax(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ), RootComponent);
            }

            return(framingBoundBox);
        }
コード例 #2
0
        private BoundBase UpdateBound()
        {
            BoundBase resultBound = null;

            if (bComponentHierarchyChangedDirty || bTransformationDirty)
            {
                AABB aabb = AABB.CreateFromMinMax(FindEdgeInMesh((lhv, rhv) => { return(Math.Min(lhv, rhv)); }),
                                                  FindEdgeInMesh((lhv, rhv) => { return(Math.Max(lhv, rhv)); }), this);
                Matrix4    TransformMatrix = GetWorldMatrix();
                Quaternion rotation        = TransformMatrix.ExtractRotation();
                if (rotation.Xyz.LengthSquared > 0.01f)
                {
                    resultBound = new OBB(aabb.GetLocalSpaceOrigin(), aabb.GetLocalSpaceExtent(), TransformMatrix, this);
                }
                else
                {
                    aabb.ScalePlusTranslation = TransformMatrix;
                    resultBound = aabb;
                }
                bComponentHierarchyChangedDirty = false;
            }
            else
            {
                resultBound = Bound;
            }
            return(resultBound);
        }
コード例 #3
0
        private BoundBase CreateBound()
        {
            BoundBase  resultBound     = null;
            AABB       aabb            = AABB.CreateFromMinMax(FindMinFromModel(), FindMaxFromModel(), this);
            Matrix4    TransformMatrix = GetWorldMatrix();
            Quaternion rotation        = TransformMatrix.ExtractRotation();

            if (rotation.Xyz.LengthSquared > 0.01f)
            {
                resultBound = new OBB(aabb.GetLocalSpaceOrigin(), aabb.GetLocalSpaceExtent(), TransformMatrix, this);
            }
            else
            {
                aabb.ScalePlusTranslation = TransformMatrix;
                resultBound = aabb;
            }
            return(resultBound);
        }
コード例 #4
0
        private static BoundBase UpdateCollisionBound(ref SceneComponent component, float[,] vertices)
        {
            BoundBase resultBound = null;

            AABB aabb = AABB.CreateFromMinMax(
                FindEdgeInMesh((lhv, rhv) => { return(Math.Min(lhv, rhv)); }, vertices),
                FindEdgeInMesh((lhv, rhv) => { return(Math.Max(lhv, rhv)); }, vertices),
                component);
            Matrix4    TransformMatrix = component.GetWorldMatrix();
            Quaternion rotation        = TransformMatrix.ExtractRotation();

            if (rotation.Xyz.LengthSquared > 0.01f)
            {
                resultBound = new OBB(aabb.GetLocalSpaceOrigin(), aabb.GetLocalSpaceExtent(), TransformMatrix, component);
            }
            else
            {
                aabb.ScalePlusTranslation = TransformMatrix;
                resultBound = aabb;
            }

            return(resultBound);
        }
コード例 #5
0
        public AABB GetAABBFromAllChildComponents()
        {
            List <BoundBase> childBoundBoxes = new List <BoundBase>();

            GetHierarchyBoundingBoxes(this, ref childBoundBoxes);

            var   max = childBoundBoxes[0].GetMax();
            var   min = childBoundBoxes[0].GetMin();
            float minX = min.X, minY = min.Y, minZ = min.Z, maxX = max.X, maxY = max.Y, maxZ = max.Z;

            for (Int32 i = 1; i < childBoundBoxes.Count; i++)
            {
                var localMax = childBoundBoxes[i].GetMax();
                var localMin = childBoundBoxes[i].GetMin();
                maxX = Math.Max(maxX, localMax.X);
                maxY = Math.Max(maxY, localMax.Y);
                maxZ = Math.Max(maxZ, localMax.Z);
                minX = Math.Min(minX, localMin.X);
                minY = Math.Min(minY, localMin.Y);
                minZ = Math.Min(minZ, localMin.Z);
            }
            return(AABB.CreateFromMinMax(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ), this));
        }