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)); }
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); }