/// <summary> /// Converts an array into 3 ints, and then checks to see if they are equal. /// </summary> /// <param name="sides">Array of sides to check</param> /// <param name="arg">true for Assert.AreEqual, false for Assert.ArNotEqual</param> public void ArrToSides(int[] sides, bool arg) { if (sides.Count() != 3) { Assert.Fail(); // This method is just for testing that the exact same numbers will pass in both methods. } int a = sides[0]; int b = sides[1]; int c = sides[2]; try { if (arg) { Assert.AreEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides)); } else { Assert.AreNotEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides)); } } catch { TestContext.WriteLine(String.Format("ArrToSidesCheck: Params = {0} - {1} - {2} - Arg: " + arg.ToString(), a, b, c)); TestContext.WriteLine(String.Format("ArrToSidesCheck: Params = Count: {0} - Max: {1} - Min: {2} - Arg: " + arg.ToString(), sides.Count(), sides.Max(), sides.Min())); Assert.Fail(); } }
public void Apply(int rotationChange, int powerChange, MarsLanderEnvironment environment) { if (Status != LanderStatus.Flying) return; if (Situation.Fuel < Situation.Power + powerChange) powerChange = 0; if (Situation.Fuel < Situation.Power) powerChange = -1; Situation.Power += LimitPower(powerChange); Situation.Rotation += LimitRotation(rotationChange); Situation.Fuel -= Situation.Power; Situation.HorizontalSpeed += Trigonometry.GetHorizontalSpeedFraction(Situation.Rotation, ZeroDegreesDirection.Top) * Situation.Power; if (Situation.HorizontalSpeed > MarsLanderRules.MaxHorizontalSpeed) Situation.HorizontalSpeed = MarsLanderRules.MaxHorizontalSpeed; if (Situation.HorizontalSpeed < MarsLanderRules.MinHorizontalSpeed) Situation.HorizontalSpeed = MarsLanderRules.MinHorizontalSpeed; Situation.VerticalSpeed += Trigonometry.GetVerticalSpeedFraction(Situation.Rotation, ZeroDegreesDirection.Top) * Situation.Power - MarsLanderRules.Gravity; if (Situation.VerticalSpeed > MarsLanderRules.MaxVerticalSpeed) Situation.VerticalSpeed = MarsLanderRules.MaxVerticalSpeed; if (Situation.VerticalSpeed < MarsLanderRules.MinVerticalSpeed) Situation.VerticalSpeed = MarsLanderRules.MinVerticalSpeed; Situation.X += Situation.HorizontalSpeed; Situation.Y += Situation.VerticalSpeed; RoundValues(); Situations.Add(Situation.Clone()); Actions.Add($"{rotationChange} {powerChange}"); SetStatus(environment); }
public static void Act(int droneIndex) { var opponentDrones = OpponentDrone.GetOpponentDrones(); var unoccupiedZones = GameOfDronesManager.Zones.Where(zone => zone.OwnerId == -1); var heldZones = GameOfDronesManager.Zones.Where(zone => zone.OwnerId == GameOfDronesManager.PlayerId) .Select(zone => new { zone, OpponentCount = GameOfDronesManager.Participants .Select(participant => participant.Drones .Count(drone => Trigonometry.GetDistance( new Point(drone.Location.X, drone.Location.Y), new Point(zone.Center.X, zone.Center.Y)) <= GameOfDronesManager.ZoneRadius)) .OrderByDescending(count => count) .First() }); // Find empty zones and send as many as is feasible (while keeping all currently held zones occupied). var untargetedZones = GameOfDronesManager.Zones.ToList(); foreach (var targetZone in opponentDrones.Select(drone => drone.TargetZone)) { untargetedZones.RemoveAll(zone => zone.Id == targetZone.Id); } // Assign player drones to target nearest unassigned zone. Actions.Commit(GoToNearestAvailableZone(droneIndex, untargetedZones)); }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (TargetShip != null) { // If we are not driven by another ship, we should update the position if ((Parent == UnderSiegeGameplayScreen.SceneRoot || Parent == null)) { float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, TargetShip.WorldPosition); if (Math.Abs(angle - WorldRotation) > 0.1f) { RigidBody.AngularVelocity = Trigonometry.GetRotateDirectionForShortestRotation(this, TargetShip.WorldPosition) * TotalThrust * 0.01f / ShipData.Mass; } else { RigidBody.FullAngularStop(); } if ((TargetShip.WorldPosition - WorldPosition).LengthSquared() >= minDistance * minDistance) { RigidBody.LinearVelocity = new Vector2(RigidBody.LinearVelocity.X, TotalThrust / ShipData.Mass); } else { RigidBody.FullLinearStop(); } } } else { FindNearestTargetShip(); } }
/// <summary> /// Initializes an circle from three points. /// https://github.com/sergarrido/random/tree/master/circle3d /// </summary> /// <param name="pt1">Start point of the arc.</param> /// <param name="pt2">Interior point on arc.</param> /// <param name="pt3">End point of the arc.</param> public Circle(Point3 pt1, Point3 pt2, Point3 pt3) { if (!pt1.IsValid) { throw new Exception("The first point is not valid."); } if (!pt2.IsValid) { throw new Exception("The second point is not valid."); } if (!pt3.IsValid) { throw new Exception("The third point is not valid."); } Point3 center = Trigonometry.EquidistantPoint(pt1, pt2, pt3); Vector3 normal = Vector3.ZAxis.PerpendicularTo(pt1, pt2, pt3); Vector3 xDir = pt1 - center; Vector3 yDir = Vector3.CrossProduct(normal, xDir); Plane = new Plane(center, xDir, yDir); Radius = xDir.Length; _length = Math.Abs(2.0 * Math.PI * Radius); ToNurbs(); }
public void TestTypeOrdering() { ParameterExpression x = Expression.Parameter(typeof(int), "x"); ConstantExpression c = Expression.Constant(2); BinaryExpression sum = Expression.Add(x, c); BinaryExpression product = Expression.Multiply(x, c); Expression cos = Trigonometry.Cosine(x); Expression sin = Trigonometry.Sine(x); Assert.IsTrue(Ordering.Compare(c, x) < 0, "2 < x"); Assert.IsTrue(Ordering.Compare(x, c) > 0, "x > 2"); Assert.IsTrue(Ordering.Compare(c, sum) < 0, "2 < (2+x)"); Assert.IsTrue(Ordering.Compare(sum, c) > 0, "(2+x) > 2"); Assert.IsTrue(Ordering.Compare(x, sum) < 0, "x < (2+x)"); Assert.IsTrue(Ordering.Compare(sum, x) > 0, "(2+x) > x"); Assert.IsTrue(Ordering.Compare(x, sin) < 0, "x < sin(x)"); Assert.IsTrue(Ordering.Compare(sin, x) > 0, "sin(x) > x"); Assert.IsTrue(Ordering.Compare(product, sum) < 0, "2*x < (2+x)"); Assert.IsTrue(Ordering.Compare(sum, product) > 0, "(2+x) > 2*x"); Assert.IsTrue(Ordering.Compare(sum, sum) == 0, "(2+x) = (2+x)"); Assert.IsTrue(Ordering.Compare(product, product) == 0, "2*x = 2*x"); Assert.IsTrue(Ordering.Compare(product, sin) < 0, "2*x < sin(x)"); Assert.IsTrue(Ordering.Compare(sin, product) > 0, "sin(x) > 2*x"); Assert.IsTrue(Ordering.Compare(cos, sin) < 0, "cos(x) < sin(x)"); Assert.IsTrue(Ordering.Compare(sin, cos) > 0, "sin(x) > cos(x)"); }
public Resultado GetClima(int dia) { if (Trigonometry.Colinealidad(_planetas[0].GetPosicion(dia), _planetas[1].GetPosicion(dia), _planetas[2].GetPosicion(dia), _deltaColinealidad)) { // Si los 3 planetas están en linea, reemplazo cualquiera de ellos por el sol, y verifico si tmb están en linea. if (Trigonometry.Colinealidad(_planetas[0].GetPosicion(dia), _planetas[1].GetPosicion(dia), _sol.GetPosicion(dia), _deltaColinealidad)) { return new Resultado { Dia = dia, Clima = Constants.Sequia, Lluvia = 0 } } ; return(new Resultado { Dia = dia, Clima = Constants.Optimo, Lluvia = 0 }); } if (Trigonometry.PuntoEnTriangulo(_planetas[0].GetPosicion(dia), _planetas[1].GetPosicion(dia), _planetas[2].GetPosicion(dia), _sol.GetPosicion(dia))) { return(new Resultado { Dia = dia, Clima = Constants.Lluvia, Lluvia = Trigonometry.GetPerimetro(_planetas[0].GetPosicion(dia), _planetas[1].GetPosicion(dia), _planetas[2].GetPosicion(dia)) }); } return(new Resultado { Dia = dia, Clima = Constants.Confuso, Lluvia = 0 }); } }
/// <summary> /// Create a new rotation matrix based on a rotation axis and an angle. /// </summary> /// <param name="axis">Axis around which the rotation is executed</param> /// <param name="angle">Angle of the clockwise rotation.</param> public RotationMatrix3d(Cartesian3dCoordinate axis, double angle) { // Angle is reverse to provide a clockwise rotation. double c = Trigonometry.Cos(-angle); double s = Trigonometry.Sin(-angle); double t = 1.0 - c; // Need to use normalised vector. axis = axis.Normalize(); // Create the matrix m_Matrix = new double[3, 3]; m_Matrix[0, 0] = c + (axis.X * axis.X * t); m_Matrix[1, 1] = c + (axis.Y * axis.Y * t); m_Matrix[2, 2] = c + (axis.Z * axis.Z * t); double part1 = axis.X * axis.Y * t; double part2 = axis.Z * s; m_Matrix[1, 0] = part1 + part2; m_Matrix[0, 1] = part1 - part2; part1 = axis.X * axis.Z * t; part2 = axis.Y * s; m_Matrix[2, 0] = part1 - part2; m_Matrix[0, 2] = part1 + part2; part1 = axis.Y * axis.Z * t; part2 = axis.X * s; m_Matrix[2, 1] = part1 + part2; m_Matrix[1, 2] = part1 - part2; }
public override void Execute(GameTime gameTime) { base.Execute(gameTime); float targetAngle = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(ObjectToRotate.WorldPosition, Position); float distance = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(ObjectToRotate, Position); if (distance < 0.005f) { // ObjectToRotate.WorldRotation = targetAngle; Completed = true; return; } float directionToRotate = Trigonometry.GetRotateDirectionForShortestRotation(ObjectToRotate, Position); if (!GlobalVariables.SIMPLEPHYSICS) { float distanceToStartDeccelerating = ObjectToRotate.RigidBody.AngularVelocity * (float)Math.Ceiling(ObjectToRotate.RigidBody.AngularVelocity / acceleration) * 0.5f; if (distance > distanceToStartDeccelerating) { ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * acceleration; } else { ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(ObjectToRotate.WorldRotation - targetAngle) * acceleration; } } else { ObjectToRotate.RigidBody.AngularVelocity = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * ObjectToRotate.RigidBody.MaxAngularVelocity; } }
public void GetIntersections_ValidParameters_GetIntersection( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, IntersectionType expectedIntersectionType, double?expectedIntersectX, double?expectedIntersectY) { var vector1 = new Vector(new Point(x1, y1), new Point(x2, y2)); var vector2 = new Vector(new Point(x3, y3), new Point(x4, y4)); var sw = Stopwatch.StartNew(); var intersection = Trigonometry.GetIntersection(vector1, vector2); Console.WriteLine(sw.Elapsed); Assert.Multiple(() => { Assert.That(intersection.IntersectionType, Is.EqualTo(expectedIntersectionType)); Assert.That(intersection.X, Is.EqualTo(expectedIntersectX)); Assert.That(intersection.Y, Is.EqualTo(expectedIntersectY)); }); }
private void CreateTransferVector(Case_Load boxLoad, out float timeToTransfer, out Vector3 transferVector) { if ((CurrentTask.Source.Side() == RackSide.Right && !ParentMS.SwitchSides) || (CurrentTask.Source.Side() == RackSide.Left && ParentMS.SwitchSides)) { rackLoc = -shuttleAP_Zpos; } else { rackLoc = shuttleAP_Zpos; } int loadDepth = CurrentTask.Destination.LoadDepth(); //Get the depth in the rack timeToTransfer = ParentMS.TimeToPos1; if (loadDepth == -1) //-1 = IA = Inter Aisle Transfer { timeToTransfer = ParentMS.TimeToPos1 + ParentMS.TimeToPos2; rackLoc = rackLoc * 3; //dropoff into the other aisle } else if (loadDepth == 2) { rackLoc = rackLoc * 2; timeToTransfer = ParentMS.TimeToPos2; } Vector3 direction = Trigonometry.DirectionYaw(Trigonometry.Yaw(boxLoad.Route.Orientation)); transferVector = Trigonometry.CrossProduct(direction, new Vector3(0, rackLoc, 0)); }
private static string GoToNearestZone(int droneIndex) { var drone = GameOfDronesManager.Player.PlayerDrones[droneIndex]; var zones = GameOfDronesManager.Zones .Where(zone => zone.OwnerId != GameOfDronesManager.PlayerId) .Select(zone => new { zone.Center.X, zone.Center.Y, zone.OwnerId, DistanceToCurrentDrone = Trigonometry.GetDistance( new Point(zone.Center.X, zone.Center.Y), new Point(drone.Location.X, drone.Location.Y)) }); var nearestZone = zones .OrderBy(zone => zone.DistanceToCurrentDrone) .FirstOrDefault(); if (nearestZone == null) { return($"{drone.Location.X} {drone.Location.Y}"); } return($"{nearestZone.X} {nearestZone.Y}"); }
public Operand Simplify(Polynomials p, Numbers n, Trigonometry t, Dictionary <char, Operand> dict) { os = new Simplifier(p, n, t, dict); Print.Log("formatting"); Operand ans = os.Simplify(this); if (os.CanFactor) { PossibleForms[Polynomials.Factored] = true; } if (os.CanExpand) { PossibleForms[Polynomials.Expanded] = true; } if (os.ts.HasExactForm) { PossibleForms[Numbers.Exact] = true; } HasTrig = os.ts.tfs.HasTrig; return(ans); }
public GridNodeAStar(GridNode thisGridNode, GridNode originGridNode, GridNode targetGridNode) { X = thisGridNode.X; Y = thisGridNode.Y; GCost = Trigonometry.GetGridDistance(new Point(X, Y), new Point(originGridNode.X, originGridNode.Y)); HCost = Trigonometry.GetGridDistance(new Point(X, Y), new Point(targetGridNode.X, targetGridNode.Y)); }
private static string FormatComplex(Complex cplx, TrigonometryMode trigonometryMode) { var sb = new StringBuilder(); sb.Append("R: "); sb.Append(cplx.Real); sb.Append(" i: "); sb.Append(cplx.Imaginary); sb.Append("\r\n φ: "); switch (trigonometryMode) { case TrigonometryMode.DEG: sb.Append(Trigonometry.Rad2Deg(cplx.Phase)); sb.Append(" °"); break; case TrigonometryMode.GRAD: sb.Append(Trigonometry.Rad2Grad(cplx.Phase)); sb.Append(" grad"); break; case TrigonometryMode.RAD: sb.Append(cplx.Phase); sb.Append(" rad"); break; } sb.Append(" ABS: "); sb.Append(cplx.Magnitude); return(sb.ToString()); }
public override void Update(GameTime gameTime) { base.Update(gameTime); FindTarget(); if (Target != null) { CheckIfDamagedTarget(); // Rotate to target float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, Target.WorldPosition); if (Math.Abs(angle - WorldRotation) > 0.1f) { RigidBody.AngularVelocity = 3.5f * Trigonometry.GetRotateDirectionForShortestRotation(this, Target.WorldPosition); } else { LocalRotation = angle - Parent.WorldRotation; RigidBody.FullAngularStop(); } } FiringArc.Visible = MouseOver || IsSelected; FiringArc.Update(gameTime); }
private static string GoToNearestAvailableZone( int droneIndex, IEnumerable <Zone> availableZones) { var drone = GameOfDronesManager.Player.PlayerDrones[droneIndex]; var zonesWithDistance = availableZones .Where(zone => zone.OwnerId != GameOfDronesManager.PlayerId) .Select(zone => new { zone.Center.X, zone.Center.Y, zone.OwnerId, DistanceToCurrentDrone = Trigonometry.GetDistance( new Point(zone.Center.X, zone.Center.Y), new Point(drone.Location.X, drone.Location.Y)) }); var nearestZone = zonesWithDistance.OrderBy(zone => zone.DistanceToCurrentDrone).FirstOrDefault(); if (nearestZone == null) { return(GoToNearestZone(droneIndex)); } drone.Target = $"{nearestZone.X} {nearestZone.Y}"; return(drone.Target); }
public void TestException() // make sure our exceptions work { try { bool x = Trigonometry.isPythagoreanTriple(Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue - 2); // DllNotFoundException just used as a placeholder for something that is not ArgumentException throw new DllNotFoundException("Did not throw ArgumentException"); } catch (ArgumentException) { TestContext.WriteLine("ArgumentException block."); // The arguments failed and ArgumentException was thrown Assert.IsTrue(true); } catch (DllNotFoundException) { TestContext.WriteLine("DllNotFoundException block"); // The arguments did not fail Assert.Fail(); } catch (Exception ex) // The arguments failed, but a different exception was thrown { TestContext.WriteLine(ex.ToString() + "\r\n\r\n" + ex.Message); Assert.Fail(); } }
private void btnCot_Click(object sender, EventArgs e) { if (checkContent()) { double inputNumber = Convert.ToDouble(txtInput.Text); txtInput.Text = Trigonometry.GetCot(inputNumber).ToString(); } }
public Posicion GetPosicion(int dia) { var angulo = Strategy.GetAngulo(AnguloInicial, Velocidad, dia); var xyPos = Trigonometry.DegreesToXY(angulo, Distancia); return(xyPos); }
protected override void IfSelected() { base.IfSelected(); // Here we are changing the orientation of the turret, so it should not fire Orientation = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, ScreenManager.GameMouse.InGamePosition); LocalRotation = Orientation; currentFireTimer = 0; }
private double GetAngle() { if (_angle != null) { return((double)_angle); } _angle = Trigonometry.GetAngle(Point1, Point2); return((double)_angle); }
public void It_Returns_False_If_Three_Points_Are_Not_Collinear() { // Arrange Point3 pt1 = new Point3(25.923, 27.057, 0.0); Point3 pt2 = new Point3(35.964, 20.451, 0.0); Point3 pt3 = new Point3(51.299, 37.950, 0.0); // Assert Trigonometry.ArePointsCollinear(pt1, pt2, pt3).Should().BeFalse(); }
public IEnumerable <Drone> GetOccupyingDrones() { return(GameOfDronesManager.Participants .SelectMany(participant => participant.Drones .Where(drone => Trigonometry.GetDistance( new Point(drone.Location.X, drone.Location.Y), new Point(Center.X, Center.Y)) < GameOfDronesManager.ZoneRadius))); }
public void LoadPallet() { Core.Resources.Mesh mesh = Common.Meshes.Get("cube"); palletLoad = Load.Create(mesh, LoadLength, LoadHeight - euroPalletInfo.height, LoadWidth); palletLoad.Color = LoadColor; palletLoad.UserDeletable = false; palletLoad.OnSelecting += palletLoad_OnSelecting; palletLoad.Yaw = Trigonometry.PI(Trigonometry.Angle2Rad(Angle)); Group(palletLoad, new Vector3(0, (LoadHeight / 2) + 0.001f, 0)); }
private void TrackStopPoint_OnEnter(ActionPoint sender, Load load) { track.Route.Motor.Stop(); if (Tasks.Count > 0) { var currentTask = Tasks[0]; if (currentTask.TCarCycle == TCycle.Load) { IRouteStatus sourceConveyor = (IRouteStatus)currentTask.Source.Attached.Parent; sourceConveyor.TransportSection.Route.NextRoute = conveyor.TransportSection.Route; if (currentTask.Source.LocalPosition.Z == conveyor.StartFixPoint.LocalPosition.X) { conveyor.LocalYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f)); } else { conveyor.LocalYaw = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f)); } conveyor.ThisRouteStatus.Available = RouteStatuses.Available; currentTask.Source.FixPointRouteStatus.Available = RouteStatuses.Available; currentTask.TCarCycle = TCycle.Unload; } else { if (currentTask.Destination.LocalPosition.Z == conveyor.EndFixPoint.LocalPosition.X) { if (conveyor.TransportSection.Route.Loads.Count > 0) { var loadDistance = conveyor.TransportSection.Route.Loads.First().Distance; conveyor.LocalYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f)); conveyor.TransportSection.Route.Loads.First().Distance = conveyor.TransportSection.Route.Length - loadDistance; } } else if (currentTask.Destination.LocalPosition.Z == conveyor.StartFixPoint.LocalPosition.X) { if (conveyor.TransportSection.Route.Loads.Count > 0) { var loadDistance = conveyor.TransportSection.Route.Loads.First().Distance; conveyor.LocalYaw = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f)); conveyor.TransportSection.Route.Loads.First().Distance = conveyor.TransportSection.Route.Length - loadDistance; } } IRouteStatus destinationConveyor = (IRouteStatus)currentTask.Destination.Attached.Parent; conveyor.TransportSection.Route.NextRoute = destinationConveyor.TransportSection.Route; if (currentTask.Destination.FixPointRouteStatus.Available == RouteStatuses.Available) { conveyor.ThisRouteStatus.Available = RouteStatuses.Request; } } } }
public Distance GetDistanceFromFlatSurface(Lander lander) { if (_landingZone == null) { SetLandingZone(); } var side = Side.Above; if (lander.Situation.X < _landingZone.LeftX) { side = Side.Left; } if (lander.Situation.X > _landingZone.RightX) { side = Side.Right; } var horizontalDistance = 0.0; var fullDistance = 0.0; if (side == Side.Left) { horizontalDistance = _landingZone.LeftX - lander.Situation.X; fullDistance = Trigonometry.GetDistance( new Point(_landingZone.LeftX, _landingZone.LeftY), new Point(lander.Situation.X, lander.Situation.Y)); } if (side == Side.Right) { horizontalDistance = _landingZone.RightX - lander.Situation.X; fullDistance = Trigonometry.GetDistance( new Point(_landingZone.RightX, _landingZone.RightY), new Point(lander.Situation.X, lander.Situation.Y)); } if (side == Side.Above) { fullDistance = Trigonometry.GetDistance( new Point(lander.Situation.X, // We are above, so we do not need to move to the left or right. _landingZone.LeftY), // Y is the same everywhere in the landing zone. new Point(lander.Situation.X, lander.Situation.Y)); } return(new Distance { HorizontalDistance = horizontalDistance, VerticalDistance = lander.Situation.Y - _landingZone.LeftY, // Y is the same everywhere in the landing zone. FullDistance = fullDistance }); }
public override void Update(GameTime gameTime) { base.Update(gameTime); currentLifeTimer += gameTime.ElapsedGameTime; if (currentLifeTimer >= TimeSpan.FromSeconds(MissileData.BulletLifeTime)) { Die(); } if (RigidBody.LinearVelocity.X < 0) { RigidBody.LinearAcceleration = new Vector2(500, RigidBody.LinearAcceleration.Y); } else { RigidBody.LinearVelocity = new Vector2(0, RigidBody.LinearVelocity.Y); RigidBody.LinearAcceleration = new Vector2(0, RigidBody.LinearAcceleration.Y); } if (Target != null && Target.Alive) { float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, Target.WorldPosition); if (Math.Abs(angle - WorldRotation) > 0.1f) { RigidBody.AngularVelocity = 15 * Trigonometry.GetRotateDirectionForShortestRotation(this, Target.WorldPosition); } else { // Bad that we are assuming it is not parented to anything, but I think that is a valid assumption LocalRotation = angle; RigidBody.FullAngularStop(); } } else { RigidBody.FullAngularStop(); } EngineBlaze.Update(gameTime); if (Explosion.Animation.IsPlaying) { Explosion.Update(gameTime); } if (Explosion.Animation.Finished) { Alive = false; } }
virtual public void FromAngle(float angle) { DisableAll(); /** * Splitting a circle in 16 parts * I can use every couple of pieces to have the circle split giving equal priority * To each cardinal side of a D-Pad. later increased the size of the north, south, east, and west * cardinals so it feels better. */ float DiagonalPriority = ControllerSettings.DPAD_FROM_ANGLE_MODIFIER_IN_RADIANS; if (angle < Trigonometry.CardinalDirection(ZONE_ONE + DiagonalPriority) && angle >= Trigonometry.CardinalDirection(-ZONE_ONE - DiagonalPriority)) { _rightKey = true; } else if ((angle >= Trigonometry.CardinalDirection(ZONE_FOUR - DiagonalPriority) && angle <= Trigonometry.CardinalDirection(OUTSIDE_OF_ZONES)) || (angle >= Trigonometry.CardinalDirection(-OUTSIDE_OF_ZONES) && angle <= Trigonometry.CardinalDirection(-ZONE_FOUR + DiagonalPriority))) { _leftKey = true; } else if (angle >= Trigonometry.CardinalDirection(ZONE_TWO - DiagonalPriority) && angle < Trigonometry.CardinalDirection(ZONE_THREE + DiagonalPriority)) { _downKey = true; } else if (angle >= Trigonometry.CardinalDirection(-ZONE_THREE - DiagonalPriority) && angle < Trigonometry.CardinalDirection(-ZONE_TWO + DiagonalPriority)) { _upKey = true; } else if (angle >= Trigonometry.CardinalDirection(-ZONE_TWO) && angle < Trigonometry.CardinalDirection(-ZONE_ONE)) { _upKey = true; _rightKey = true; } else if (angle >= Trigonometry.CardinalDirection(ZONE_ONE) && angle < Trigonometry.CardinalDirection(ZONE_TWO)) { _rightKey = true; _downKey = true; } else if (angle >= Trigonometry.CardinalDirection(ZONE_THREE) && angle < Trigonometry.CardinalDirection(ZONE_FOUR)) { _downKey = true; _leftKey = true; } else if (angle >= Trigonometry.CardinalDirection(-ZONE_FOUR) && angle < Trigonometry.CardinalDirection(-ZONE_THREE)) { _leftKey = true; _upKey = true; } }
private void AddFixPoints(string[] fixPointList, LoadDirection direction, float leftPosition, float rightPosition) { var color = direction == LoadDirection.Source ? Color.Red : Color.Blue; var fixPointType = direction == LoadDirection.Source ? FixPoint.Types.Start : FixPoint.Types.End; foreach (var fixPoint in fixPointList) { var localYaw = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f)); var fixPointArray = fixPoint.Split(':'); var side = fixPointArray[0]; var name = fixPointArray.Length > 2 ? fixPointArray[2] : ""; var trackSide = string.Equals("R", side) ? rightPosition : leftPosition; if (string.Equals("R", side) && direction == LoadDirection.Source) { localYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f)); } if (string.Equals("L", side) && direction == LoadDirection.Destination) { localYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f)); } var trackPosition = TCarLength / 2 - 0.05f; // Default value to be replaced by TryParse var isFloat = float.TryParse(fixPointArray[1], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"), out trackPosition); if (isFloat) { // Find out which fixpoint is the furthest furthestFixPoint = furthestFixPoint < trackPosition ? trackPosition : furthestFixPoint; DematicFixPoint fp = new DematicFixPoint(color, fixPointType, this); fp.Name = name; if (direction == LoadDirection.Source) { fp.OnSnapped += new FixPoint.SnappedEvent(SourceFixPoint_OnSnapped); fp.OnUnSnapped += new FixPoint.UnSnappedEvent(SourceFixPoint_OnUnSnapped); } else { fp.OnSnapped += new FixPoint.SnappedEvent(DestinationFixPoint_OnSnapped); fp.OnUnSnapped += new FixPoint.UnSnappedEvent(DestinationFixPoint_OnUnSnapped); } Add(fp); fp.LocalPosition = new Vector3(-trackPosition, 0, trackSide); fp.LocalYaw = localYaw; // Label Text3D label = new Text3D(Color.Yellow, 0.08f, 0.1f, new Font(FontFamily.GenericSansSerif, 1.0f)); label.Text = name; Add(label); label.LocalPosition = new Vector3(-trackPosition + 0.08f, 0, trackSide - 0.02f); label.Pitch = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f)); } } }