public void initProjection(Projection projection, params double[] projParams) { double[,] projectionMatrix = null; double d = 1; switch (projection) { case Projection.FRONT: projectionMatrix = new double[, ] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 1 } }; break; case Projection.PROFILE: projectionMatrix = new double[, ] { { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }; break; case Projection.HORIZONTAL: projectionMatrix = new double[, ] { { 1, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }; break; case Projection.AXONOMETRIC: double psi = projParams[0] * Math.PI / 180; double fi = projParams[1] * Math.PI / 180; double sinPsi = Math.Sin(fi); double cosPsi = Math.Cos(psi); double sinFi = Math.Sin(fi); double cosFi = Math.Cos(fi); projectionMatrix = new double[, ] { { cosPsi, sinFi *sinPsi, 0, 0 }, { 0, cosFi, 0, 0 }, { sinPsi, -sinFi * cosPsi, 0, 0 }, { 0, 0, 0, 1 } }; break; case Projection.OBLIQUE: double l = projParams[0]; double alpha = projParams[1] * Math.PI / 180; double sinAlpha = Math.Sin(alpha); double cosAlpha = Math.Cos(alpha); projectionMatrix = new double[, ] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { l *cosAlpha, l *sinAlpha, 0, 0 }, { 0, 0, 0, 1 } }; break; case Projection.PERSPECTIVE: d = projParams[0]; if (d == 0) { d = 0.1; } projectionMatrix = new double[, ] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 1 / d }, { 0, 0, 0, 0 } }; break; default: break; } foreach (var itemFace in mFaces) { foreach (var itemEdge in itemFace.getEdges()) { List <Point3D> pointsBefore = itemEdge.getPoints(); List <Point3D> pointsAfter = new List <Point3D>(pointsBefore.Count); foreach (var itemPoint in pointsBefore) { double[] before = new double[] { itemPoint.X, itemPoint.Y, itemPoint.Z, 1 }; double[] after = GeometryUtils.matrixMultiplication(before, projectionMatrix); Point3D pointAfter; double p4 = after[3]; if (p4 == 0) { p4 = 0.1; } if (projection.Equals(Projection.PERSPECTIVE)) { pointAfter = new Point3D(after[0] / p4, after[1] / p4, after[2] / p4); } else { pointAfter = new Point3D(after[0], after[1], after[2]); } pointsAfter.Add(pointAfter); } itemEdge.setPoints(pointsAfter); } } }
public void initView(Projection projection, params double[] projParams) { double[,] viewMatrix = null; switch (projection) { case Projection.FRONT: break; case Projection.PROFILE: break; case Projection.HORIZONTAL: break; case Projection.AXONOMETRIC: break; case Projection.OBLIQUE: break; case Projection.PERSPECTIVE: double theta = projParams[1] * Math.PI / 180; double fi2 = projParams[2] * Math.PI / 180; double ro = projParams[3]; double sinTheta = Math.Sin(theta); double cosTheta = Math.Cos(theta); double sinFi2 = Math.Sin(fi2); double cosFi2 = Math.Cos(fi2); //viewMatrix = new double[,] { // { -sinTheta, -cosFi2*cosTheta, -sinFi2*cosTheta, 0 }, // { cosTheta, -cosFi2*sinTheta, -sinFi2*sinTheta, 0 }, // { 0, sinFi2, -cosTheta, 0 }, // { 0, 0, ro, 1 } }; viewMatrix = new double[, ] { { -sinTheta, -cosFi2 * cosTheta, -sinFi2 * cosTheta, 0 }, { cosTheta, -cosFi2 * sinTheta, -sinFi2 * sinTheta, 0 }, { 0, sinFi2, -cosFi2, 0 }, { 0, 0, ro, 1 } }; break; default: break; } if (viewMatrix == null) { return; } foreach (var itemFace in mFaces) { foreach (var itemEdge in itemFace.getEdges()) { List <Point3D> pointsBefore = itemEdge.getPoints(); List <Point3D> pointsAfter = new List <Point3D>(pointsBefore.Count); foreach (var itemPoint in pointsBefore) { double[] before = new double[] { itemPoint.X, itemPoint.Y, itemPoint.Z, 1 }; double[] after = GeometryUtils.matrixMultiplication(before, viewMatrix); pointsAfter.Add(new Point3D(after[0], after[1], after[2])); } itemEdge.setPoints(pointsAfter); } } }