Esempio n. 1
0
        public ColliderShape CreateShape()
        {
            if (InitialHeights == null ||
                !IsValidHeightStickSize(InitialHeights.HeightStickSize) ||
                InitialHeights.HeightRange.Y < InitialHeights.HeightRange.X ||
                Math.Abs(InitialHeights.HeightRange.Y - InitialHeights.HeightRange.X) < float.Epsilon ||
                Math.Abs(InitialHeights.HeightScale) < float.Epsilon)
            {
                return(null);
            }

            var arrayLength = InitialHeights.HeightStickSize.X * InitialHeights.HeightStickSize.Y;

            object unmanagedArray;

            switch (InitialHeights.HeightType)
            {
            case HeightfieldTypes.Float:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights.Floats);
                break;
            }

            case HeightfieldTypes.Short:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights.Shorts);
                break;
            }

            case HeightfieldTypes.Byte:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights.Bytes);
                break;
            }

            default:
                return(null);
            }

            var offsetToCenterHeightZero = CenterHeightZero ? InitialHeights.HeightRange.X + ((InitialHeights.HeightRange.Y - InitialHeights.HeightRange.X) * 0.5f) : 0f;

            var shape = new HeightfieldColliderShape
                        (
                InitialHeights.HeightStickSize.X,
                InitialHeights.HeightStickSize.Y,
                InitialHeights.HeightType,
                unmanagedArray,
                InitialHeights.HeightScale,
                InitialHeights.HeightRange.X,
                InitialHeights.HeightRange.Y,
                FlipQuadEdges
                        )
            {
                LocalOffset   = LocalOffset + new Vector3(0, offsetToCenterHeightZero, 0),
                LocalRotation = LocalRotation,
            };

            return(shape);
        }
Esempio n. 2
0
        public ColliderShape CreateShape()
        {
            object unmanagedArray;

            switch (HeightStickArraySource.HeightType)
            {
            case HeightfieldTypes.Float:
            {
                unmanagedArray = CreateHeights <float>(HeightStickArraySource);
                break;
            }

            case HeightfieldTypes.Short:
            {
                unmanagedArray = CreateHeights <short>(HeightStickArraySource);
                break;
            }

            case HeightfieldTypes.Byte:
            {
                unmanagedArray = CreateHeights <byte>(HeightStickArraySource);
                break;
            }

            default:
                return(null);
            }

            if (unmanagedArray == null)
            {
                return(null);
            }

            var shape = new HeightfieldColliderShape
                        (
                HeightStickArraySource.HeightStickSize.X,
                HeightStickArraySource.HeightStickSize.Y,
                HeightStickArraySource.HeightType,
                unmanagedArray,
                HeightStickArraySource.HeightScale,
                HeightStickArraySource.HeightRange.X,
                HeightStickArraySource.HeightRange.Y,
                FlipQuadEdges
                        )
            {
                LocalOffset   = LocalOffset + new Vector3(0, GetCenteringOffset(), 0),
                LocalRotation = LocalRotation,
            };

            return(shape);
        }
Esempio n. 3
0
 private HeightfieldDebugPrimitive(HeightfieldColliderShape heightfieldColliderShape)
 {
     heightfield = heightfieldColliderShape;
 }
        public ColliderShape CreateShape()
        {
            if (HeightStickSize.X <= 1 ||
                HeightStickSize.Y <= 1 ||
                HeightRange.Y < HeightRange.X ||
                Math.Abs(HeightRange.Y - HeightRange.X) < float.Epsilon)
            {
                return(null);
            }

            float heightScale = (HeightfieldType != HeightfieldTypes.Float) && HeightScale.Enabled ? HeightScale.Scale : CalculateHeightScale();

            if (Math.Abs(heightScale) < float.Epsilon)
            {
                return(null);
            }

            var arrayLength = HeightStickSize.X * HeightStickSize.Y;

            object unmanagedArray;

            switch (HeightfieldType)
            {
            case HeightfieldTypes.Float:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights?.Floats);
                break;
            }

            case HeightfieldTypes.Short:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights?.Shorts);
                break;
            }

            case HeightfieldTypes.Byte:
            {
                unmanagedArray = CreateHeights(arrayLength, InitialHeights?.Bytes);
                break;
            }

            default:
                return(null);
            }

            var shape = new HeightfieldColliderShape
                        (
                HeightStickSize.X,
                HeightStickSize.Y,
                HeightfieldType,
                unmanagedArray,
                heightScale,
                HeightRange.X,
                HeightRange.Y,
                FlipQuadEdges
                        )
            {
                LocalOffset   = LocalOffset,
                LocalRotation = LocalRotation,
            };

            return(shape);
        }