public void GeneratePlane(PlanePosition p = null) { // Get value if passed, otherwise generate PlanePosition position = p != null ? p : GenerateRandomTrack(); // Get random values float speed = Random.Range(Globals.minHorSpeed, Globals.maxHorSpeed); float verticalSpeed = Random.Range(Globals.minVerSpeed, Globals.maxVerSpeed); float height = Random.Range(Globals.minHeight, Globals.maxHeight); // Generate plane var plane = Instantiate(_planePrefab, Vector3.zero, Quaternion.identity); // Get controller and assign values var controller = plane.GetComponent <PlaneController>(); controller.planePositions = position; controller.mSpeed = speed; controller.mDesiredHeight = height; controller.mVerticalSpeed = verticalSpeed; controller.uiController = _uiController; controller._sctaController = _sctaController; // Assign this as parent, so plane will be the child plane.transform.parent = this.transform; }
private LocalDate ConvertPositionToDate(PlanePosition plainPosition) { return(plainPosition switch { PlanePosition.Quarter1 => LocalDate.FromDateTime(DateTime.Today), PlanePosition.Quarter2 => LocalDate.FromDateTime(DateTime.Today.AddDays(-1)), PlanePosition.Quarter3 => LocalDate.FromDateTime(DateTime.Today.AddDays(-2)), PlanePosition.Quarter4 => LocalDate.FromDateTime(DateTime.Today.AddDays(1)), PlanePosition.OnAxis => throw new HoffException("Не удалось определить четверть круга: точка лежит на оси координат"), _ => throw new HoffException("Не удалось определить четверть круга :("), });
public static GameObject GetFromPlane(int row, int col, PlanePosition.PlaneType type) { Vector2 start = CoordsToVec2(row, col); Collider2D[] hits = Physics2D.OverlapBoxAll(start, Vector2.one * 0.1f, 0.0f); foreach (Collider2D hit in hits) { GameObject obj = hit.gameObject; PlanePosition p = obj.GetComponent <PlanePosition>(); if (p && p.Matches(row, col, type)) { return(obj); } } return(null); }
public const double Nb17 = 131072.0; //Number of bits for Encoding public static PlanePosition DecodeADSBToPosition(PlanePosition ReferencePosition, ADSBPositionMessage NewMessage) { double LatitudeReference = ReferencePosition.Latitude; double LongitudeReference = ReferencePosition.Longitude; int LatitudeCpr = NewMessage.CprLatitude; int LongitudeCpr = NewMessage.CprLongitude; int Cpr = NewMessage.CprFormate; double DLat = (Cpr == 0) ? Dlat0 : Dlat1; double j = Math.Floor(LatitudeReference / DLat) + Math.Floor(0.5 + mod(LatitudeReference, DLat) / DLat - LatitudeCpr / Nb17); double RLat = (double)DLat * (j + LatitudeCpr / Nb17); double Dlon = 360.0 / (NumberOfLongitudeZones.lookup(RLat) - Cpr); double m = Math.Floor(LongitudeReference / Dlon) + Math.Floor(0.5 + mod(LongitudeReference, Dlon) / Dlon - LongitudeCpr / Nb17); double RLon = (double)Dlon * (m + LongitudeCpr / Nb17); return(new PlanePosition(NewMessage.Timestamp, (double)RLat, (double)RLon, (double)NewMessage.Altitude)); }
public static IEnumerable <Facet> GetFacetsBelowPlane(this Model model, float z) { foreach (Facet facet in model.Facets) { PlanePosition position = facet.GetPlanePosition(z); if (position == PlanePosition.Below) { yield return(facet); } else if (position == PlanePosition.Intersect) { foreach (Facet item in facet.GetSections(z)) { yield return(item); } } } }
private void SpawnInPlane(GameObject obj, int row, int col, GameObject[,] plane) { // TODO: this is silly but I don't want to think about it right now PlanePosition.PlaneType t = PlanePosition.PlaneType.Ground; float yOffset = 0.0f; if (plane == actionPlane) { t = PlanePosition.PlaneType.Action; yOffset = 0.5f; } obj.transform.position = new Vector3(col, -row + yOffset, 0); plane[col, row] = obj; PlanePosition pos = obj.GetComponent <PlanePosition>(); if (pos) { pos.Set(row, col, t); } NetworkServer.Spawn(obj); }
/// <summary> /// На вход подаётся координата, в декартовой системе координат. /// В зависимости от попадания в соответствующий квадрант, с учётом вхождения(попадания) координаты в заданную окружность радиуса R, /// требуется получить курс иностранной валюты с сайта ЦБ РФ к рублю РФ на соответствующую дату /// </summary> public ICurrencyCourse GetCourse(IPoint point) { if (!_geometryService.CheckPointInCircle(point, _options.CircleRadius)) { throw new HoffException("Координата находится вне круга"); } PlanePosition plainPosition = _geometryService.GetPlanePosition(point); LocalDate courseDate = ConvertPositionToDate(plainPosition); ICurrencyCourse?course = _dataProvider.GetCourse(courseDate, _options.CurrencyCode); if (course == null) { throw new HoffException("Запрошенные данные не найдены"); } if (course.CourseDate < courseDate) //ЦБ присылает последние данные какие есть, даже если запрашивали на следующий день { throw new HoffException($"Данные на {courseDate:yyyyMMdd} еще не доступны!"); } return(course); }
public static Slice GetSlice(this Model model, float z, SlicerOptions options) { Slice slice = new Slice(); foreach (Facet facet in model.Facets) { PlanePosition position = facet.GetPlanePosition(z); if (position == PlanePosition.Intersect) { List <Vector3> points = facet.GetSection(z); if (points.Count == 2) { slice.AddSection(points[0], points[1], facet.Normal); } } } slice.Join(); slice.Simplify(options.Slice.SimplifyDistance); if (options.Slice.Flatten) { slice.Flatten(options.Slice.FlattenTolerance); } return(slice); }
/// <summary> /// Splits this triangle with given plane. /// </summary> /// <param name="splitter"> <see cref="Plane"/> that is used for splitting.</param> /// <param name="frontCoplanarElements"> /// An optional collection for this triangle if it's located on this plane and faces the /// same way. /// </param> /// <param name="backCoplanarElements"> /// An optional collection for this triangle if it's located on this plane and faces the /// opposite way. /// </param> /// <param name="frontElements"> /// An optional collection for parts of this triangle that are located in front of this plane. /// </param> /// <param name="backElements"> /// An optional collection for parts of this triangle that are located behind this plane. /// </param> /// <param name="customData"> Not used.</param> public void Split(Plane splitter, ICollection <SplittableTriangle> frontCoplanarElements, ICollection <SplittableTriangle> backCoplanarElements, ICollection <SplittableTriangle> frontElements, ICollection <SplittableTriangle> backElements, object customData = null) { PlanePosition triangleType = 0; PlanePosition[] positions = new PlanePosition[3]; // Determine position of the triangle relative to the plane. splitter.PointPosition(this.First.Position, out positions[0], ref triangleType); splitter.PointPosition(this.Second.Position, out positions[1], ref triangleType); splitter.PointPosition(this.Third.Position, out positions[2], ref triangleType); // Process this triangle's data based on its position. switch (triangleType) { case PlanePosition.Coplanar: // See where this triangle is looking and it to corresponding list. if (this.Normal * splitter.Normal > 0) { if (frontCoplanarElements != null) { frontCoplanarElements.Add(this); } } else { if (backCoplanarElements != null) { backCoplanarElements.Add(this); } } break; case PlanePosition.Front: if (frontElements != null) { frontElements.Add(this); } break; case PlanePosition.Back: if (backElements != null) { backElements.Add(this); } break; case PlanePosition.Spanning: if (frontElements == null && backElements == null) { return; // Any calculations won't be saved anywhere. } // // Prepare to create a split of this triangle. // // Cash vertices into an array, so we can loop through it. MeshVertex[] vertices = this.Vertices; // Create lists for vertices on the front and back. List <MeshVertex> fvs = new List <MeshVertex>(4); List <MeshVertex> bvs = new List <MeshVertex>(4); // // Process edges. // // We go through the polygon edge by edge with i being index of the start of the // edge, and j - end. for (int i = 0, j = 1; i < 3; i++, j = (j + 1) % 3) { // If edge doesn't begin behind the plane, add starting vertex to front vertices. if (positions[i] != PlanePosition.Back) { fvs.Add(vertices[i]); } // Else put the starting vertex to the back vertices. else { bvs.Add(vertices[i]); } // If this edge intersects the plane, split it. if ((positions[i] | positions[j]) == PlanePosition.Spanning) { // Calculate fraction that describes position of splitting vertex along // the line between start and end of the edge. float positionParameter = (splitter.D - splitter.Normal * vertices[i].Position) / (splitter.Normal * (vertices[j].Position - vertices[i].Position)); // Linearly interpolate the vertex that splits the edge. MeshVertex splittingVertex = (MeshVertex)vertices[i].CreateLinearInterpolation(vertices[j], positionParameter); // Add splitting vertex to both lists. fvs.Add(splittingVertex); bvs.Add(splittingVertex); } // Create front and back triangle(s) from vertices from corresponding lists. if (frontElements != null) { SplittableTriangle.TriangulateLinearly(fvs, false, frontElements); } if (backElements != null) { SplittableTriangle.TriangulateLinearly(bvs, false, backElements); } } break; default: throw new ArgumentOutOfRangeException(); } }
public void PointPosition(Vector3 point, out PlanePosition pointPlanePosition, ref PlanePosition polygonPlanePosition) { pointPlanePosition = this.PointPosition(point); polygonPlanePosition |= pointPlanePosition; }