//--- //DEFAULT OBJECTS //--- //Default Rectangled Simple Surface (no shifts) public static Technique DefaultRectangledSimple(SizeF tileSize, HatchingMode hatching) { Technique t; t = new Technique(tileSize, new Point(1, 1), new Point(1, 1)); t.SetTileHatching(0, 0, hatching); t.SetPointShift(0, 0, new PointF(0, 0)); return(t); }
public void SetTileHatching(int x, int y, HatchingMode val) { if (!Misc.WithinBounds(x, y, this._TileHatching.GetLength(0), this._TileHatching.GetLength(1), -1, -1)) { throw new ExceptionSurface("Point (" + x + "," + y + ") is not within TileHatching bounds!"); } this._TileHatching[x, y] = val; if (this.Modified != null) { this.Modified(TechniqueModifications.TileHatching); } }
//Default Rectangled Alternated Surface (no shifts) / hatching00 represents the hatching of tile (0,0). the rest are alternated to this public static Technique DefaultRectangledAlternated(SizeF tileSize, HatchingMode hatchingOnTile00) { Technique t; t = new Technique(tileSize, new Point(2, 2), new Point(1, 1)); t.SetTileHatching(0, 0, hatchingOnTile00); t.SetTileHatching(0, 1, (HatchingMode)(1 - (int)hatchingOnTile00)); //1-x does bool negation t.SetTileHatching(1, 0, (HatchingMode)(1 - (int)hatchingOnTile00)); // --''-- t.SetTileHatching(1, 1, hatchingOnTile00); t.SetPointShift(0, 0, new PointF(0, 0)); return(t); }
//Returns the triangle in which a given point (ray) (x,y) is located. It returns the real coordinates of points that form the triangle in which the ray (x,y) goes trough the surface //Using Surface's technique for information public Vector3[] GetPositionTriangle(float x, float y, ShiftModes shiftApplied) { ShiftModes shiftm = shiftApplied; //detect shifting from technique if (shiftApplied == ShiftModes.AutoDetect) { shiftm = this.SurfaceTechnique.DetectShiftMode(); if (shiftm == ShiftModes.Both) { throw new ExceptionSurface("A horizontal and a vertical shift were both found in this surface's technique. Function GetPositionHeight cannot compute surfaces with a technique that uses shifts both horisontal and vertical! Please use only one kind of shift."); } } //get the tile where the position is located and check if the tile obtained is within surface limits. if not, throw exception Point tile = this.GetPositionTile(x, y, shiftApplied); if (!Misc.WithinBounds(tile, this.Size, -2, -2)) { throw new ExceptionSurface("The tile that contains the point (" + x + "," + y + ") is not within surface limits!"); //okay, uses offsets of -2 because: for once the tile number is one less than the points in a surface, which is returned in this.size. and another thing is that the function verifies in interval [0,size] but it must not include size in our case, because from 0 to size-1 is the boundary that includes all good points } HatchingMode tileHatch = this.GetTileHatching(tile.X, tile.Y); //determine the triangle from this tile that contains this point //same algorithm for any shift mode works Vector3 p1, p2; //points that determin the hatching line on this tile Vector3 A, B, C; //points of the triangle that contains this point if (tileHatch == HatchingMode.NWSE) { p1 = this.GetPointRealCoordinatesXYHeight(tile.X, tile.Y + 1, true); p2 = this.GetPointRealCoordinatesXYHeight(tile.X + 1, tile.Y, true); PointF pInter = Line2D.Intersection(Line2D.FromTwoPoints(p1.X, p1.Y, p2.X, p2.Y), new Line2D(x, y, 0, 1)); //determine the intersection point between a vertical line that goes through the point and the one that determines the hatching. The result can help determine which triangle exacly this point belongs to bool leftTriangle = true; // consider it is the left triangle first, for faster computing //lines were parallel and the point is on the right triangle if (float.IsInfinity(pInter.Y)) { if (x > p1.X) { leftTriangle = false; } } //lines not parallel, but the point is on the right triangle if (y > pInter.Y) { leftTriangle = false; } //set the triangle (obs: one point was not calculated) if (leftTriangle) { A = p1; B = p2; C = this.GetPointRealCoordinatesXYHeight(tile.X, tile.Y, true); } else //right triangle { A = p1; B = this.GetPointRealCoordinatesXYHeight(tile.X + 1, tile.Y + 1, true); C = p2; } } else //NESW { p1 = this.GetPointRealCoordinatesXYHeight(tile.X, tile.Y, true); p2 = this.GetPointRealCoordinatesXYHeight(tile.X + 1, tile.Y + 1, true); PointF pInter = Line2D.Intersection(Line2D.FromTwoPoints(p1.X, p1.Y, p2.X, p2.Y), new Line2D(x, y, 0, 1)); //determine the intersection point between a vertical line that goes through the point and the one that determines the hatching. The result can help determine which triangle exacly this point belongs to bool leftTriangle = true; // consider it is the left triangle first, for faster computing //lines were parallel and the point is on the right triangle if (float.IsInfinity(pInter.Y)) { if (x > p1.X) { leftTriangle = false; } } //lines not parallel, but the point is on the right triangle if (y < pInter.Y) { leftTriangle = false; } //set the triangle (obs: one point was not calculated) if (leftTriangle) { A = p1; B = this.GetPointRealCoordinatesXYHeight(tile.X, tile.Y + 1, true); C = p2; } else //right triangle { A = p1; B = p2; C = this.GetPointRealCoordinatesXYHeight(tile.X + 1, tile.Y, true); } } //returns the triangle in the form of an 3 elements array of Vector3 object. (The triangle is given clockwise, relative to the surface) Vector3[] triangle = new Vector3[3]; triangle[0] = A; triangle[1] = B; triangle[2] = C; return(triangle); }