/// <summary> /// Gets the particle. /// </summary> /// <returns> /// A new particle. /// </returns> public override IParticle GetParticle() { // Determine initial position by displacing the particles around the InitialPosition. var position = this.Position; var scaledPositionCoefficient = PositionCoefficient * this.Scale; position.X += MathsHelper.Random((int)-scaledPositionCoefficient.X, (int)scaledPositionCoefficient.X); // Determine velocity. var velocity = new Vector2(0f, -0.125f); var lifespan = MathsHelper.Random(5, 15); var particle = Atlas.GetAnimatedParticle( "gameplay", "Skull", this, position, velocity, 0f, 0f, this.Scale, recycle: true, fadeIn: true, fadeOut: true, frameDelay: lifespan, trackParent: false, shrink: false); particle.Color = curseColor; return(particle); }
// Update is called once per frame void Update() { Vector3 desiredPosition = GetDesiredCameraPosition(); Vector3 actualPosition = desiredPosition; if (m_lerpAmount < 1.0f && m_lerpToTriggerTime > 0) { m_lerpAmount += (Time.deltaTime / m_lerpToTriggerTime); actualPosition = Vector3.Lerp(m_lerpPosition, desiredPosition, m_lerpAmount); } if (m_shaking) { m_shakeTime += Time.deltaTime; if (m_shakeTime > m_shakeLerp) { m_lastShakePositionOffset = m_shakePositionOffset; m_shakeTime = 0.0f; m_shakePositionOffset = MathsHelper.RandomWithNegativeVector2() * m_shakeDistance; } actualPosition += Vector3.Lerp(m_lastShakePositionOffset, m_shakePositionOffset, m_shakeTime / m_shakeLerp); } transform.position = actualPosition; }
public void DivisonTest() { MathsHelper helper = new MathsHelper(); int result = helper.Division(20, 10); Assert.AreEqual(2, result); }
public void SubtractTest() { MathsHelper helper = new MathsHelper(); int result = helper.Subtract(20, 10); Assert.AreEqual(10, result); }
void OnSceneGUI() { IntersectionTester tester = (IntersectionTester)target; float handleSize = HandleUtility.GetHandleSize((Vector3)tester.v0) / 8.0f; tester.v0 = Handles.Slider2D(tester.v0, Vector3.up, Vector3.right, Vector3.forward, handleSize, Handles.SphereCap, new Vector2(0.1f, 0.1f)); tester.v1 = Handles.Slider2D(tester.v1, Vector3.up, Vector3.right, Vector3.forward, handleSize, Handles.SphereCap, new Vector2(0.1f, 0.1f)); tester.v2 = Handles.Slider2D(tester.v2, Vector3.up, Vector3.right, Vector3.forward, handleSize, Handles.SphereCap, new Vector2(0.1f, 0.1f)); tester.v3 = Handles.Slider2D(tester.v3, Vector3.up, Vector3.right, Vector3.forward, handleSize, Handles.SphereCap, new Vector2(0.1f, 0.1f)); tester.v4 = Handles.Slider2D(tester.v4, Vector3.up, Vector3.right, Vector3.forward, handleSize, Handles.SphereCap, new Vector2(0.1f, 0.1f)); Vector2 altV0 = new Vector2(tester.v0.x, tester.v0.z); Vector2 altV1 = new Vector2(tester.v1.x, tester.v1.z); Vector2 altV2 = new Vector2(tester.v2.x, tester.v2.z); Vector2 altV3 = new Vector2(tester.v3.x, tester.v3.z); Vector2 altV4 = new Vector2(tester.v4.x, tester.v4.z); Vector2 i0, i1; bool intersection = MathsHelper.LineTriIntersect(altV0, altV1, altV2, altV3, altV4, out i0, out i1); intersection |= MathsHelper.LineInTri(altV0, altV1, altV2, altV3, altV4); Handles.color = intersection ? Color.red : Color.green; Handles.DrawLine(tester.v0, tester.v1); Handles.DrawLine(tester.v2, tester.v3); Handles.DrawLine(tester.v4, tester.v3); Handles.DrawLine(tester.v4, tester.v2); }
public void Open(GameObject trigger) { Vector2 posXY = new Vector2(trigger.transform.position.x, trigger.transform.position.z); Vector2 hingeStart = new Vector2(PivotPosition.x, PivotPosition.z); Vector2 hingeEnd = hingeStart + new Vector2(DoorDirection.x, DoorDirection.z); float sign = MathsHelper.sign(posXY, hingeStart, hingeEnd); sign = sign / Mathf.Abs(sign); m_lerpDirection = -sign; // 1.0f; m_openInteraction.Enabled = false; m_closeInteraction.Enabled = true; m_targetValue = -sign; m_sourceValue = 0.0f; AudioSource source = GetComponent <AudioSource>() as AudioSource; if (source != null) { source.Play(); } }
/// <summary> /// Calculate the area enclosed by this curve, were the start and end points to be /// joined by a straight line segment. /// A plane may optionally be specified, otherwise by default the projected area on /// the XY plane will be used. /// </summary> /// <param name="centroid">Output. The centroid of the enclosed area, in local coordinates /// on the specified plane.</param> /// <param name="onPlane">The plane to use to calculate the area. /// If not specified, the XY plane will be used.</param> /// <returns>The signed area enclosed by this curve on the specified plane, /// as a double.</returns> public override double CalculateEnclosedArea(out Vector centroid, Plane onPlane = null) { double result = 0; centroid = Vector.Zero; for (int i = 0; i < SubCurves.Count; i++) { Curve subCrv = SubCurves[i]; Vector start = subCrv.StartPoint; Vector end = subCrv.EndPoint; if (onPlane != null) { start = onPlane.GlobalToLocal(start); end = onPlane.GlobalToLocal(end); } double areaUnder = MathsHelper.AreaUnder(start.X, start.Y, end.X, end.Y, ref centroid); result += areaUnder; Vector subCentroid; double subArea = subCrv.CalculateEnclosedArea(out subCentroid, onPlane); result += subArea; centroid += subCentroid * subArea; } centroid /= result; return(result); }
private void ShotgunState() { m_timeSinceLastShot += Time.deltaTime; float attackRate = 1 / (m_shotgunAttackSpeed); if (m_timeSinceLastShot > attackRate) { m_audio.TriggerShotgun(); m_timeSinceLastShot = 0.0f; int bulletsToFire = Random.Range(m_shotgunAttackCountMin, m_shotgunAttackCountMax); Vector2 playerDirection = m_movement.DirectionToPlayer(); for (int i = 0; i < bulletsToFire; ++i) { Vector2 attackNormal = playerDirection.PerpendicularClockwise(); Vector2 inaccuracy = attackNormal * MathsHelper.RandomWithNegative() * (m_shotgunAttackInaccuracy * m_stage); Vector2 attackVelocity = (playerDirection + inaccuracy) * (m_shotgunBulletSpeed + m_shotgunAttackVelocityVariance * m_stage * Random.value); m_shooting.Shoot(attackVelocity, 1); } } if (m_timeInState > m_shotgunDuration) { ChooseNextState(); } }
/// <summary> /// Calculate the position of the inner corner /// </summary> /// <param name="roadIndexA">The first road index</param> /// <param name="roadIndexB">The second road index</param> /// <param name="magnitude">The magnitude of the corner</param> /// <param name="posOut">The position of the innre corner</param> /// <returns>True if we have found a cross over</returns> public bool GetInnerCorner(int roadIndexA, int roadIndexB, float magnitude, out Vector3 posOut) { Vector3 pos = gameObject.transform.position; RoadNetworkNode rnn = Details.Roads[roadIndexA].GetComponent <RoadNetworkNode>(); Vector3 roadPointA = rnn.GetOffSetDownRoad(pos, magnitude); RoadNetworkNode rnnB = Details.Roads[roadIndexB].GetComponent <RoadNetworkNode>(); Vector3 roadPointB = rnnB.GetOffSetDownRoad(pos, magnitude); Vector3 roadPointAEnd = MathsHelper.OffSetVector( roadPointA, Details.Roads[roadIndexA].GetAngleOfRoad(pos) + (float)(Math.PI / 2), magnitude); Vector3 roadPointBEnd = MathsHelper.OffSetVector( roadPointB, Details.Roads[roadIndexB].GetAngleOfRoad(pos) + (float)(Math.PI / 2), magnitude); posOut = new Vector3(); Vector3 outB = new Vector3(); Vector3 diffA = roadPointA - roadPointAEnd; Vector3 diffB = roadPointB - roadPointBEnd; if (MathsHelper.ClosestPointsOnTwoLines(out posOut, out outB, roadPointA, diffA.normalized, roadPointB, diffB.normalized)) { return(true); } posOut = (roadPointA + roadPointB) / 2; return(false); }
/// <summary> /// Update all of the end points of the cross roads /// </summary> /// <param name="order">The orderd list of roads</param> /// <param name="mbs">The created mesg builder</param> /// <param name="leftIntersectionInner">The inner left cross section</param> /// <param name="leftIntersectionOutter">The outter left cross section</param> /// <param name="rightIntersectionInner">The inner right cross section</param> /// <param name="rightIntersectionOutter">The outter right cross section</param> /// <param name="middleIntersectionInner">The middle road cross sections</param> /// <param name="oppositeIntersectionInner">The opposite road cross sections</param> private void UpdateRoadNodesEndPoints(out RoadCrossRoadOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner, out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter, out RoadCrossSection middleIntersectionInner, out RoadCrossSection oppositeIntersectionInner) { RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0]; RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1]; RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2]; RoadNetworkNode roadD = _roadNetworkNode.Details.Roads[3]; order = new RoadCrossRoadOrder( _list[0], roadA, _list[1], roadB, _list[2], roadC, _list[3], roadD); mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0); // left road Vector3 posA; Vector3 posA2; Vector3 posB; FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.CurbLeftEnd, order.LeftRoad.CurbRightEnd, out posA); FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.Left, order.LeftRoad.CurbRightEnd, out posA2); FindOverlapPoint(order.OppositeRoad.Angle, order.LeftRoad.Angle, order.OppositeRoad.CurbRightEnd, order.LeftRoad.CurbLeftEnd, out posB); Vector3 curbToCurb = posA - posB; float newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2); leftIntersectionInner = order.LeftRoad.GetIntersection(newRoadAngle, posA); leftIntersectionOutter = order.LeftRoad.GetIntersection(newRoadAngle, posA2); FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.CurbRightEnd, order.RightRoad.CurbLeftEnd, out posA); FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.Right, order.RightRoad.CurbLeftEnd, out posA2); FindOverlapPoint(order.OppositeRoad.Angle, order.RightRoad.Angle, order.OppositeRoad.CurbLeftEnd, order.RightRoad.CurbRightEnd, out posB); curbToCurb = posB - posA; newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2); rightIntersectionInner = order.RightRoad.GetIntersection(newRoadAngle, posA); rightIntersectionOutter = order.RightRoad.GetIntersection(newRoadAngle, posA2); curbToCurb = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd; newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2); middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbLeftEnd); curbToCurb = rightIntersectionInner.CurbRightEnd - leftIntersectionInner.CurbLeftEnd; newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) - (Mathf.PI / 2); oppositeIntersectionInner = order.OppositeRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbRightEnd); // Store the ids so we know where to update them later Guid leftRoadNodeId = order.LeftRoad.ID; Guid rightRoadNodeId = order.RightRoad.ID; Guid middleRoadNodeId = order.MiddleRoad.ID; Guid oppositeRoadNodeId = order.OppositeRoad.ID; order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle)); order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle)); order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle)); order.ReSetOpposite(FindSmallestRoadForJunction(order.OppositeRoadNode, oppositeIntersectionInner, order.OppositeRoad.Middle)); IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad); IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad); IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad); IntersectionManager.Instance.SetIntersection(oppositeRoadNodeId, order.OppositeRoad); }
public void AddTest() { MathsHelper helper = new MathsHelper(); int result = helper.Add(20, 10); NUnit.Framework.Assert.AreEqual(34, result); }
public void Add_20_and_10_40expected_30returned_test_fail() { MathsHelper helper = new MathsHelper(); int result = helper.Add(20, 10); Assert.AreEqual(40, result); }
public void MultiplicationTest() { MathsHelper helper = new MathsHelper(); int result = helper.Multiplication(20, 10); Assert.AreEqual(200, result); }
// Spawns the associated prefab public virtual void SpawnPrefab() { if (TargetInventory != null) { // if there's a prefab set for the item at this slot, we instantiate it at the specified offset if (Prefab != null && TargetInventory.TargetTransform != null) { GameObject droppedObject = (GameObject)Instantiate(Prefab); if (droppedObject.GetComponent <ItemPicker>() != null) { droppedObject.GetComponent <ItemPicker>().Quantity = Quantity; } // we randomize the drop position Vector3 randomDropDirection = UnityEngine.Random.insideUnitSphere; randomDropDirection.Normalize(); Vector3 randomDropDistance = MathsHelper.RandomVector3(PrefabDropMinDistance, PrefabDropMaxDistance); randomDropDirection = Vector3.Scale(randomDropDirection, randomDropDistance); if (SpawnShape == SpawnShapes.HalfCircle) { randomDropDirection.y = Mathf.Abs(randomDropDirection.y); } droppedObject.transform.position = TargetInventory.TargetTransform.position + randomDropDirection; } } }
/// <summary> /// Gets the particle. /// </summary> /// <returns> /// A new particle. /// </returns> protected override IParticle GetParticle() { // Determine which edge this particle should be set to. var verticalPosition = MathsHelper.Random((int)DrawingManager.BaseResolutionHeight); var position = Vector2.Zero; var velocity = Vector2.Zero; var size = MathsHelper.Random() > 50 ? ParticleEffectConstants.Medium : ParticleEffectConstants.Small; if (!this.flipOriginEdge) { // Start from the left edge. position = new Vector2(0f, verticalPosition); velocity = this.velocities[Direction.Right][MathsHelper.Random(this.velocities[Direction.Right].Count)]; this.flipOriginEdge = true; } else { // Start from the right edge. position = new Vector2(DrawingManager.BaseResolutionWidth - size, verticalPosition); velocity = this.velocities[Direction.Left][MathsHelper.Random(this.velocities[Direction.Left].Count)]; this.flipOriginEdge = false; } return(new Particle(null, position, velocity, 0f, 0f, Vector2.One, MathsHelper.Random(15, 60), new Rectangle(0, 0, size, size), recycle: this.Flags[ParticleEffectFlag.Recycle], fadeIn: false, fadeOut: true, trackParent: false, shrink: false) { Texture = TextureManager.GetColorTexture(this.Color) }); }
public void AddTest() { MathsHelper helper = new MathsHelper(); int result = helper.Add(20, 10); Assert.AreEqual(30, result); }
/// <summary> /// Get the angle of the road /// </summary> /// <param name="baseObject">The road to get the angle from</param> /// <returns>The angle of the road</returns> public float GetAngleOfRoad(Vector3 baseObject) { Vector3 endPosition = transform.position; Vector3 diff = endPosition - baseObject; return(MathsHelper.GetAngleFrom(diff.x, diff.z) - Mathf.PI / 2); }
/// <summary> /// Draw all the roads linked /// </summary> /// <param name="gameObject"></param> internal void DrawRoads(GameObject gameObject) { if (Roads == null) { return; } Vector3 roadCorner = gameObject.transform.position; for (int i = 0; i < Roads.Count; i++) { if (Roads[i] == null) { return; } Vector3 roadA = Roads[i].gameObject.transform.position; Gizmos.color = Color.yellow; if (Modified || Roads[i].Details.Modified) { Gizmos.color = Color.cyan; } Gizmos.DrawLine(roadA, roadCorner); float roadWidth = RoadConstructorHelper.CrossSectionDetails.RoadWidthValue / 2; Gizmos.color = Color.green; Vector3 intersectionDown = Roads[i].GetOffSetDownRoad(roadCorner, 0); float a = Roads[i].GetAngleOfRoad(roadCorner); Vector3 endA = MathsHelper.OffSetVector(intersectionDown, a + (Mathf.PI / 2), roadWidth); Vector3 endB = MathsHelper.OffSetVector(intersectionDown, a - (Mathf.PI / 2), roadWidth); Gizmos.DrawLine(endA, endB); } }
void Update() { float angleIncrease = Frequency * MathsHelper.TAU * Time.deltaTime; Angle += angleIncrease; Angle = MathsHelper.WrapAngle(Angle); value = Mathf.Sin(Angle) * Amplitude; }
private void RandomWanderTarget() { if (m_triggerableAI.GetTriggerArea() != null) { Collider2D triggerArea = m_triggerableAI.GetTriggerArea().GetComponent <Collider2D>(); m_wanderTarget = triggerArea.bounds.center; m_wanderTarget += MathsHelper.RandomWithNegativeVector2() * triggerArea.bounds.extents; } }
static void Main(string[] args) { MathsHelper calculator = new MathsHelper(); int r = calculator.Add(3, 7); int R = calculator.Subtract(r, -7); Console.WriteLine("3 + 7 = {0} 10 - 7 = {1}" + Environment.NewLine + "Press any key...", r, 8); Console.ReadKey(); }
public bool CheckComplete(Vector2f currentPosition) { if (MathsHelper.LineToPointDistance2D(LastWaypoint, currentPosition) < WaypointTolerance) { return(false); } return(true); }
/// <summary> /// Initializes the Engine Component. /// </summary> public override void Initialize() { // Aura has 2 horizontal directions. for (var i = 0; i < 5; i++) { var horizontalVelocity = MathsHelper.NextFloat(); this.velocities[Direction.Right].Add(new Vector2(horizontalVelocity, 0f)); this.velocities[Direction.Left].Add(new Vector2(-horizontalVelocity, 0f)); } }
/// <summary> /// Get the intersection of two points /// </summary> /// <param name="angleA">The first angle</param> /// <param name="angleB">The second angle</param> /// <param name="pointA">The first point</param> /// <param name="pointB">the second point</param> /// <param name="intersectionPoint">The intersection of the two angles</param> private static void GetPointFrom(float angleA, float angleB, Vector3 pointA, Vector3 pointB, out Vector3 intersectionPoint) { Vector3 offSetPointA = MathsHelper.OffSetVector(pointA, angleA - (float)(Math.PI / 2), 50); Vector3 offsetPointB = MathsHelper.OffSetVector(pointB, angleB - (float)(Math.PI / 2), 50); Vector3 outB = new Vector3(); Vector3 diffA = offSetPointA - pointA; Vector3 diffB = offsetPointB - pointB; MathsHelper.ClosestPointsOnTwoLines(out intersectionPoint, out outB, pointA, diffA.normalized, pointB, diffB.normalized); }
/// <summary> /// Gets the particle. /// </summary> /// <returns> /// A new particle. /// </returns> protected override IParticle GetParticle() { // Randomize this particle's lifespan. var lifespan = MathsHelper.Random(60, 300); return(new Particle(null, Vector2.Zero, velocities[MathsHelper.Random(this.velocities.Count)], 0f, 0f, Vector2.One, lifespan, new Rectangle(0, 0, ParticleEffectConstants.Small, ParticleEffectConstants.Small), recycle: this.Flags[ParticleEffectFlag.Recycle], fadeIn: false, fadeOut: true, trackParent: false, shrink: false) { Texture = TextureManager.GetColorTexture(this.Color) }); }
/// <summary> /// Get the angle of the road /// </summary> /// <param name="roadNetworkNode">The main node</param> /// <returns>The angle of the road</returns> private float GetAngleOfRoad(RoadNetworkNode rnn) { GameObject StartObj = _roadNetworkNode.gameObject; GameObject EndObj = rnn.gameObject; Vector3 startPosition = StartObj.transform.position; Vector3 endPosition = EndObj.transform.position; Vector3 diff = startPosition - endPosition; return(MathsHelper.GetAngleFrom(diff.x, diff.z)); }
/// <summary> /// Get the angle of the road /// </summary> /// <param name="roadNetworkNode">The main node</param> /// <param name="index">Index of the road</param> /// <returns>The angle of the road</returns> public static float GetAngleOfRoadClampped(RoadNetworkNode roadNetworkNode, int index) { GameObject StartObj = roadNetworkNode.gameObject; GameObject EndObj = roadNetworkNode.Details.Roads[index].gameObject; Vector3 startPosition = StartObj.transform.position; Vector3 endPosition = EndObj.transform.position; Vector3 diff = startPosition - endPosition; return(MathsHelper.ClampAngle(MathsHelper.GetAngleFrom(diff.x, diff.z))); }
/// <summary> /// Get the best angle from all the roads /// </summary> /// <returns>The best angle</returns> private float GetCurrentAngle() { if (Details.Union == UNION_TYPE.NONE) { return(0); } Vector3 pos = Details.Roads[0].transform.position - transform.position; return(MathsHelper.GetAngleFrom(pos.x, pos.z)); }
public void Add_20_10_returned_30() { int a = 20; int b = 10; int expected = 30; MathsHelper mathHelper = new MathsHelper(); int result = mathHelper.Add(a, b); Assert.AreEqual(result, expected); }
public void Subtract_20_10_returned_10() { int a = 20; int b = 10; int expected = 10; MathsHelper mathHelper = new MathsHelper(); int result = mathHelper.Subtract(a, b); Assert.AreEqual(expected, result); }
public static void Main() { try { MathsHelper helper = new MathsHelper(); Console.WriteLine(helper.Add(10, 20)); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public void SubtractTest() { MathsHelper helper = new MathsHelper(); int result = helper.Subtract(20, 10); Assert.AreEqual(20, result); }