Пример #1
0
        public float MaxDeformation(Vector3I cube, MyCubeGrid cubeGrid)
        {
            float maxDeformationSq = 0.0f;
            float maxBoneErrorSq   = GetMaxBoneError(cubeGrid.GridSize);

            maxBoneErrorSq *= maxBoneErrorSq;

            foreach (var boneOffset in BoneOffsets)
            {
                Vector3  offset;
                Vector3I bonePos   = cube * BoneDensity + boneOffset;
                bool     boneExits = Bones.TryGetValue(bonePos, out offset);

                float definitionLength =
                    GetDefinitionOffsetWithNeighbours(cube, cube * BoneDensity + boneOffset, cubeGrid).LengthSquared();
                float offsetLength = offset.LengthSquared();

                float deformationSq = Math.Abs(definitionLength - offsetLength);

                if (deformationSq > maxDeformationSq)
                {
                    maxDeformationSq = deformationSq;
                }

                if (!boneExits && deformationSq > maxBoneErrorSq)
                {
                    Bones.Add(bonePos, offset);
                    cubeGrid.AddDirtyBone(cube, boneOffset);
                }
            }
            return((float)Math.Sqrt(maxDeformationSq));
        }
Пример #2
0
        public float MaxDeformation(Vector3I cube, MyCubeGrid cubeGrid)
        {
            float maxDeformationSq = 0.0f;
            float maxBoneErrorSq = GetMaxBoneError(cubeGrid.GridSize);
            maxBoneErrorSq *= maxBoneErrorSq;

            foreach (var boneOffset in BoneOffsets)
            {
                Vector3 offset;
                Vector3I bonePos = cube*BoneDensity + boneOffset;
                bool boneExits = Bones.TryGetValue(bonePos, out offset);

                float definitionLength =
                    GetDefinitionOffsetWithNeighbours(cube, cube*BoneDensity + boneOffset, cubeGrid).LengthSquared();
                float offsetLength = offset.LengthSquared();

                float deformationSq = Math.Abs(definitionLength - offsetLength);

                if (deformationSq > maxDeformationSq)
                {
                    maxDeformationSq = deformationSq;
                }

                if (!boneExits && deformationSq > maxBoneErrorSq)
                {
                    Bones.Add(bonePos, offset);
                    cubeGrid.AddDirtyBone(cube, boneOffset);
                }
            }
            return (float)Math.Sqrt(maxDeformationSq);
        }