/// <summary> /// Transform a two dimensionnal array of polygon arrays of model coordinates into a two dimensionnal array of polygon arrays of screen coordinates. /// </summary> /// <param name="polygons">Two dimensionnal array of polygon arrays of model coordinates</param> /// <returns>Two dimensionnal array of polygon array of screen coordinates</returns> public PolygonArray[,] ModelToScreen(PolygonArray[,] polygons) { PolygonArray[,] screenCoords = new PolygonArray[polygons.GetLength(0), polygons.GetLength(1)]; int len = polygons.Length; Matrix4d modelMatrix = getModelViewAsMatrix4d(); Matrix4d projectionMatrix = getProjectionAsMatrix4d(); double[] viewport = getViewPortAsDouble(); Vector4d screenCoord = default(Vector4d); for (int i = 0; i <= polygons.GetLength(0) - 1; i++) { for (int j = 0; j <= polygons.GetLength(1) - 1; j++) { double[] x = new double[len]; double[] y = new double[len]; double[] z = new double[len]; PolygonArray polygon = polygons[i, j]; for (int k = 0; k <= polygon.Length - 1; k++) { if (!Glut.Glut.Project(new Vector4d(polygon.X[k], polygon.Y[k], polygon.Z[k], 0), modelMatrix, projectionMatrix, viewport, ref screenCoord)) { FailedProjection("Could not retrieve model coordinates in screen for point #" + k + " of polygon (" + i + "," + j + ")."); } x[k] = screenCoord.X; y[k] = screenCoord.Y; z[k] = screenCoord.Z; } screenCoords[i, j] = new PolygonArray(x, y, z); } } return(screenCoords); }
/// <summary> /// Transform a polygon array of model coordinates into a polygon array of screen coordinates. /// </summary> /// <param name="polygon">Polygon array of model coordinates</param> /// <returns>Polygon array of screen coordinates</returns> public PolygonArray ModelToScreen(PolygonArray polygon) { List <Coord3d> screenCoords = new List <Coord3d>(); int len = polygon.Length; double[] x = new double[len]; double[] y = new double[len]; double[] z = new double[len]; Matrix4d modelMatrix = getModelViewAsMatrix4d(); Matrix4d projectionMatrix = getProjectionAsMatrix4d(); double[] viewport = getViewPortAsDouble(); Vector4d screenCoord = default(Vector4d); for (int i = 0; i <= len - 1; i++) { if (!Glut.Glut.Project(new Vector4d(polygon.X[i], polygon.Y[i], polygon.Z[i], 0), modelMatrix, projectionMatrix, viewport, ref screenCoord)) { FailedProjection("Could not retrieve model coordinates in screen for point #" + i + "."); } x[i] = screenCoord.X; y[i] = screenCoord.Y; z[i] = screenCoord.Z; } return(new PolygonArray(x, y, z)); }