public void Update(double time, bool AI = false) { if (!AI) { _currentFramesInput = GetUserInput(); } if (_currentFramesInput.HasFlag(Input.Slow)) { time *= SLOW_MULTIPLIER; } // _position.Azimuth += time*0.5*Direction; if (_currentFramesInput.HasFlag(Input.Left)) { _position.Azimuth -= _velocity.Azimuth * time; } else if (_currentFramesInput.HasFlag(Input.Right)) { _position.Azimuth += _velocity.Azimuth * time; } _position = _position.Normalised(); _vertexBuffer.Bind(); _vertexBuffer.Initialise(); _vertexBuffer.SetData(BuildVertexList(), _dataSpecification); _vertexBuffer.UnBind(); }
public void PolarToCartesianCoordinateTestMethod() { PolarVector polarVectorDegree = new PolarVector(5, 30); Vector2f vector = polarVectorDegree.PolarToCartesianCoordinateDegrees(); Assert.IsTrue(Math.Abs(vector.X - 4.33) < 0.05 & Math.Abs(vector.Y - 2.5) < 0.05); }
public void GetEndCaps(int beatIndex, int sideIndex, int leftOrRight) { var deltaWidth = Math.Max(_impactDistances[beatIndex] - _positions[beatIndex].Radius, 0); var pLeft = new PolarVector(_positions[beatIndex].Azimuth + sideIndex * _angleBetweenSides[beatIndex], Math.Max(_positions[beatIndex].Radius - _outlineWidth, _impactDistances[beatIndex])); var pRight = new PolarVector(_positions[beatIndex].Azimuth + sideIndex * _angleBetweenSides[beatIndex] + _angleBetweenSides[beatIndex], Math.Max(_positions[beatIndex].Radius - _outlineWidth, _impactDistances[beatIndex])); double dR = _outlineWidth * Math.Tan(MathHelper.DegreesToRadians(30)); double dThetaInner = _outlineWidth / (pLeft.Radius + dR); double dThetaOuter = _outlineWidth / (pLeft.Radius + _widths[beatIndex] + dR); //left if (leftOrRight == 0 || leftOrRight == 2) { _outlineBoundsTemp[0] = PolarVector.ToCartesianCoordinates(pLeft); _outlineBoundsTemp[1] = PolarVector.ToCartesianCoordinates(pLeft, -dThetaInner, dR); _outlineBoundsTemp[2] = PolarVector.ToCartesianCoordinates(pLeft, -dThetaOuter, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth + dR); _outlineBoundsTemp[3] = PolarVector.ToCartesianCoordinates(pLeft, -dThetaOuter, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth + dR); _outlineBoundsTemp[4] = PolarVector.ToCartesianCoordinates(pLeft, 0, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth); _outlineBoundsTemp[5] = PolarVector.ToCartesianCoordinates(pLeft); } //right if (leftOrRight == 1 || leftOrRight == 2) { _outlineBoundsTemp[6] = PolarVector.ToCartesianCoordinates(pRight); _outlineBoundsTemp[7] = PolarVector.ToCartesianCoordinates(pRight, dThetaInner, dR); _outlineBoundsTemp[8] = PolarVector.ToCartesianCoordinates(pRight, dThetaOuter, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth + dR); _outlineBoundsTemp[9] = PolarVector.ToCartesianCoordinates(pRight, dThetaOuter, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth + dR); _outlineBoundsTemp[10] = PolarVector.ToCartesianCoordinates(pRight, 0, _widths[beatIndex] - deltaWidth + 2 * _outlineWidth); _outlineBoundsTemp[11] = PolarVector.ToCartesianCoordinates(pRight); } }
public void CartesianToPolarCoordinateTestMethod() { Vector2f cartesian = new Vector2f(5, 3); PolarVector polarVectorDegree = cartesian.CartesianToPolarCoordinateDegrees(); Assert.IsTrue(Math.Abs(polarVectorDegree.r - 5.83) < 0.05 & Math.Abs(polarVectorDegree.theta - 30.963) < 0.05); }
public Vector2 getWorldPosition() { // add scene rot // convert to vector2d PolarVector offseted = new PolarVector(position.Angle - GameScene.rotation, position.Radius); return(offseted.toVector2()); }
public Player() { _length = MathHelper.DegreesToRadians(PLAYER_LENGTH_DEGREES); _width = PLAYER_WIDTH; _position = new PolarVector(1.5 * (Math.PI / 3) - _length * 0.5f, PLAYER_RADIUS); _velocity = new PolarVector(-9, 0); Direction = 1; UseGamePad = false; }
public List <float> BuildVertexList() { var verts = new List <Vector2>(); verts.Add(PolarVector.ToCartesianCoordinates(_position)); verts.Add(PolarVector.ToCartesianCoordinates(_position, _length / 2, _width)); verts.Add(PolarVector.ToCartesianCoordinates(_position, _length, 0)); return(verts.SelectMany(v => new[] { v.X, v.Y }).ToList()); }
public List <IntPoint> GetBounds() { var p = new List <IntPoint>(); var p1 = PolarVector.ToCartesianCoordinates(_position); var p2 = PolarVector.ToCartesianCoordinates(_position, _length / 2, _width); var p3 = PolarVector.ToCartesianCoordinates(_position, _length, 0); p.Add(new IntPoint(p1.X, p1.Y)); p.Add(new IntPoint(p2.X, p2.Y)); p.Add(new IntPoint(p3.X, p3.Y)); return(p); }
public Vector2[] GetSideBounds(int beatIndex, int sideIndex) { var sp = new PolarVector(_positions[beatIndex].Azimuth + sideIndex * _angleBetweenSides[beatIndex], Math.Max(_positions[beatIndex].Radius, _impactDistances[beatIndex])); var deltaWidth = Math.Max(_impactDistances[beatIndex] - _positions[beatIndex].Radius, 0); sideBoundsTemp[0] = PolarVector.ToCartesianCoordinates(sp); sideBoundsTemp[1] = PolarVector.ToCartesianCoordinates(sp, _angleBetweenSides[beatIndex], 0); sideBoundsTemp[2] = PolarVector.ToCartesianCoordinates(sp, _angleBetweenSides[beatIndex], _widths[beatIndex] - deltaWidth); sideBoundsTemp[3] = PolarVector.ToCartesianCoordinates(sp, _angleBetweenSides[beatIndex], _widths[beatIndex] - deltaWidth); sideBoundsTemp[4] = PolarVector.ToCartesianCoordinates(sp, 0, _widths[beatIndex] - deltaWidth); sideBoundsTemp[5] = PolarVector.ToCartesianCoordinates(sp); return(sideBoundsTemp); }
public void AddOnsetDrawing(List <bool> sides, PolarVector velocity, double width, double minimumRadius, double impactTime) { _velocities[DrawingIndex] = velocity; var initialRadius = (impactTime * velocity.Radius + minimumRadius); _impactDistances[DrawingIndex] = minimumRadius; _positions[DrawingIndex] = new PolarVector(0, initialRadius); _widths[DrawingIndex] = width; _sides[DrawingIndex] = sides; _numberOfSides[DrawingIndex] = sides.Count; _angleBetweenSides[DrawingIndex] = GetAngleBetweenSides(_numberOfSides[DrawingIndex]); DrawingIndex += 1; }
private List <IntPoint> GetSideBounds(int index) { var p = new List <IntPoint>(); var sp = new PolarVector(Position.Azimuth + index * AngleBetweenSides, Position.Radius); var p1 = PolarVector.ToCartesianCoordinates(sp); var p2 = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, 0); var p3 = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, _width + PulseWidth); var p4 = PolarVector.ToCartesianCoordinates(sp, 0, _width + PulseWidth); p.Add(new IntPoint(p1.X, p1.Y)); p.Add(new IntPoint(p2.X, p2.Y)); p.Add(new IntPoint(p3.X, p3.Y)); p.Add(new IntPoint(p4.X, p4.Y)); return(p); }
public override void Update(double time, bool focused = false) { // Update total elapsed time _totalTime += time; if (InputSystem.NewKeys.Contains(Key.Escape)) { Exit(); } _player.Update(time); _centerPolygon.Update(time, false); DoGUI(); // Update next if needed if (_selectedItemChanged) { // Reset elapsed time _totalTime = 0; _menuFontDrawing.DrawingPrimitives.Clear(); _menuFDP = new QFontDrawingPrimitive(_menuFont.Font, _menuRenderOptions); _menuFDP.Print(_selectedMenuItemText.ToUpper(), Vector3.Zero, QFontAlignment.Centre); _menuFontDrawing.DrawingPrimitives.Add(_menuFDP); _selectedItemChanged = false; } // Pulse text var size = _menuFont.Font.Measure(_selectedMenuItemText.ToUpper()); var selectedSide = GetSelectedSide(); var newPos = new PolarVector(selectedSide * _centerPolygon.AngleBetweenSides + _centerPolygon.AngleBetweenSides * 0.5f, _player.Position.Radius + _player.Width + size.Height * 0.9); var extraRotation = (selectedSide >= 0 && selectedSide < 3) ? (-Math.PI / 2.0) : (Math.PI / 2.0); var extraOffset = (selectedSide >= 0 && selectedSide < 3) ? (0) : (-size.Height / 4); newPos.Radius += extraOffset; var cart = newPos.ToCartesianCoordinates(); var mvm = Matrix4.CreateTranslation(0, size.Height / 2, 0) * Matrix4.CreateScale(0.90f + (float)Math.Pow(Math.Sin(_totalTime * 3), 2) * 0.10f) * Matrix4.CreateRotationZ((float)(newPos.Azimuth + extraRotation)) * Matrix4.CreateTranslation(cart.X, cart.Y, 0); _menuFDP.ModelViewMatrix = mvm; }
public Measurement(float aLenght, int aAngle, bool al1, float bLenght, int bAngle, bool bl1, float cLenght, int cAngle, bool cl1) { if (!al1) { aAngle = 360 - aAngle; } a = new PolarVector(aLenght, aAngle, new System.Drawing.Point(0, 0)); if (!bl1) { bAngle = 360 - bAngle; } b = new PolarVector(bLenght, bAngle, new System.Drawing.Point(0, 0)); if (!cl1) { cAngle = 360 - cAngle; } c = new PolarVector(cLenght, cAngle, new System.Drawing.Point(0, 0)); }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { PolarVector [] a = new PolarVector [12]; a[0] = new PolarVector((float)dataGridView1.Rows[0].Cells[1].Value, (float)dataGridView1.Rows[0].Cells[2].Value, new Point(0, 0)); } catch (System.NullReferenceException) { } catch (System.InvalidCastException) { }; Measurement measurement2 = new Measurement(100F, 30, true, 100F, 150, true, 100F, 90, false); }
public void GetOutline(int beatIndex, int sideIndex) { var deltaWidth = Math.Max(_impactDistances[beatIndex] - _positions[beatIndex].Radius, 0); var pOuter = new PolarVector(_positions[beatIndex].Azimuth + sideIndex * _angleBetweenSides[beatIndex], Math.Max(_positions[beatIndex].Radius, _impactDistances[beatIndex] + _outlineWidth) + _widths[beatIndex] - deltaWidth); var pInner = new PolarVector(_positions[beatIndex].Azimuth + sideIndex * _angleBetweenSides[beatIndex], Math.Max(_positions[beatIndex].Radius, _impactDistances[beatIndex] + _outlineWidth)); _outlineBoundsTemp[0] = PolarVector.ToCartesianCoordinates(pOuter); _outlineBoundsTemp[1] = PolarVector.ToCartesianCoordinates(pOuter, _angleBetweenSides[beatIndex], 0); _outlineBoundsTemp[2] = PolarVector.ToCartesianCoordinates(pOuter, _angleBetweenSides[beatIndex], _outlineWidth); _outlineBoundsTemp[3] = PolarVector.ToCartesianCoordinates(pOuter, _angleBetweenSides[beatIndex], _outlineWidth); _outlineBoundsTemp[4] = PolarVector.ToCartesianCoordinates(pOuter, 0, _outlineWidth); _outlineBoundsTemp[5] = PolarVector.ToCartesianCoordinates(pOuter); _outlineBoundsTemp[6] = PolarVector.ToCartesianCoordinates(pInner); _outlineBoundsTemp[7] = PolarVector.ToCartesianCoordinates(pInner, _angleBetweenSides[beatIndex], 0); _outlineBoundsTemp[8] = PolarVector.ToCartesianCoordinates(pInner, _angleBetweenSides[beatIndex], -_outlineWidth); _outlineBoundsTemp[9] = PolarVector.ToCartesianCoordinates(pInner, _angleBetweenSides[beatIndex], -_outlineWidth); _outlineBoundsTemp[10] = PolarVector.ToCartesianCoordinates(pInner, 0, -_outlineWidth); _outlineBoundsTemp[11] = PolarVector.ToCartesianCoordinates(pInner); }
private void InitialisePolygon(List <bool> sides, PolarVector velocity, double width, double minimumRadius, double impactTime) { Velocity = velocity; var initialRadius = (impactTime * Velocity.Radius + minimumRadius + 20); ImpactDistance = minimumRadius; Position = new PolarVector(0, initialRadius); _sides = sides; NumberOfSides = _sides.Count; EvenColour = OddColour = Color4.White; EvenOutlineColour = OddOutlineColour = Color4.Black; AngleBetweenSides = GetAngleBetweenSides(NumberOfSides); _width = width; _evenCount = _oddCount; }
public void Reset() { Score = 0; Hits = 0; _position = new PolarVector(1.5 * (Math.PI / 3) - _length * 0.5f, PLAYER_RADIUS); }
static void FormattedPrint(PolarVector vector, string name) // форматированный вывод данных вектора { Console.WriteLine("Vector {0}. Length: {1:F6}. Polar angle: {2:F6} degrees.", name, vector.GetLength(), vector.GetAngle()); }
static void Main(string[] args) { Console.Title = "PolarVector Demonstation"; ProgramInfo(); PolarVector Z1 = new PolarVector(); // создаем экземпляр класса PolarVector - Z1, используя конструктор по умолчанию Console.WriteLine(); FormattedPrint(Z1, "Z1"); double z2Length, z2Angle; // длина и угол вектора Z2 (вводит пользователь) bool parsed; // прошел ли успешно парсинг введенной строки do { Console.WriteLine("Enter the length of new vector: "); parsed = double.TryParse(Console.ReadLine().Replace('.', ','), out z2Length); }while (!parsed); do { Console.WriteLine("Enter the polar angle of new vector: "); parsed = double.TryParse(Console.ReadLine().Replace('.', ','), out z2Angle); }while (!parsed); PolarVector Z2 = null; do { try { Z2 = new PolarVector(z2Length, z2Angle); // создаем экземпляр класса PolarVector - Z2, используя коструктор с параметрами FormattedPrint(Z2, "Z2"); parsed = true; } catch (ArgumentException e) { Console.WriteLine(e.Message.Remove(e.Message.LastIndexOf('\n'))); do { Console.WriteLine("Enter the length of the vector Z2 once more: "); parsed = double.TryParse(Console.ReadLine().Replace('.', ','), out z2Length); }while (!parsed); parsed = false; } } while (!parsed); PolarVector Z3 = new PolarVector(Z2); // создаем экземпляр класса PolarVector - Z3, используя конструктор копирования FormattedPrint(Z3, "Z3"); Z3 *= 2; // увеличиваем длину вектора Z3 при помощи перегруженной операции * (Альтернатива: Z3 = Z3 * 2) Console.WriteLine("\nNow let's multiply vector Z3 by 2. Z3 *= 2"); FormattedPrint(Z3, "Z3"); Z3.TurnVector(90); // при помощи метода, "поворачиваем" вектор Z3 на 90 градусов () Console.WriteLine("\nNow let's turn vector Z3 on 90 degrees."); FormattedPrint(Z3, "Z3"); try { Z1 = Z2 + Z3; // присваиваем Z1 значение "суммы" Z2 и Z3, вычисленной при помощи перегруженного оператора Console.WriteLine("\nNow let's add vectors Z2 and Z3. The result will be written in vector Z1. Z1 = Z2 + Z3"); FormattedPrint(Z1, "Z1"); } catch (DivideByZeroException e) { Console.WriteLine("Error with vector Z1: both right and left operand`s lengthes were 0."); Console.WriteLine(e.Message); } Console.WriteLine("\nPress ENTER to quit"); Console.ReadKey(); }
private IEnumerable <float> BuildVertexList() { var verts = new Vector2[_vertexBuffer.DrawableIndices]; int index = 0; _evenCount = 0; _oddCount = 0; for (int i = 0; i < NumberOfSides; i += 2) { if (_sides[i]) { var sp = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius); verts[index] = PolarVector.ToCartesianCoordinates(sp); verts[index + 1] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, 0); verts[index + 2] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, _width + PulseWidth); verts[index + 3] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, _width + PulseWidth); verts[index + 4] = PolarVector.ToCartesianCoordinates(sp, 0, _width + PulseWidth); verts[index + 5] = PolarVector.ToCartesianCoordinates(sp); _evenCount += 6; index += 6; } } for (int i = 1; i < NumberOfSides; i += 2) { if (_sides[i]) { var sp = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius); verts[index] = PolarVector.ToCartesianCoordinates(sp); verts[index + 1] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, 0); verts[index + 2] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, _width + PulseWidth); verts[index + 3] = PolarVector.ToCartesianCoordinates(sp, AngleBetweenSides, _width + PulseWidth); verts[index + 4] = PolarVector.ToCartesianCoordinates(sp, 0, _width + PulseWidth); verts[index + 5] = PolarVector.ToCartesianCoordinates(sp); _oddCount += 6; index += 6; } } //generate vertices for outline of even side for (int i = 0; i < NumberOfSides; i += 2) { if (_sides[i]) { var pInner = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius); var pOuter = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius + _width + PulseWidth); verts[index] = PolarVector.ToCartesianCoordinates(pOuter); verts[index + 1] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, 0); verts[index + 2] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, OutlineWidth); verts[index + 3] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, OutlineWidth); verts[index + 4] = PolarVector.ToCartesianCoordinates(pOuter, 0, OutlineWidth); verts[index + 5] = PolarVector.ToCartesianCoordinates(pOuter); verts[index + 6] = PolarVector.ToCartesianCoordinates(pInner); verts[index + 7] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, 0); verts[index + 8] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, OutlineWidth); verts[index + 9] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, OutlineWidth); verts[index + 10] = PolarVector.ToCartesianCoordinates(pInner, 0, OutlineWidth); verts[index + 11] = PolarVector.ToCartesianCoordinates(pInner); index += 12; } } //generate vertices for outline of odd side for (int i = 1; i < NumberOfSides; i += 2) { if (_sides[i]) { var pInner = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius); var pOuter = new PolarVector(Position.Azimuth + i * AngleBetweenSides, Position.Radius + _width + PulseWidth); verts[index] = PolarVector.ToCartesianCoordinates(pOuter); verts[index + 1] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, 0); verts[index + 2] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, OutlineWidth); verts[index + 3] = PolarVector.ToCartesianCoordinates(pOuter, AngleBetweenSides, OutlineWidth); verts[index + 4] = PolarVector.ToCartesianCoordinates(pOuter, 0, OutlineWidth); verts[index + 5] = PolarVector.ToCartesianCoordinates(pOuter); verts[index + 6] = PolarVector.ToCartesianCoordinates(pInner); verts[index + 7] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, 0); verts[index + 8] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, OutlineWidth); verts[index + 9] = PolarVector.ToCartesianCoordinates(pInner, AngleBetweenSides, OutlineWidth); verts[index + 10] = PolarVector.ToCartesianCoordinates(pInner, 0, OutlineWidth); verts[index + 11] = PolarVector.ToCartesianCoordinates(pInner); index += 12; } } return(verts.SelectMany(v => new[] { v.X + Translate.X, v.Y + Translate.Y })); }
public PolarPolygon(List <bool> sides, PolarVector velocity, double width, double minimumRadius, double impactTime) { InitialisePolygon(sides, velocity, width, minimumRadius, impactTime); }
public PolarPolygon(int numberOfSides, PolarVector velocity, double width, double minimumRadius, double impactTime) { var sides = Enumerable.Repeat(true, numberOfSides).ToList(); InitialisePolygon(sides, velocity, width, minimumRadius, impactTime); }
public void ResetSpeedTo(PolarVector v) { Speed = v; }