public void AddGrid(BoxFaces plane, int columns, int rows, float width, float height) { // checks if (columns < 2 || rows < 2) { throw new ArgumentNullException("columns or rows too small"); } if (width <= 0 || height <= 0) { throw new ArgumentNullException("width or height too small"); } // step var stepy = height / (rows - 1); var stepx = width / (columns - 1); float minx = 0, miny = 0; float maxx = width; float maxy = height; for (int y = 0; y < rows; y++) { this.AddLine(new Vector3(minx, stepy * y, 0), new Vector3(maxx, stepy * y, 0)); } for (int x = 0; x < columns; x++) { this.AddLine(new Vector3(stepx * x, miny, 0), new Vector3(stepx * x, maxy, 0)); } }
/// <summary> /// /// </summary> /// <param name="plane"></param> /// <param name="columns"></param> /// <param name="rows"></param> /// <param name="width"></param> /// <param name="height"></param> public void AddGrid(BoxFaces plane, int columns, int rows, float width, float height) { // checks if (columns < 2 || rows < 2) { throw new ArgumentNullException("columns or rows too small"); } if (width <= 0 || height <= 0) { throw new ArgumentNullException("width or height too small"); } // step var stepy = height / (rows - 1); var stepx = width / (columns - 1); float minx = 0, miny = 0; float maxx = width; float maxy = height; for (int y = 0; y < rows; y++) { this.AddLine(new Vector3(minx, stepy * y, 0), new Vector3(maxx, stepy * y, 0)); } for (int x = 0; x < columns; x++) { this.AddLine(new Vector3(stepx * x, miny, 0), new Vector3(stepx * x, maxy, 0)); } }
public Geometry3D BuildBox(Vector3 center, double xlength, double ylength, double zlength) { var geo = new Geometry3D(); BoxFaces faces = BoxFaces.All; if ((faces & BoxFaces.PositiveZ) == BoxFaces.PositiveZ) { this.AddCubeFace(geo, center, new Vector3(0, 0, 1), new Vector3(0, 1, 0), zlength, xlength, ylength); } if ((faces & BoxFaces.NegativeZ) == BoxFaces.NegativeZ) { this.AddCubeFace(geo, center, new Vector3(0, 0, -1), new Vector3(0, 1, 0), zlength, xlength, ylength); } if ((faces & BoxFaces.PositiveX) == BoxFaces.PositiveX) { this.AddCubeFace(geo, center, new Vector3(1, 0, 0), new Vector3(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.NegativeX) == BoxFaces.NegativeX) { this.AddCubeFace(geo, center, new Vector3(-1, 0, 0), new Vector3(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.NegativeY) == BoxFaces.NegativeY) { this.AddCubeFace(geo, center, new Vector3(0, -1, 0), new Vector3(0, 0, 1), ylength, xlength, zlength); } if ((faces & BoxFaces.PositiveY) == BoxFaces.PositiveY) { this.AddCubeFace(geo, center, new Vector3(0, 1, 0), new Vector3(0, 0, 1), ylength, xlength, zlength); } return(geo); }
public void AddCube(BoxFaces faces = BoxFaces.All) { if ((faces & BoxFaces.PositiveX) == BoxFaces.PositiveX) { AddFacePX(); } if ((faces & BoxFaces.NegativeX) == BoxFaces.NegativeX) { AddFaceNX(); } if ((faces & BoxFaces.NegativeY) == BoxFaces.NegativeY) { AddFaceNY(); } if ((faces & BoxFaces.PositiveY) == BoxFaces.PositiveY) { AddFacePY(); } if ((faces & BoxFaces.PositiveZ) == BoxFaces.PositiveZ) { AddFacePZ(); } if ((faces & BoxFaces.NegativeZ) == BoxFaces.NegativeZ) { AddFaceNZ(); } }
/// <summary> /// Adds a box aligned with the X, Y and Z axes. /// </summary> /// <param name="rectangle"> /// The 3-D "rectangle". /// </param> public void AddBox(Rect3D rectangle, BoxFaces faces = BoxFaces.All) { this.AddBox( new Vector3((float)rectangle.X + (float)(rectangle.SizeX * 0.5), (float)rectangle.Y + (float)(rectangle.SizeY * 0.5), (float)rectangle.Z + (float)(rectangle.SizeZ * 0.5)), rectangle.SizeX, rectangle.SizeY, rectangle.SizeZ, faces); }
/// <summary> /// Adds a box with the specifed faces, aligned with the X, Y and Z axes. /// </summary> /// <param name="center"> /// The center point of the box. /// </param> /// <param name="xlength"> /// The length of the box along the X axis. /// </param> /// <param name="ylength"> /// The length of the box along the Y axis. /// </param> /// <param name="zlength"> /// The length of the box along the Z axis. /// </param> /// <param name="faces"> /// The faces to include. /// </param> public void AddBox(Vector3 center, double xlength, double ylength, double zlength, BoxFaces faces = BoxFaces.All) { if ((faces & BoxFaces.PositiveX) == BoxFaces.PositiveX) { this.AddCubeFace(center, new Vector3(1, 0, 0), new Vector3(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.NegativeX) == BoxFaces.NegativeX) { this.AddCubeFace(center, new Vector3(-1, 0, 0), new Vector3(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.NegativeY) == BoxFaces.NegativeY) { this.AddCubeFace(center, new Vector3(0, -1, 0), new Vector3(0, 0, 1), ylength, xlength, zlength); } if ((faces & BoxFaces.PositiveY) == BoxFaces.PositiveY) { this.AddCubeFace(center, new Vector3(0, 1, 0), new Vector3(0, 0, 1), ylength, xlength, zlength); } if ((faces & BoxFaces.PositiveZ) == BoxFaces.PositiveZ) { this.AddCubeFace(center, new Vector3(0, 0, 1), new Vector3(0, 1, 0), zlength, xlength, ylength); } if ((faces & BoxFaces.NegativeZ) == BoxFaces.NegativeZ) { this.AddCubeFace(center, new Vector3(0, 0, -1), new Vector3(0, 1, 0), zlength, xlength, ylength); } }
/// <summary> /// Generates a rectangles mesh on the axis-aligned plane given by the box-face. /// </summary> /// <param name="plane">Box face which determines the plane the grid lies on.</param> /// <param name="columns">width of the grid, i.e. horizontal resolution </param> /// <param name="rows">height of the grid, i.e. vertical resolution</param> /// <param name="width">total size in horizontal </param> /// <param name="height">total vertical size</param> /// <param name="flipTriangles">flips the triangle faces</param> /// <param name="flipTexCoordsUAxis">flips the u-axis (horizontal) of the texture coords.</param> /// <param name="flipTexCoordsVAxis">flips the v-axis (vertical) of the tex.coords.</param> public void AddRectangularMesh(BoxFaces plane, int columns, int rows, float width, float height, bool flipTriangles = false, bool flipTexCoordsUAxis = false, bool flipTexCoordsVAxis = false) { // checks if (columns < 2 || rows < 2) { throw new ArgumentNullException("columns or rows too small"); } if (width <= 0 || height <= 0) { throw new ArgumentNullException("width or height too small"); } // index0 int index0 = this.positions.Count; // positions var stepy = height / (rows-1); var stepx = width / (columns-1); //rows++; //columns++; for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { this.positions.Add(new Vector3(x * stepx, y * stepy, 0)); } } // indices if (flipTriangles) { this.AddRectangularMeshTriangleIndicesFlipped(index0, rows, columns); } else { this.AddRectangularMeshTriangleIndices(index0, rows, columns); } // normals if (this.normals != null) { this.AddRectangularMeshNormals(index0, rows, columns); } // texcoords if (this.textureCoordinates != null) { this.AddRectangularMeshTextureCoordinates(rows, columns, flipTexCoordsVAxis, flipTexCoordsUAxis); } }
/// <summary> /// Adds a box with the specified faces, aligned with the specified axes. /// </summary> /// <param name="center">The center point of the box.</param> /// <param name="x">The x axis.</param> /// <param name="y">The y axis.</param> /// <param name="xlength">The length of the box along the X axis.</param> /// <param name="ylength">The length of the box along the Y axis.</param> /// <param name="zlength">The length of the box along the Z axis.</param> /// <param name="faces">The faces to include.</param> public void AddBox(Point3D center, Vector3D x, Vector3D y, double xlength, double ylength, double zlength, BoxFaces faces = BoxFaces.All) { var z = Vector3D.CrossProduct(x, y); if ((faces & BoxFaces.Front) == BoxFaces.Front) { this.AddCubeFace(center, x, z, xlength, ylength, zlength); } if ((faces & BoxFaces.Back) == BoxFaces.Back) { this.AddCubeFace(center, -x, z, xlength, ylength, zlength); } if ((faces & BoxFaces.Left) == BoxFaces.Left) { this.AddCubeFace(center, -y, z, ylength, xlength, zlength); } if ((faces & BoxFaces.Right) == BoxFaces.Right) { this.AddCubeFace(center, y, z, ylength, xlength, zlength); } if ((faces & BoxFaces.Top) == BoxFaces.Top) { this.AddCubeFace(center, z, y, zlength, xlength, ylength); } if ((faces & BoxFaces.Bottom) == BoxFaces.Bottom) { this.AddCubeFace(center, -z, y, zlength, xlength, ylength); } }
/// <summary> /// Adds a box with the specified faces, aligned with the X, Y and Z axes. /// </summary> /// <param name="center"> /// The center point of the box. /// </param> /// <param name="xlength"> /// The length of the box along the X axis. /// </param> /// <param name="ylength"> /// The length of the box along the Y axis. /// </param> /// <param name="zlength"> /// The length of the box along the Z axis. /// </param> /// <param name="faces"> /// The faces to include. /// </param> public void AddBox(Point3D center, double xlength, double ylength, double zlength, BoxFaces faces) { this.AddBox(center, new Vector3D(1, 0, 0), new Vector3D(0, 1, 0), xlength, ylength, zlength, faces); }
/// <summary> /// Add a box with specifed faces, align with the X, Y and Z axes. /// </summary> /// <param name="center">The center of the box.</param> /// <param name="xLength">The length of the box along the X axis.</param> /// <param name="yLength">The length of the box along the Y axis.</param> /// <param name="zLength">The length of the box along the Z axis.</param> /// <param name="faces">The faces to include.</param> public void AddBox(Point3D center, double xLength, double yLength, double zLength, BoxFaces faces) { if ((faces & BoxFaces.Front) == BoxFaces.Front) AddCubeFace(center, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), xLength, yLength, zLength); if ((faces & BoxFaces.Left) == BoxFaces.Left) AddCubeFace(center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), yLength, xLength, zLength); if ((faces & BoxFaces.Right) == BoxFaces.Right) AddCubeFace(center, new Vector3D(1, 0, 0), new Vector3D(0, 0, 1), yLength, xLength, zLength); if ((faces & BoxFaces.Back) == BoxFaces.Back) AddCubeFace(center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), xLength, yLength, zLength); if ((faces & BoxFaces.Top) == BoxFaces.Top) AddCubeFace(center, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), zLength, yLength, xLength); if ((faces & BoxFaces.Bottom) == BoxFaces.Bottom) AddCubeFace(center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), zLength, yLength, xLength); }
/// <summary> /// Adds a box with the specified faces, aligned with the X, Y and Z axes. /// </summary> /// <param name="center"> /// The center point of the box. /// </param> /// <param name="xlength"> /// The length of the box along the X axis. /// </param> /// <param name="ylength"> /// The length of the box along the Y axis. /// </param> /// <param name="zlength"> /// The length of the box along the Z axis. /// </param> /// <param name="faces"> /// The faces to include. /// </param> public void AddBox(Point3D center, double xlength, double ylength, double zlength, BoxFaces faces) { if ((faces & BoxFaces.Front) == BoxFaces.Front) { this.AddCubeFace(center, new Vector3D(1, 0, 0), new Vector3D(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.Back) == BoxFaces.Back) { this.AddCubeFace(center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), xlength, ylength, zlength); } if ((faces & BoxFaces.Left) == BoxFaces.Left) { this.AddCubeFace(center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), ylength, xlength, zlength); } if ((faces & BoxFaces.Right) == BoxFaces.Right) { this.AddCubeFace(center, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), ylength, xlength, zlength); } if ((faces & BoxFaces.Top) == BoxFaces.Top) { this.AddCubeFace(center, new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), zlength, xlength, ylength); } if ((faces & BoxFaces.Bottom) == BoxFaces.Bottom) { this.AddCubeFace(center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), zlength, xlength, ylength); } }