Exemplo n.º 1
0
        private Vector3 CalculateSegmentConnectionOffsetForNoCornerExclusion(ObjectPlacementBoxStackSegment sourceSegment, ObjectPlacementBoxStackSegment destinationSegment)
        {
            // No offset if the destination segment doesn't have any stacks
            if (destinationSegment.NumberOfStacks == 0)
            {
                return(Vector3.zero);
            }

            bool  srcPointsInSameDirAsDestination;
            bool  srcExtensionDirAlignedWithDestDir = sourceSegment.ExtensionDirection.IsAlignedWith(destinationSegment.ExtensionDirection, out srcPointsInSameDirAsDestination);
            float multiplicationSign = 1.0f;

            if (srcExtensionDirAlignedWithDestDir)
            {
                if (!srcPointsInSameDirAsDestination)
                {
                    multiplicationSign *= -1.0f;
                }
            }

            float   destBoxSizeAlongDestExtensionDir = destinationSegment.GetBoxSizeAlongNormalizedDirection(destinationSegment.ExtensionDirection);
            float   srcBoxSizeAlongDestExtensionDir  = sourceSegment.GetBoxSizeAlongNormalizedDirection(destinationSegment.ExtensionDirection);
            Vector3 offsetAlongDestExtensionDir      = destinationSegment.ExtensionDirection * (destBoxSizeAlongDestExtensionDir - srcBoxSizeAlongDestExtensionDir) * 0.5f;

            float   destBoxSizeAlongSrcExtensionDir = destinationSegment.GetBoxSizeAlongNormalizedDirection(sourceSegment.ExtensionDirection);
            float   srcBoxSizeAlongSrcExtensionDir  = sourceSegment.GetBoxSizeAlongNormalizedDirection(sourceSegment.ExtensionDirection);
            Vector3 offsetAlongSourceExtensionDir   = multiplicationSign * sourceSegment.ExtensionDirection * ((srcBoxSizeAlongSrcExtensionDir + destBoxSizeAlongSrcExtensionDir) * 0.5f + _paddingSettings.PaddingAlongExtensionPlane);

            return(offsetAlongDestExtensionDir + offsetAlongSourceExtensionDir);
        }
Exemplo n.º 2
0
        private Vector3 CalculateSegmentConnectionOffsetForCornerExclusion(ObjectPlacementBoxStackSegment sourceSegment, ObjectPlacementBoxStackSegment destinationSegment)
        {
            bool  srcPointsInSameDirAsDestination;
            bool  srcExtensionDirAlignedWithDestDir = sourceSegment.ExtensionDirection.IsAlignedWith(destinationSegment.ExtensionDirection, out srcPointsInSameDirAsDestination);
            float multiplicationSign = 1.0f;

            if (srcExtensionDirAlignedWithDestDir)
            {
                if (!srcPointsInSameDirAsDestination)
                {
                    multiplicationSign *= -1.0f;
                }
            }

            float   destBoxSizeAlongDestExtensionDir = destinationSegment.GetBoxSizeAlongNormalizedDirection(destinationSegment.ExtensionDirection);
            float   srcBoxSizeAlongDestExtensionDir  = sourceSegment.GetBoxSizeAlongNormalizedDirection(destinationSegment.ExtensionDirection);
            Vector3 offsetAlongDestExtensionDir      = destinationSegment.ExtensionDirection * Mathf.Abs((destBoxSizeAlongDestExtensionDir + srcBoxSizeAlongDestExtensionDir) * 0.5f);

            float   destBoxSizeAlongSrcExtensionDir = destinationSegment.GetBoxSizeAlongNormalizedDirection(sourceSegment.ExtensionDirection);
            float   srcBoxSizeAlongSrcExtensionDir  = sourceSegment.GetBoxSizeAlongNormalizedDirection(sourceSegment.ExtensionDirection);
            Vector3 offsetAlongSourceExtensionDir   = multiplicationSign * sourceSegment.ExtensionDirection * (srcBoxSizeAlongSrcExtensionDir + destBoxSizeAlongSrcExtensionDir) * 0.5f;

            return(offsetAlongDestExtensionDir + offsetAlongSourceExtensionDir);
        }
Exemplo n.º 3
0
        public bool ExtensionVectorOverlaps(ObjectPlacementBoxStackSegment querySegment)
        {
            if (NumberOfStacks == 0 || querySegment.NumberOfStacks == 0)
            {
                return(false);
            }

            if (_extensionDirection.IsAlignedWith(querySegment.ExtensionDirection))
            {
                Plane   segmentBasePlane = GetBasePlane();
                Vector3 thisSegmentStart = segmentBasePlane.ProjectPoint(FirstStackBasePosition);
                Vector3 thisSegmentEnd   = segmentBasePlane.ProjectPoint(LastStackBasePosition);
                if (NumberOfStacks == 1)
                {
                    thisSegmentEnd = thisSegmentStart + _extensionDirection * 0.5f * GetBoxSizeAlongNormalizedDirection(_extensionDirection);
                }

                Vector3 querySegmentStart = segmentBasePlane.ProjectPoint(querySegment.FirstStackBasePosition);
                Vector3 querySegmentEnd   = segmentBasePlane.ProjectPoint(querySegment.LastStackBasePosition);
                if (querySegment.NumberOfStacks == 1)
                {
                    querySegmentEnd = querySegmentStart + querySegment.ExtensionDirection * 0.5f * querySegment.GetBoxSizeAlongNormalizedDirection(querySegment.ExtensionDirection);
                }

                return(querySegmentStart.IsOnSegment(thisSegmentStart, thisSegmentEnd) || querySegmentEnd.IsOnSegment(thisSegmentStart, thisSegmentEnd) ||
                       thisSegmentStart.IsOnSegment(querySegmentStart, querySegmentEnd) || thisSegmentEnd.IsOnSegment(querySegmentStart, querySegmentEnd));
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool ExtensionVectorIntersects(ObjectPlacementBoxStackSegment querySegment)
        {
            if (NumberOfStacks == 0 || querySegment.NumberOfStacks == 0)
            {
                return(false);
            }

            if (_extensionDirection.IsPerpendicularTo(querySegment.ExtensionDirection))
            {
                Plane   segmentBasePlane = GetBasePlane();
                Vector3 thisSegmentStart = segmentBasePlane.ProjectPoint(FirstStackBasePosition);
                Vector3 thisSegmentEnd   = segmentBasePlane.ProjectPoint(LastStackBasePosition);
                if (NumberOfStacks == 1)
                {
                    thisSegmentEnd = thisSegmentStart + _extensionDirection * 0.5f * GetBoxSizeAlongNormalizedDirection(_extensionDirection);
                }

                Vector3 querySegmentStart = segmentBasePlane.ProjectPoint(querySegment.FirstStackBasePosition);
                Vector3 querySegmentEnd   = segmentBasePlane.ProjectPoint(querySegment.LastStackBasePosition);
                if (querySegment.NumberOfStacks == 1)
                {
                    querySegmentEnd = querySegmentStart + querySegment.ExtensionDirection * 0.5f * querySegment.GetBoxSizeAlongNormalizedDirection(querySegment.ExtensionDirection);
                }

                Segment3D thisSegment3D  = new Segment3D(thisSegmentStart, thisSegmentEnd);
                Segment3D querySegment3D = new Segment3D(querySegmentStart, querySegmentEnd);

                return(thisSegment3D.IntersectsWith(querySegment3D));
            }

            return(false);
        }