public void MoveFrez(List <Vector3> positions, int diameter, FileHelper.FrezType frez, double critDepth) { //List<Vector3> positions = PathData.GetPositions(begin, end, Unit); foreach (var v in positions) { MoveFrezStep(v, diameter, frez, critDepth); } }
public async void MoveFrezStep(Vector3 v, int diameter, FileHelper.FrezType frez, double critDepth) { int r = diameter / 2; r *= Resolution; //make origin point of a sphere-like frez at the bottom instead of middle if (frez == FileHelper.FrezType.K) { v.Y += r; } int index; float sphereZ = 0; for (float y = (v.Z - r); y <= (v.Z + r); y++) //do gory zaokraglić { for (float x = (v.X - r); x <= (v.X + r); x++) { index = (int)((int)(y) * (Length + 1) + x) + VertexOffset; //TOdO: warunek glebiej niz na r //if (index < (y) * (Length + 1) + x) + VertexOff) if (index >= 0 && x + offsetX > -1 && x + offsetX < (Length + 1) && y + offsetY > -1 && y + offsetY < (Width)) { Vertices[index].Normal = Vector3.Zero; if (frez == FileHelper.FrezType.K) { //sphereZ = ((float)-Math.Sqrt(Math.Abs((r * r) - (x - v.X) * (x - v.X) - (y - v.Z) * (y - v.Z))) + v.Y); sphereZ = ((float)-Math.Sqrt((r * r) - (x - v.X) * (x - v.X) - (y - v.Z) * (y - v.Z)) + v.Y); } else if (frez == FileHelper.FrezType.F) { sphereZ = v.Y; } bool freezable = ((x - v.X) * (x - v.X)) + ((y - v.Z) * (y - v.Z)) <= (r * r) && Vertices[index].Position.Y / Unit > sphereZ; if (sphereZ <= critDepth * Resolution) { CritError(this, null); var dialog = new MessageDialog("Milling under critical Level!"); await dialog.ShowAsync(); goto outer; //TODO SEROIUSLY DO STH WITH IT! } if (freezable) { Vertices[index].Position.Y = Unit * sphereZ; //TODO change later, upper bound } } } } outer :; //calculate normals for (float y = (v.Z - r - 1); y <= (v.Z + r + 1); y++) //do gory zaokraglić { for (float x = (v.X - r - 1); x <= (v.X + r + 1); x++) { index = (int)((int)(y) * (Length + 1) + x) + VertexOffset; if (index >= 0 && x + offsetX > -1 && x + offsetX < (Length + 1) && y + offsetY > -1 && y + offsetY < (Width)) { RecalculateNormalsForTriangle(index); } } } vertexBuffer.SetData <VertexPositionColorNormal>(Vertices); }