/// <summary> /// Setup constructor /// </summary> /// <param name="pos"> Ray intersection position </param> /// <param name="normal"> Ray intersection normal </param> /// <param name="distance"> Ray intersection distance </param> /// <param name="obj">Intersected object</param> public Line2Intersection( Point2 pos, Vector2 normal, float distance, object obj ) { m_Position = pos; m_Normal = normal; m_Distance = distance; m_Object = obj; }
public void Point2_IsConstructedProperly() { var result = new Point2(123, 456); TheResultingValue(result) .ShouldBe(123, 456); }
public Rectangle2(Point2 point, Size2 sizeF) { X = point.X; Y = point.Y; Width = sizeF.Width; Height = sizeF.Height; }
public static IViewPort New(VideoTypes videoType, IDisposableResource parent, Point2 location, Size2 size) { IViewPort api = null; #if WIN32 if (videoType == VideoTypes.D3D9) api = new D3D9.ViewPort(parent, location, size); #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) api = new D3D11.ViewPort(parent, location, size); #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) api = new OpenGL.ViewPort(parent, location, size); #endif #if XNA if (videoType == VideoTypes.XNA) api = new XNA.ViewPort(parent, location, size); #endif #if VITA if (videoType == VideoTypes.Vita) api = new Vita.ViewPort(parent, location, size); #endif if (api == null) Debug.ThrowError("ViewPortAPI", "Unsuported InputType: " + videoType); return api; }
static void Main(string[] args) { /********* VALUE TYPES *********/ int x = 5; ChangeValue(x); //only set to 10 in this method, one method completes program will go back to using x value in the main arguments scope. This application will print out x being equal to 5. Console.WriteLine("X: {0}", x); /********* REFERENCE TYPES *********/ Point1 p1 = new Point1(); //reference types are usually classes and arrays p1.X = 5; p1.Y = 10; Point1 p2 = p1; Point1 p3 = p2; p3.Y = 50; Console.WriteLine(p2.Y); Point2 p10 = new Point2(); p10.X = 10; p10.Y = 5; ChangePoint(p10); Console.WriteLine("X: {0}, Y:{1}", p10.X, p10.Y); Console.ReadLine(); }
public Rectangle( Point2 min, Point2 max ) { m_X = min.X; m_Y = min.Y; m_Width = max.X - min.X; m_Height = max.Y - min.Y; }
/// <summary> /// Create new Search Node. /// </summary> /// <param name="_position">Position of the Search Node in the grid.</param> /// <param name="_cost">Cost to move to this Node.</param> /// <param name="_pathCost">Estimated cost of the path.</param> /// <param name="_next">Next Search Node.</param> public SearchNode(Point2 _position, int _cost, int _pathCost, SearchNode _next) { this.position = _position; this.cost = _cost; this.pathCost = _pathCost; this.next = _next; }
public override void UpdatePreview() { ITilemapToolEnvironment env = this.Environment; Point2 topLeft = new Point2( Math.Min(env.ActionBeginTile.X, env.HoveredTile.X), Math.Min(env.ActionBeginTile.Y, env.HoveredTile.Y)); Point2 size = new Point2( 1 + Math.Abs(env.ActionBeginTile.X - env.HoveredTile.X), 1 + Math.Abs(env.ActionBeginTile.Y - env.HoveredTile.Y)); // Don't update the rect when still using the same boundary size bool hoverInsideActiveArea = (env.ActiveOrigin == topLeft && env.ActiveArea.Width == size.X && env.ActiveArea.Height == size.Y); if (hoverInsideActiveArea) return; env.ActiveOrigin = topLeft; env.ActiveArea.ResizeClear(size.X, size.Y); env.ActiveArea.Fill(true, 0, 0, size.X, size.Y); // Manually define outlines in the trivial rect case Tileset tileset = env.ActiveTilemap != null ? env.ActiveTilemap.Tileset.Res : null; Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize; env.ActiveAreaOutlines.Clear(); env.ActiveAreaOutlines.Add(new Vector2[] { new Vector2(0, 0), new Vector2(tileSize.X * size.X, 0), new Vector2(tileSize.X * size.X, tileSize.Y * size.Y), new Vector2(0, tileSize.Y * size.Y), new Vector2(0, 0) // Close the loop }); env.SubmitActiveAreaChanges(true); }
public int distanceSquaredFrom(Point2 to) { int deltaX = to.X - m_position.X; int deltaY = to.Y - m_position.Y; return deltaX * deltaX + deltaY * deltaY; }
public void epsg3140_to_wgs() { var crs = EpsgMicroDatabase.Default.GetCrs(3140); var wgs = EpsgMicroDatabase.Default.GetCrs(4326); // source for coordinates is http://epsg.io/3140/map var ptWgs = new GeographicCoordinate(-17.785, 177.97); var pt3140 = new Point2(530138.52663372, 821498.68898981); // units in links var gen = new EpsgCrsCoordinateOperationPathGenerator(); var paths = gen.Generate(wgs, crs); var compiler = new StaticCoordinateOperationCompiler(); var txs = paths .Select(p => compiler.Compile(p)) .Where(p => p != null); var forward = txs.Single(); var actualForward = (Point2)forward.TransformValue(ptWgs); Assert.AreEqual(pt3140.X, actualForward.X, 30); Assert.AreEqual(pt3140.Y, actualForward.Y, 30); var reverse = forward.GetInverse(); var actualReverse = (GeographicCoordinate)reverse.TransformValue(pt3140); Assert.AreEqual(ptWgs.Longitude, actualReverse.Longitude, 0.01); Assert.AreEqual(ptWgs.Latitude, actualReverse.Latitude, 0.01); }
protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e) { Brush triangleBrush = new SolidBrush(Color.Black); Point2 itemCenter = new Point2(e.Item.Width / 2, e.Item.Height / 2); int triangleSize = 2; if (e.Item.Pressed) { e.Graphics.FillRectangle( new SolidBrush(this.ColorTable.ButtonPressedHighlight), 1, 1, e.Item.Width - 2, e.Item.Height - 2); e.Graphics.DrawRectangle( new Pen(this.ColorTable.ButtonPressedHighlightBorder), 1, 1, e.Item.Width - 3, e.Item.Height - 3); } else if (e.Item.Selected) { e.Graphics.FillRectangle( new SolidBrush(this.ColorTable.ButtonSelectedHighlight), 1, 1, e.Item.Width - 2, e.Item.Height - 2); e.Graphics.DrawRectangle( new Pen(this.ColorTable.ButtonSelectedHighlightBorder), 1, 1, e.Item.Width - 3, e.Item.Height - 3); } e.Graphics.FillPolygon(triangleBrush, new Point[] { new Point(itemCenter.X - triangleSize, (e.Item.Height * 3 / 4) - triangleSize), new Point(itemCenter.X + triangleSize + 1, (e.Item.Height * 3 / 4) - triangleSize), new Point(itemCenter.X, (e.Item.Height * 3 / 4) + (triangleSize / 2))}); }
public override List<Point2> getValidMoves(Point2 origin, MapProperties mapProperties) { validPoints.Clear(); Point2 checkPoint; foreach (Point2 dir in legalMoves) { checkPoint = origin; for (int i = 0; i < attackRange; i++) { checkPoint += dir; if (checkPointOutOfBounds(checkPoint)) { break; } print(mapProperties); Tile tileAtPoint = mapProperties.getTile(checkPoint); if (checkTileContainsObstacle(tileAtPoint)) { break; } validPoints.Add(checkPoint); } } return validPoints; }
public TilemapTileDrawSource(Tilemap tilemap, Point2 origin, Grid<bool> area) { if (tilemap == null) throw new ArgumentNullException("tilemap"); this.tilemap = tilemap; this.origin = origin; this.area = new Grid<bool>(area); }
public override List<Point2> getValidMoves(Point2 origin, MapProperties mapProperties) { validPoints.Clear(); foreach (Point2 dir in legalMoves) { Point2 checkPoint = origin + dir; if (!checkPointOutOfBounds(checkPoint)) { Tile tileAtPoint = mapProperties.getTile(checkPoint); if (checkTileNeutral(tileAtPoint)) { validPoints.Add(checkPoint); } else { while (checkTileOwned(tileAtPoint) && !checkTileContainsEntity(tileAtPoint)) { validPoints.Add(checkPoint); checkPoint += dir; if (checkPointOutOfBounds(checkPoint)) { break; } tileAtPoint = mapProperties.getTile(checkPoint); } } } } return validPoints; }
public override List<Point2> getAffectedTiles(Point2 origin, Point2 affectedTile, MapProperties mapProperties) { List<Point2> affectedTiles = new List<Point2>(); affectedTiles.Add(origin); affectedTiles.Add(affectedTile); return affectedTiles; }
/// <summary> /// Determines the intersection between a 2d line and a plane /// </summary> /// <param name="start">Line start</param> /// <param name="end">Line end</param> /// <param name="plane">Plane</param> /// <returns>Returns intersection details, or null if there was no intersection.</returns> public static Line2Intersection GetLinePlaneIntersection( Point2 start, Point2 end, Plane2 plane ) { Vector2 vec = end - start; float len = vec.Length; vec /= len; float startDot = plane.Normal.Dot( start ); float diffDot = plane.Normal.Dot( vec ); if ( !Utils.CloseToZero( diffDot ) ) { float t = ( startDot + plane.Distance ) / -diffDot; if ( ( t >= 0 ) && ( t <= len ) ) { Line2Intersection result = new Line2Intersection( ); result.IntersectionPosition = start + ( vec * t ); result.IntersectionNormal = plane.Normal; result.Distance = t; result.StartInside = ( startDot + plane.Distance ) < 0; return result; } } return null; }
public KrovakModifiedNorth( GeographicCoordinate geographicOrigin, double latitudeOfPseudoStandardParallel, double azimuthOfInitialLine, double scaleFactor, Vector2 falseProjectedOffset, ISpheroid<double> spheroid, Point2 evaluationPoint, double[] constants ) : this(new KrovakModified( geographicOrigin, latitudeOfPseudoStandardParallel, azimuthOfInitialLine, scaleFactor, falseProjectedOffset, spheroid, evaluationPoint, constants )) { Contract.Requires(spheroid != null); Contract.Requires(constants != null); Contract.Requires(constants.Length == 10); }
public void Point2_EqualsObject() { var size1 = new Point2(123, 456); var size2 = new Point2(123, 456); TheResultingValue(size1.Equals((Object)size2)).ShouldBe(true); TheResultingValue(size1.Equals("This is a test")).ShouldBe(false); }
public void cast_vector() { var ptA = new Point2(2, 3); Vector2 vecA = ptA; Point2 ptB = vecA; ptB.Should().Be(ptA); }
/// <summary> /// Initializes a new instance of the <see cref="Bounds2"/> class so that it /// has a specified point in its center and has width and height equal to the speficied <c>size</c> parameter. /// </summary> /// <param name="centerPoint">The center point of the new boundary.</param> /// <param name="size">The width and the height of the boundary.</param> public Bounds2(Point2<double> centerPoint, double size) { double halfSize = size / 2; minX = centerPoint.X - halfSize; minY = centerPoint.Y - halfSize; maxX = centerPoint.X + halfSize; maxY = centerPoint.Y + halfSize; }
public void coordinate_pair_get_elements() { ICoordinatePair<double> p = new Point2(3, 4); var a = new Vector2(p); Assert.Equal(3, a.X); Assert.Equal(4, a.Y); }
public static void interface_point_extraction() { var p = new Point2(1, 2); var line = new Line2(p, new Vector2(3, 4)); var explicitP = ((ILine2<double>)line).P; explicitP.Should().Be(p); }
public static void construct_point_to_point() { var a = new Point2(1, 2); var b = new Point2(3, 5); var line = new Line2(a, b); line.P.Should().Be(a); line.Direction.Should().Be(new Vector2(2, 3)); }
public static void construct_point_and_vector() { var a = new Point2(1, 2); var d = new Vector2(3, 4); var line = new Line2(a, d); line.P.Should().Be(a); line.Direction.Should().Be(d); }
public CircleObject(CircleObject baseInstance) { //Copy from baseInstance Location = baseInstance.Location; Radius = baseInstance.Radius; StartTime = baseInstance.StartTime; Type = baseInstance.Type; Effect = baseInstance.Effect; }
public void distance_point() { var a = new Point2(1, 2); var b = new Point2(3, 5); var d1 = a.Distance(b); var d2 = b.Distance(a); d1.Should().Be(d2); d1.Should().Be(System.Math.Sqrt(13)); }
public bool Contains(int x, int y) { if (RadiusX <= 0 || RadiusY <= 0){ return false; } Point2 normalized = new Point2(x - center.X, y - center.Y); float nX = normalized.X; float nY = normalized.Y; return (double) (nX*nX)/(RadiusX*RadiusX) + (double) (nY*nY)/(RadiusY*RadiusY) <= 1.0; }
private static object CastFromDoublePoint(Point2 input, Type desiredCoordinateType) { var vectorType = GetGenericPointType(desiredCoordinateType); var cast = vectorType .GetMethods(BindingFlags.Static | BindingFlags.Public) .First(x => (x.Name == "op_Implicit" || x.Name == "op_Explicit") && x.ReturnParameter.ParameterType == vectorType && x.GetParameters().Count() == 1 && x.GetParameters()[0].ParameterType == typeof(Point2)); return cast.Invoke(null, new object[] { input }); }
public void distance_squared_point() { var a = new Point2(1, 2); var b = new Point2(3, 5); var d1 = a.DistanceSquared(b); var d2 = b.DistanceSquared(a); d1.Should().Be(d2); d1.Should().Be(13); }
TurnInfo saveTurn(Entity selectedEntity, int action, Point2 tileSelected, AIMapInfo mapInfo) { TurnInfo turnInfo = new TurnInfo(); List<Point2> affectedTiles = selectedEntity.getEntityActionManager().actions[action].getAffectedTiles(selectedEntity.getCurrentLocation(), tileSelected, mapInfo); foreach (Point2 p in affectedTiles) { turnInfo.addAffectedTile(mapInfo.getTile(p)); } return turnInfo; }
//public override void CopyTexture(Texture2DBase sourceTexture, SwapChainBase destinationSwapChain) //{ // var src = (RenderTexture2D)sourceTexture; // var dst = (SwapChain)destinationSwapChain; // CommandList.Orbital_Video_D3D12_CommandList_CopyTextureToSwapChain(handle, src.handle, dst.handle); //} public override void CopyTexture(Texture2DBase sourceTexture, Texture2DBase destinationTexture, Point2 sourceOffset, Point2 destinationOffset, Size2 size, int sourceMipmapLevel, int destinationMipmapLevel) { var src = (RenderTexture2D)sourceTexture; var dst = (RenderTexture2D)destinationTexture; CommandList.Orbital_Video_D3D12_CommandList_CopyTextureRegion(handle, src.handle, dst.handle, (uint)sourceOffset.x, (uint)sourceOffset.y, 0, (uint)destinationOffset.x, (uint)destinationOffset.y, 0, (uint)size.width, (uint)size.height, 1, (uint)sourceMipmapLevel, (uint)destinationMipmapLevel); }
public Point2 Calculate(Point2 location) { return(Point2.Create(location.X, location.Y - 1)); }
public void onReady() { SpawnItems.tool = this; SpawnItems.model = GameObject.Find(Application.loadedLevelName).transform.FindChild("items").gameObject; SpawnItems.regions = new ItemsRegion[NetworkRegions.REGION_X, NetworkRegions.REGION_Y]; for (int i = 0; i < NetworkRegions.REGION_X; i++) { for (int j = 0; j < NetworkRegions.REGION_Y; j++) { SpawnItems.regions[i, j] = new ItemsRegion(); } } if (Network.isServer) { int num = 0; for (int k = 0; k < SpawnItems.model.transform.FindChild("spawns").childCount; k++) { if (ServerSettings.mode == 0 && UnityEngine.Random.@value > Loot.NORMAL_ITEM_CHANCE || ServerSettings.mode == 1 && UnityEngine.Random.@value > Loot.BAMBI_ITEM_CHANCE || ServerSettings.mode == 2 && UnityEngine.Random.@value > Loot.HARDCORE_ITEM_CHANCE || ServerSettings.mode == 3 && UnityEngine.Random.@value > Loot.GOLD_ITEM_CHANCE) { Transform child = SpawnItems.model.transform.FindChild("spawns").GetChild(k); Point2 region = NetworkRegions.getRegion(child.position); int loot = Loot.getLoot(child.name); int type = ItemType.getType(loot); if (ItemWeight.getWeight(loot) != -1000 || type == 30) { if (type == 10) { SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, UnityEngine.Random.Range(1, ItemAmount.getAmount(loot) + 1), ItemState.getState(loot), child.position)); num++; } else if (type == 25) { for (int l = 0; l < UnityEngine.Random.Range(3, 6); l++) { SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, ItemAmount.getAmount(loot), ItemState.getState(loot), child.position + new Vector3(UnityEngine.Random.Range(-0.5f, 0.5f), 0f, UnityEngine.Random.Range(-0.5f, 0.5f)))); num++; } } else if (loot == 30000) { SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(11, 1, ItemState.getState(11), child.position)); SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(4017, 1, ItemState.getState(4017), child.position)); SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(5017, 1, ItemState.getState(5017), child.position)); num = num + 3; } else if (loot != 30001) { SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, ItemAmount.getAmount(loot), ItemState.getState(loot), child.position)); num++; } else { SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(12, 1, ItemState.getState(12), child.position)); SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(4018, 1, ItemState.getState(4018), child.position)); SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(5018, 1, ItemState.getState(5018), child.position)); num = num + 3; } } } } if (ServerSettings.map != 0) { base.InvokeRepeating("respawn", 5f, Loot.getRespawnRate() * (ServerSettings.mode != 3 ? 1f : 0.5f)); } } }
public Window(Point2 position, Size2 size, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition) { Init(position.x, position.y, size.width, size.height, sizeType, type, startupPosition); }
public void TestInitialize() { _p = new Point2(10, 20); _p2 = new Point2(-20, 60); }
public List <Point2> GetCellNeighbors(Point2 location) { return(_gameBoard.GetCellNeighbors(location)); }
public bool IsCellVisible(Point2 location) { return(_gameBoard.IsCellVisible(location)); }
public int GetTerrainTypeIdOfCell(Point2 location) { return(_gameBoard.GetCell(location).TerrainTypeId); }
public List <int> GetNeighboringTerrainTypeIds(Point2 cellLocation) { return(_gameBoard.GetNeighboringTerrainTypeIds(cellLocation)); }
internal Cell GetCell(Point2 location) { return(_gameBoard.GetCell(location)); }
/// <summary> /// /// </summary> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static WpfArc FromXArc(IArc arc, double dx, double dy) { var p1 = Point2.Create(arc.Point1.X + dx, arc.Point1.Y + dy); var p2 = Point2.Create(arc.Point2.X + dx, arc.Point2.Y + dy); var p3 = Point2.Create(arc.Point3.X + dx, arc.Point3.Y + dy); var p4 = Point2.Create(arc.Point4.X + dx, arc.Point4.Y + dy); var rect = Rect2.Create(p1, p2); var center = Point2.Create(rect.X + rect.Width / 2.0, rect.Y + rect.Height / 2.0); double offsetX = center.X - rect.X; double offsetY = center.Y - rect.Y; double minLenght = Max(offsetX, offsetY); double length1 = center.Distance(p3); double p3x = p3.X + (p3.X - center.X) / length1 * minLenght; double p3y = p3.Y + (p3.Y - center.Y) / length1 * minLenght; double length2 = center.Distance(p4); double p4x = p4.X + (p4.X - center.X) / length2 * minLenght; double p4y = p4.Y + (p4.Y - center.Y) / length2 * minLenght; p3.X = p3x; p3.Y = p3y; p4.X = p4x; p4.Y = p4y; var p3i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p3, true); var p4i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p4, true); Point2 start; Point2 end; if (p3i.Count == 1) { start = p3i.FirstOrDefault(); } else { start = Point2.Create(p3.X, p3.Y); } if (p4i.Count == 1) { end = p4i.FirstOrDefault(); } else { end = Point2.Create(p4.X, p4.Y); } double angle = MathHelpers.AngleLineSegments(center, start, center, end); bool isLargeArc = angle > 180.0; double helperLenght = 60.0; double lengthStart = center.Distance(start); double p3hx = start.X + (start.X - center.X) / lengthStart * helperLenght; double p3hy = start.Y + (start.Y - center.Y) / lengthStart * helperLenght; double lengthEnd = center.Distance(end); double p4hx = end.X + (end.X - center.X) / lengthEnd * helperLenght; double p4hy = end.Y + (end.Y - center.Y) / lengthEnd * helperLenght; p3.X = p3hx; p3.Y = p3hy; p4.X = p4hx; p4.Y = p4hy; return(new WpfArc() { P1 = p1, P2 = p2, P3 = p3, P4 = p4, Rect = rect, Center = center, Start = start, End = end, Radius = Size2.Create(offsetX, offsetY), IsLargeArc = isLargeArc, Angle = angle }); }
public virtual bool ContainsPoint(Point2 Point) { return(Math.Sqrt(Math.Pow((double)Point.X - (double)Location.X, 2) + Math.Pow((double)Point.Y - (double)Location.Y, 2)) <= Radius); }
public static extern Point2 <bool> AddPoint2B(Point2 <bool> lhs, Point2 <bool> rhs);
public override void SetPosition(Point2 position) { SetPosition(position.x, position.y); }
public static extern void GetPoint2BOut(bool e00, bool e01, out Point2 <bool> value);
/// <summary> /// Initializes an instance of <see cref="SpatialTransform"/>. /// </summary> public SpatialTransform() { _pan = new Point2(0, 0); Reset(); }
// Update is called once per frame void Update() { //if (AppMgr.pts == null) return; //if (AppMgr.lns == null) return; gameObject.SetActive(Active); ///Debug.Log(PointId); if (Point1 != null && Point2 != null && Point3 != null) { Vec1 = Point1.GetComponent <Point>().transform.position; Vec1.z = 0.0f; Vec2 = Point2.GetComponent <Point>().transform.position; Vec2.z = 0.0f; Vec3 = Point3.GetComponent <Point>().transform.position; Vec3.z = 0.0f; } else { GameObject[] OBJs = FindObjectsOfType <GameObject>(); GameObject LineObj = null; Line LN = null; for (int i = 0; i < OBJs.Length; i++) { LN = OBJs[i].GetComponent <Line>(); if (LN != null) { if (LN.Id == LineId) { LineObj = OBJs[i]; break; } } } if (LineObj == null) { Active = false; LineId = -1; } else { Point1 = Point2 = Point3 = null; for (int i = 0; i < OBJs.Length; i++) { Point PT = OBJs[i].GetComponent <Point>(); if (PT != null) { if (PT.Id == PointId) { Point2 = OBJs[i]; Vec2 = PT.transform.position; Vec2.z = 0.0f; } if (PT.Id == LN.Point1Id) { Point1 = OBJs[i]; Vec1 = PT.transform.position; Vec1.z = 0.0f; } if (PT.Id == LN.Point2Id) { Point3 = OBJs[i]; Vec3 = PT.transform.position; Vec3.z = 0.0f; } } } if (Point1 == null || Point2 == null || Point3 == null) { Active = false; } } } LR = GetComponent <LineRenderer>(); LR.SetPosition(0, Vec1); LR.SetPosition(1, Vec2); LR.SetPosition(2, Vec3); Renderer RD = GetComponent <LineRenderer>(); RD.material.color = StandardColor; }
public override Action <DrawingContext>[] PrepareToDrawing(Vector?vec, double PixelsPerDip, bool DrawOver = false) { Point P1, P2; if (vec.HasValue) { P1 = NP1; P2 = NP2; } else { P1 = Point1.ToPoint(Chart); P2 = Point2.ToPoint(Chart); } P1.GetCoeffsAB(P2, out double A, out double B); var linpen = new Pen(this.LineBrush, this.LineThikness + 1); linpen.Freeze(); var linps = new List <Point>(); if (LineIndent == 0) { linps.Add(new Point(0, B)); linps.Add(new Point(Chart.ChWidth, A * Chart.ChWidth + B)); } else { double z = 0, x = 0; double len = Math.Sqrt(Math.Pow(Chart.ChWidth, 2) + Math.Pow(B - A * Chart.ChWidth + B, 2)); double dx1 = LineDash / Math.Sqrt(A + 1); double dx2 = LineIndent / Math.Sqrt(A + 1); while (z < len) { linps.Add(new Point(x, A * x + B)); z += LineDash; x += dx1; linps.Add(new Point(x, A * x + B)); z += LineIndent; x += dx2; } } Action <DrawingContext> drawing; if (DrawOver) { drawing = dc => { for (int i = 0; i < linps.Count; i += 2) { dc.DrawLine(linpen, linps[i], linps[i + 1]); } dc.DrawEllipse(Brushes.Black, null, P1, 14, 14); dc.DrawEllipse(Brushes.White, null, P1, 12, 12); dc.DrawEllipse(Brushes.Black, null, P1, 10, 10); dc.DrawEllipse(Brushes.Black, null, P2, 14, 14); dc.DrawEllipse(Brushes.White, null, P2, 12, 12); dc.DrawEllipse(Brushes.Black, null, P2, 10, 10); }; } else { drawing = dc => { for (int i = 0; i < linps.Count; i += 2) { dc.DrawLine(linpen, linps[i], linps[i + 1]); } }; } return(new Action <DrawingContext>[] { drawing, null, null }); }
public IVoxel GetRelative(Point2 offset) { return(world.GetVoxel(world.GetPos(this) + offset)); }
/// <summary> /// Sets the color of all transparent pixels based on the non-transparent color values next to them. /// This does not affect any alpha values but prepares the Layer for correct filtering once uploaded /// to <see cref="Duality.Resources.Texture"/>. /// </summary> public void ColorTransparentPixels() { ColorRgba[] dataCopy = new ColorRgba[this.data.Length]; Array.Copy(this.data, dataCopy, this.data.Length); Parallel.ForEach(Partitioner.Create(0, this.data.Length), range => { Point2 pos = new Point2(); int[] nPos = new int[8]; bool[] nOk = new bool[8]; int[] mixClr = new int[4]; for (int i = range.Item1; i < range.Item2; i++) { if (dataCopy[i].A != 0) { continue; } pos.Y = i / this.width; pos.X = i - (pos.Y * this.width); mixClr[0] = 0; mixClr[1] = 0; mixClr[2] = 0; mixClr[3] = 0; nPos[0] = i - this.width; nPos[1] = i + this.width; nPos[2] = i - 1; nPos[3] = i + 1; nPos[4] = i - this.width - 1; nPos[5] = i + this.width - 1; nPos[6] = i - this.width + 1; nPos[7] = i + this.width + 1; nOk[0] = pos.Y > 0; nOk[1] = pos.Y < this.height - 1; nOk[2] = pos.X > 0; nOk[3] = pos.X < this.width - 1; nOk[4] = nOk[2] && nOk[0]; nOk[5] = nOk[2] && nOk[1]; nOk[6] = nOk[3] && nOk[0]; nOk[7] = nOk[3] && nOk[1]; int nMult = 2; for (int j = 0; j < 8; j++) { if (!nOk[j]) { continue; } if (dataCopy[nPos[j]].A == 0) { continue; } mixClr[0] += dataCopy[nPos[j]].R * nMult; mixClr[1] += dataCopy[nPos[j]].G * nMult; mixClr[2] += dataCopy[nPos[j]].B * nMult; mixClr[3] += nMult; if (j > 3) { nMult = 1; } } if (mixClr[3] > 0) { this.data[i].R = (byte)Math.Round((float)mixClr[0] / (float)mixClr[3]); this.data[i].G = (byte)Math.Round((float)mixClr[1] / (float)mixClr[3]); this.data[i].B = (byte)Math.Round((float)mixClr[2] / (float)mixClr[3]); } } }); }
public IVoxel GetVoxel(int x, int y) { var p = new Point2(x, y); return(GetVoxel(p)); }
public Waypoint() { this.pos = new Point2(10, -1); }
public override void Draw(IDrawDevice device) { // Determine basic working data Tilemap tilemap = this.ActiveTilemap; Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null; Point2 tileCount = tilemap != null ? tilemap.Size : new Point2(1, 1); Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize; // Early-out, if insufficient if (tilemap == null) { return; } if (tileset == null) { return; } // Determine the total size and origin of the rendered Tilemap Vector2 renderTotalSize = tileCount * tileSize; Vector2 renderOrigin = Vector2.Zero; this.origin.ApplyTo(ref renderOrigin, ref renderTotalSize); MathF.TransformCoord(ref renderOrigin.X, ref renderOrigin.Y, this.GameObj.Transform.Angle, this.GameObj.Transform.Scale); // Determine Tile visibility TilemapCulling.TileInput cullingIn = new TilemapCulling.TileInput { // Remember: All these transform values are in world space TilemapPos = this.GameObj.Transform.Pos + new Vector3(renderOrigin), TilemapScale = this.GameObj.Transform.Scale, TilemapAngle = this.GameObj.Transform.Angle, TileCount = tileCount, TileSize = tileSize }; TilemapCulling.TileOutput cullingOut = TilemapCulling.GetVisibleTileRect(device, cullingIn); int renderedTileCount = cullingOut.VisibleTileCount.X * cullingOut.VisibleTileCount.Y; // Determine rendering parameters Material material = (tileset != null ? tileset.RenderMaterial : null) ?? Material.Checkerboard.Res; ColorRgba mainColor = this.colorTint; // Determine and adjust data for Z offset generation float depthPerTile = -cullingIn.TileSize.Y * cullingIn.TilemapScale * this.tileDepthScale; if (this.tileDepthMode == TileDepthOffsetMode.Flat) { depthPerTile = 0.0f; } float originDepthOffset = Rect.Align(this.origin, 0, 0, 0, tileCount.Y * depthPerTile).Y; if (this.tileDepthMode == TileDepthOffsetMode.World) { originDepthOffset += (this.GameObj.Transform.Pos.Y / (float)tileSize.Y) * depthPerTile; } float renderBaseOffset = this.offset + this.tileDepthOffset * depthPerTile + originDepthOffset; // Prepare vertex generation data Vector2 tileXStep = cullingOut.XAxisWorld * cullingIn.TileSize.X; Vector2 tileYStep = cullingOut.YAxisWorld * cullingIn.TileSize.Y; Vector3 renderPos = cullingOut.RenderOriginWorld; float renderOffset = renderBaseOffset; Point2 tileGridPos = cullingOut.VisibleTileStart; // Reserve the required space for vertex data in our locally cached buffer const int MaxVerticesPerBatch = 65532; if (this.vertices == null) { this.vertices = new RawList <VertexC1P3T2>(); } this.vertices.Count = Math.Min(renderedTileCount * 4, MaxVerticesPerBatch); VertexC1P3T2[] vertexData = this.vertices.Data; // Prepare vertex data array for batch-submitting IReadOnlyGrid <Tile> tiles = tilemap.Tiles; TileInfo[] tileData = tileset.TileData.Data; int submittedTileCount = 0; int submittedBatchCount = 0; int vertexBaseIndex = 0; for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++) { Tile tile = tiles[tileGridPos.X, tileGridPos.Y]; if (tile.Index < tileData.Length) { Rect uvRect = tileData[tile.Index].TexCoord0; bool visualEmpty = tileData[tile.Index].IsVisuallyEmpty; int tileBaseOffset = tileData[tile.Index].DepthOffset; float localDepthOffset = (tile.DepthOffset + tileBaseOffset) * depthPerTile; if (!visualEmpty) { vertexData[vertexBaseIndex + 0].Pos.X = renderPos.X; vertexData[vertexBaseIndex + 0].Pos.Y = renderPos.Y; vertexData[vertexBaseIndex + 0].Pos.Z = renderPos.Z; vertexData[vertexBaseIndex + 0].DepthOffset = renderOffset + localDepthOffset; vertexData[vertexBaseIndex + 0].TexCoord.X = uvRect.X; vertexData[vertexBaseIndex + 0].TexCoord.Y = uvRect.Y; vertexData[vertexBaseIndex + 0].Color = mainColor; vertexData[vertexBaseIndex + 1].Pos.X = renderPos.X + tileYStep.X; vertexData[vertexBaseIndex + 1].Pos.Y = renderPos.Y + tileYStep.Y; vertexData[vertexBaseIndex + 1].Pos.Z = renderPos.Z; vertexData[vertexBaseIndex + 1].DepthOffset = renderOffset + localDepthOffset + depthPerTile; vertexData[vertexBaseIndex + 1].TexCoord.X = uvRect.X; vertexData[vertexBaseIndex + 1].TexCoord.Y = uvRect.Y + uvRect.H; vertexData[vertexBaseIndex + 1].Color = mainColor; vertexData[vertexBaseIndex + 2].Pos.X = renderPos.X + tileXStep.X + tileYStep.X; vertexData[vertexBaseIndex + 2].Pos.Y = renderPos.Y + tileXStep.Y + tileYStep.Y; vertexData[vertexBaseIndex + 2].Pos.Z = renderPos.Z; vertexData[vertexBaseIndex + 2].DepthOffset = renderOffset + localDepthOffset + depthPerTile; vertexData[vertexBaseIndex + 2].TexCoord.X = uvRect.X + uvRect.W; vertexData[vertexBaseIndex + 2].TexCoord.Y = uvRect.Y + uvRect.H; vertexData[vertexBaseIndex + 2].Color = mainColor; vertexData[vertexBaseIndex + 3].Pos.X = renderPos.X + tileXStep.X; vertexData[vertexBaseIndex + 3].Pos.Y = renderPos.Y + tileXStep.Y; vertexData[vertexBaseIndex + 3].Pos.Z = renderPos.Z; vertexData[vertexBaseIndex + 3].DepthOffset = renderOffset + localDepthOffset; vertexData[vertexBaseIndex + 3].TexCoord.X = uvRect.X + uvRect.W; vertexData[vertexBaseIndex + 3].TexCoord.Y = uvRect.Y; vertexData[vertexBaseIndex + 3].Color = mainColor; bool vertical = tileData[tile.Index].IsVertical; if (vertical) { vertexData[vertexBaseIndex + 0].DepthOffset += depthPerTile; vertexData[vertexBaseIndex + 3].DepthOffset += depthPerTile; } submittedTileCount++; vertexBaseIndex += 4; } } tileGridPos.X++; renderPos.X += tileXStep.X; renderPos.Y += tileXStep.Y; if ((tileGridPos.X - cullingOut.VisibleTileStart.X) >= cullingOut.VisibleTileCount.X) { tileGridPos.X = cullingOut.VisibleTileStart.X; tileGridPos.Y++; renderPos = cullingOut.RenderOriginWorld; renderPos.X += tileYStep.X * (tileGridPos.Y - cullingOut.VisibleTileStart.Y); renderPos.Y += tileYStep.Y * (tileGridPos.Y - cullingOut.VisibleTileStart.Y); renderOffset = renderBaseOffset + tileGridPos.Y * depthPerTile; } // If we reached the maximum number of vertices per batch, submit early and restart if (vertexBaseIndex >= MaxVerticesPerBatch) { device.AddVertices( material, VertexMode.Quads, vertexData, vertexBaseIndex); vertexBaseIndex = 0; submittedBatchCount++; } } // Submit the final batch will all remaining vertices if (vertexBaseIndex > 0) { device.AddVertices( material, VertexMode.Quads, vertexData, vertexBaseIndex); submittedBatchCount++; } Profile.AddToStat(@"Duality\Stats\Render\Tilemaps\NumTiles", renderedTileCount); Profile.AddToStat(@"Duality\Stats\Render\Tilemaps\NumVertices", submittedTileCount * 4); Profile.AddToStat(@"Duality\Stats\Render\Tilemaps\NumBatches", submittedBatchCount); }
void IGraphicsBackend.BeginRendering(IDrawDevice device, RenderOptions options, RenderStats stats) { DebugCheckOpenGLErrors(); this.CheckContextCaps(); this.currentDevice = device; this.renderOptions = options; this.renderStats = stats; // Prepare a shared index buffer object, in case we don't have one yet if (this.sharedBatchIBO == null) { this.sharedBatchIBO = new NativeGraphicsBuffer(GraphicsBufferType.Index); } // Prepare the target surface for rendering NativeRenderTarget.Bind(options.Target as NativeRenderTarget); // Determine whether masked blending should use alpha-to-coverage mode if (this.msaaIsDriverDisabled) { this.useAlphaToCoverageBlend = false; } else if (NativeRenderTarget.BoundRT != null) { this.useAlphaToCoverageBlend = NativeRenderTarget.BoundRT.Samples > 0; } else if (this.activeWindow != null) { this.useAlphaToCoverageBlend = this.activeWindow.IsMultisampled; } else { this.useAlphaToCoverageBlend = this.defaultGraphicsMode.Samples > 0; } // Determine the available size on the active rendering surface Point2 availableSize; if (NativeRenderTarget.BoundRT != null) { availableSize = new Point2(NativeRenderTarget.BoundRT.Width, NativeRenderTarget.BoundRT.Height); } else if (this.activeWindow != null) { availableSize = new Point2(this.activeWindow.Width, this.activeWindow.Height); } else { availableSize = this.externalBackbufferSize; } // Translate viewport coordinates to OpenGL screen coordinates (borrom-left, rising), unless rendering // to a texture, which is laid out Duality-like (top-left, descending) Rect openGLViewport = options.Viewport; if (NativeRenderTarget.BoundRT == null) { openGLViewport.Y = (availableSize.Y - openGLViewport.H) - openGLViewport.Y; } // Setup viewport and scissor rects GL.Viewport((int)openGLViewport.X, (int)openGLViewport.Y, (int)MathF.Ceiling(openGLViewport.W), (int)MathF.Ceiling(openGLViewport.H)); GL.Scissor((int)openGLViewport.X, (int)openGLViewport.Y, (int)MathF.Ceiling(openGLViewport.W), (int)MathF.Ceiling(openGLViewport.H)); // Clear buffers ClearBufferMask glClearMask = 0; ColorRgba clearColor = options.ClearColor; if ((options.ClearFlags & ClearFlag.Color) != ClearFlag.None) { glClearMask |= ClearBufferMask.ColorBufferBit; } if ((options.ClearFlags & ClearFlag.Depth) != ClearFlag.None) { glClearMask |= ClearBufferMask.DepthBufferBit; } GL.ClearColor(clearColor.R / 255.0f, clearColor.G / 255.0f, clearColor.B / 255.0f, clearColor.A / 255.0f); GL.ClearDepth((double)options.ClearDepth); // The "float version" is from OpenGL 4.1.. GL.Clear(glClearMask); // Configure Rendering params GL.Enable(EnableCap.ScissorTest); GL.Enable(EnableCap.DepthTest); if (options.DepthTest) { GL.DepthFunc(DepthFunction.Lequal); } else { GL.DepthFunc(DepthFunction.Always); } // Prepare shared matrix stack for rendering Matrix4 viewMatrix = options.ViewMatrix; Matrix4 projectionMatrix = options.ProjectionMatrix; if (NativeRenderTarget.BoundRT != null) { Matrix4 flipOutput = Matrix4.CreateScale(1.0f, -1.0f, 1.0f); projectionMatrix = projectionMatrix * flipOutput; } this.renderOptions.ShaderParameters.Set( BuiltinShaderFields.ViewMatrix, viewMatrix); this.renderOptions.ShaderParameters.Set( BuiltinShaderFields.ProjectionMatrix, projectionMatrix); this.renderOptions.ShaderParameters.Set( BuiltinShaderFields.ViewProjectionMatrix, viewMatrix * projectionMatrix); }
public bool ReadPixel(Point2 position, out Color4 color) { throw new NotImplementedException(); }
public static extern void GetPoint2FOut(float e00, float e01, out Point2 <float> value);
public override int GetHashCode() { return(71 * Point1.GetHashCode() + Point2.GetHashCode()); }
public static extern Point2 <float> AddPoint2F(Point2 <float> lhs, Point2 <float> rhs);
IEnumerator Start() { // 地形データのロード. var tmx = new TMXLoader(); tmx.Load("Levels/001"); var layer = tmx.GetLayer(0); //layer.Dump(); // タイルの配置. for (int j = 0; j < layer.Height; j++) { for (int i = 0; i < layer.Width; i++) { var v = layer.Get(i, j); var x = GetChipX(i); var y = GetChipY(j); Tile.Add(v, x, y); } } yield return(new WaitForSeconds(0.1f)); var pList = new List <Point2>(); Token player = null; // A-star実行. { // スタート地点. Point2 pStart = GetRandomPosition(layer); player = Util.CreateToken(GetChipX(pStart.x), GetChipY(pStart.y), "", "miku2", "Player"); player.SortingLayer = "Chara"; // ゴール. Point2 pGoal = GetRandomPosition(layer); var goal = Util.CreateToken(GetChipX(pGoal.x), GetChipY(pGoal.y), "", "gate1", "Goal"); goal.SortingLayer = "Chara"; // 斜め移動を許可 var allowdiag = true; var mgr = new ANodeMgr(layer, pGoal.x, pGoal.y, allowdiag); // スタート地点のノード取得 // スタート地点なのでコストは「0」 ANode node = mgr.OpenNode(pStart.x, pStart.y, 0, null); mgr.AddOpenList(node); // 試行回数。1000回超えたら強制中断 int cnt = 0; while (cnt < 1000) { mgr.RemoveOpenList(node); // 周囲を開く mgr.OpenAround(node); // 最小スコアのノードを探す. node = mgr.SearchMinScoreNodeFromOpenList(); if (node == null) { // 袋小路なのでおしまい. Debug.Log("Not found path."); break; } if (node.X == pGoal.x && node.Y == pGoal.y) { // ゴールにたどり着いた. Debug.Log("Success."); mgr.RemoveOpenList(node); node.DumpRecursive(); // パスを取得する node.GetPath(pList); // 反転する pList.Reverse(); break; } yield return(new WaitForSeconds(0.01f)); } } _state = eState.Walk; // プレイヤーを移動させる. foreach (var p in pList) { var x = GetChipX(p.x); var y = GetChipY(p.y); player.X = x; player.Y = y; yield return(new WaitForSeconds(0.2f)); } // おしまい _state = eState.End; }
public static extern Point2 <float> AddPoint2Fs(Point2 <float> *pValues, int count);