static void Main(string[] args) { Console.WriteLine($"Track this IP!!! {IPTracker.TrackIpAddress()} \r\n"); Console.WriteLine($"Sum: {MathStuff.add(2, 3)}"); Console.WriteLine($"Diff: {MathStuff.subtract(2, 3)}"); Console.ReadLine(); }
// Static method Main is the entry point method. public static void Main() { MathStuff myMathStuff = new MathStuff(); Console.WriteLine("Sqaring 5"); myMathStuff.SquareIt(5); }
void Update() { if (target != null) { transform.position = MathStuff.Damp(transform.position, target.position, .1f); } }
void Update() { targetRotation = Quaternion.Euler(0, 0, 270 + MathStuff.GetRotationToLook(spriteTransfom.position, pointToLook)); actualRotation = Quaternion.Lerp(actualRotation, targetRotation, rotationSpeed * Time.deltaTime); spriteTransfom.rotation = actualRotation; }
private void EasePositionRotationScale() { float percentRemainingAfter1Second = .001f; //rt.localRotation = MathStuff.Damp(transform.localRotation, targetRotation, percentRemainingAfter1Second); rt.anchoredPosition = MathStuff.Damp(rt.anchoredPosition, targetPosition, percentRemainingAfter1Second); transform.localScale = Vector3.one * MathStuff.Damp(transform.localScale.x, targetScale, percentRemainingAfter1Second); }
void Shoot() { GameObject b = WeaponManager.instance.projectilePools[ammoType].getPooledObject(); b.transform.position = transform.position; b.transform.rotation = Quaternion.Euler(0, 0, 180 + MathStuff.GetRotationToLook(b.transform.position, (Vector2)transform.position + InputManager.instance.GetAimDirection())); b.transform.Translate(Vector3.right * 0.5f, Space.Self); b.GetComponent <Rigidbody2D> ().velocity = b.transform.up * 30f; b.GetComponent <Projectile> ().Reset(); WeaponManager.instance.fireEvent.Invoke(); }
protected override void DoUpdate(float deltaT) { _particleShape.Position = Position; if (RotationType == ParticleManager.ParticleRotationType.PRT_Velocity) { _particleShape.Rotation = (float)MathStuff.RadianToDegree(Math.Atan(Velocity.Y / Velocity.X)) * RotationSpeedFactor; } else if (RotationType == ParticleManager.ParticleRotationType.PRT_Const) { _particleShape.Rotation += deltaT * RotationSpeedFactor; } }
//////////////////////////////////////////////// //void OpponentSequence() // //Randomizes the opponents for arcade mode // //Last three opponents will always be the same// //////////////////////////////////////////////// public void OpponentSequence() { Opponents[7] = -1; Opponents[8] = -2; Opponents[9] = -3; int[] temp = new int[] { 0, 1, 2, 3, 4, 5, 6 }; temp = MathStuff.Shuffle(temp); for (int i = 0; i < temp.Length; i++) { Opponents[i] = temp[i]; } }
void PositionCardsInspect() { float dx = 150; float x = -dx * (cards.Count - 1) / 2f; for (int i = 0; i < cards.Count; i++) { float percent = cards.Count == 1 ? .5f : i / (float)(cards.Count - 1); float y = Mathf.Sin(percent * 40) * 25; y -= Mathf.Abs(.5f - percent) * 75 + 25; Vector3 pos = new Vector2(x + dx * i, y); float roll = MathStuff.Lerp(20, -20, percent); Quaternion rot = Quaternion.Euler(0, 0, roll); cards[i].AnimateTo(pos, rot, cardScaleBig, i * .1f); cards[i].transform.SetParent(transform); } }
public void UpdateModel() { // rotate the suspension to align with provided rotation: suspension.position = transform.position; // make the model follow the hamster wheel! ////////////////////// NOTE: If suspension is a child of the veichle do we need thi? suspension.rotation = Quaternion.RotateTowards(suspension.rotation, state.suspensionOrientation, state.suspensionRotateSpeed * Time.fixedDeltaTime); // rotate the car model to align with velocity: if (model) { Vector3 vel = ballBody.velocity; float turn = Mathf.Atan2(vel.x, vel.z) * Mathf.Rad2Deg; MathStuff.Spring(ref valModelTurnX, ref velModelTurnX, turn, 0.9f, 20, Time.fixedDeltaTime); model.localEulerAngles = new Vector3(0, valModelTurnX, 0); } }
void FixedUpdate() { if (target) { // move the camera-target towards the target car's position: float distanceAboveCar = 1; transform.position = MathStuff.Damp(transform.position, target.transform.position + new Vector3(0, distanceAboveCar, 0), 0f, Time.fixedDeltaTime); // calculate a distanceMultiplier from velocity float p = 1; if (target.ballBody) { p = Mathf.Clamp(target.ballBody.velocity.z / maxSpeed, 0, 1); } if (target && target.boost && target.boost.isBoosting) { p = 1; } p = Mathf.Clamp(p, 0, 1); p = cameraDistanceCurve.Evaluate(p); cameraDistance = Mathf.Lerp(cameraDistanceMin, cameraDistanceMax, p); cameraDistance = Mathf.Lerp(cameraDistance, cameraDistance * 4, target.driver.wantsToAim?1:0); cameraAngle = Mathf.Lerp(cameraAngleMin, cameraAngleMax, p); // CAMERA SHAKE: cameraPitch = 30; if (target && target.boost && target.boost.isBoosting) { float amp = 10 * target.ballBody.velocity.z / maxSpeed; cameraPitch += Random.Range(-amp, amp); } } if (cam) // zoom camera in or out: { Vector3 localPositionTarget = new Vector3(0, 0, -cameraDistance); cam.transform.localPosition = MathStuff.Damp(cam.transform.localPosition, localPositionTarget, .1f, Time.fixedDeltaTime); pitchControl.localRotation = MathStuff.Damp(pitchControl.localRotation, Quaternion.Euler(cameraPitch, 0, 0), .1f, Time.fixedDeltaTime); cam.fieldOfView = MathStuff.Damp(cam.fieldOfView, cameraAngle, .5f, Time.fixedDeltaTime); } }
public static void Main(String[] args) { Double p, r, n, t; Console.WriteLine("Enter p:"); double.TryParse(Console.ReadLine(), out p); Console.WriteLine("Enter r:"); double.TryParse(Console.ReadLine(), out r); Console.WriteLine("Enter n:"); double.TryParse(Console.ReadLine(), out n); Console.WriteLine("Enter t:"); double.TryParse(Console.ReadLine(), out t); MathStuff calc = new MathStuff(p, r, n, t); Console.WriteLine(calc.Calculate()); }
void Update() { if (Game.isPaused) { return; } if (cooldownBeforeAttacking > 0) { cooldownBeforeAttacking -= Time.deltaTime; } else if (wantsToAttack) { Attack(); } transform.rotation = MathStuff.Damp(transform.rotation, lookDirection, rotationDampening); if (CurrentTome().updatedSinceLastRecalcPawnValues) { RecalculateValuesFromTome(); } }
/////////////////////////////////////////////////////// //IEnumerator GarbageHandler() // //Handles incoming garbage blocks. // //Will apply no more than 7 garbage blocks per cycle.// /////////////////////////////////////////////////////// private IEnumerator GarbageHandler() { if (garbageType == 0) { bool[] temp = new bool[7]; int drop = 0; if (garbage >= 7) { drop = 7; garbage -= 7; } else { drop = garbage; garbage = 0; } for (int i = 0; i < drop; i++) { temp[i] = true; } MathStuff.Shuffle(temp); for (int i = 0; i < temp.Length; i++) { if (temp[i]) { GameObject block = Instantiate(MasterController.Blocks[4], new Vector3(-3 + i, 6, 0), Quaternion.identity); block.GetComponent <BlockBehavior>().playerBlock = true; bool isFalling = block.GetComponent <BlockBehavior>().fall(); if (isFalling) { numFalling++; fallStack.Push(block); } } } while (numFalling > 0) { yield return(null); } while (fallStack.Count > 0) { GameObject tempObj = (GameObject)fallStack.Pop(); int new_x = (int)tempObj.transform.position.x + x_correct; int new_y = (int)tempObj.transform.position.y + y_correct; board[new_x, new_y] = tempObj; } } else if (garbageType == 1) { int drop = 0; if (garbage >= 7) { drop = 7; garbage -= 7; } else { drop = garbage; garbage = 0; } Stack tempStack = new Stack(); for (int i = 0; i < board_h; i++) { for (int k = 0; k < board_w; k++) { if (board[k, i] != null && (board[k, i].tag.Equals("Block_Atk") || board[k, i].tag.Equals("Block_Con"))) { tempStack.Push(board[k, i]); } } } if (tempStack.Count < drop) { drop = tempStack.Count; } GameObject[] temp = new GameObject[tempStack.Count]; for (int i = 0; i < temp.Length; i++) { temp[i] = (GameObject)tempStack.Pop(); } MathStuff.Shuffle(temp); for (int i = 0; i < drop; i++) { GameObject tempObj = Instantiate(MasterController.Blocks[4], temp[i].transform.position, Quaternion.identity);; tempObj.GetComponent <BlockBehavior>().playerBlock = true; int new_x = (int)tempObj.transform.position.x + x_correct; int new_y = (int)tempObj.transform.position.y + y_correct; board[new_x, new_y] = tempObj; Destroy(temp[i]); } } else if (garbageType == 2) { int drop = 0; if (garbage >= 7) { drop = 7; garbage -= 7; } else { drop = garbage; garbage = 0; } Stack tempStack = new Stack(); for (int i = 0; i < board_h; i++) { for (int k = 0; k < board_w; k++) { if (board[k, i] != null && (board[k, i].tag.Equals("Block_Mag") || board[k, i].tag.Equals("Block_Sup"))) { tempStack.Push(board[k, i]); } } } if (tempStack.Count < drop) { drop = tempStack.Count; } GameObject[] temp = new GameObject[tempStack.Count]; for (int i = 0; i < temp.Length; i++) { temp[i] = (GameObject)tempStack.Pop(); } MathStuff.Shuffle(temp); for (int i = 0; i < drop; i++) { GameObject tempObj = Instantiate(MasterController.Blocks[4], temp[i].transform.position, Quaternion.identity);; tempObj.GetComponent <BlockBehavior>().playerBlock = true; int new_x = (int)tempObj.transform.position.x + x_correct; int new_y = (int)tempObj.transform.position.y + y_correct; board[new_x, new_y] = tempObj; Destroy(temp[i]); } } yield return(new WaitForSeconds(0.5f)); }
private void Tick() { var status = new MissileStatus() { Position = this.Position, State = state, DistToTarget = (this.Target - this.Position).Length(), }; status.ExtraData.AppendLine($"DeltaTime: {(DateTime.Now - launchTime).TotalSeconds:F2} seconds"); status.ExtraData.AppendLine($"Distance from launch position: {(this.Position - this.launchPos).Length():F2}"); if (state == LaunchState.Separation) { if ((this.Position - this.launchPos).LengthSquared() >= downSeparationRange * downSeparationRange) { LogLine($"Separation phase finished, transitioning to boost phase"); foreach (var thrust in downThrusters) { thrust.ThrustOverridePercentage = 0; } foreach (var thrust in fwdThrusters) { thrust.Enabled = true; thrust.ThrustOverridePercentage = 1; } this.state = LaunchState.Boost; } } else if (state == LaunchState.Boost) { if ((this.Position - this.launchPos).LengthSquared() >= boostManeuverRange * boostManeuverRange) { LogLine($"Boost phase finished, transitioning to parabolic flight mode"); this.state = LaunchState.Flight; foreach (var gyro in gyros) { gyro.Enabled = true; } this.enginesActive = false; Vector3D planet = Vector3D.Zero; if (!remote.TryGetPlanetPosition(out planet)) { LogLine("Couldn't find planet!"); } LogLine($"Generating parabolic trajectory"); this.trajectory = GenerateTrajectory(this.Position, this.finalTarget.Coords, 10, planet); this.trajectoryStage = 0; this.state = LaunchState.Flight; // temporarily stop forward thrust in order to allow missile to align to target foreach (var thruster in fwdThrusters) { thruster.ThrustOverride = 0; } } } else if (state == LaunchState.Flight) { double pitch, yaw, roll; var desiredFwdVec = Vector3D.Normalize(Target - Position); MathStuff.GetRotationAngles(desiredFwdVec, Vector3D.Zero, remote.WorldMatrix, out pitch, out yaw, out roll); status.DistToTarget = (Target - Position).Length(); status.Pitch = pitch; status.Yaw = yaw; status.Roll = roll; if (!this.enginesActive && (Math.Abs(pitch) < MIN_ANGLE_FOR_ENGINE_RESTART || Math.Abs(yaw) < MIN_ANGLE_FOR_ENGINE_RESTART || Math.Abs(roll) < MIN_ANGLE_FOR_ENGINE_RESTART)) { foreach (var thrust in fwdThrusters) { thrust.ThrustOverridePercentage = 1; } this.enginesActive = true; } var pitchCorrection = pitchPID.GetCorrection(pitch, PID_TIME_DELTA); var yawCorrection = yawPID.GetCorrection(yaw, PID_TIME_DELTA); var rollCorrection = rollPID.GetCorrection(roll, PID_TIME_DELTA); status.ExtraData.Append($"PID:\nPitchCorrection: {MathHelperD.ToDegrees(pitchCorrection):F2}\n" + $"YawCorrection: {MathHelperD.ToDegrees(yawCorrection):F2}\n" + $"RollCorrection: {MathHelperD.ToDegrees(rollCorrection):F2}\n"); if (applyGyro) { MathStuff.ApplyGyroOverride(pitchCorrection, yawCorrection, rollCorrection, this.gyros, this.remote.WorldMatrix); } if ((this.Position - Target).LengthSquared() <= SWITCH_WAY_POINT_DISTANCE * SWITCH_WAY_POINT_DISTANCE) { this.trajectoryStage++; } if (this.trajectoryStage >= this.trajectory.Count || (this.Position - finalTarget.Coords).LengthSquared() <= this.armDistance * this.armDistance) { ArmMissile(); this.trajectoryStage++; this.state = LaunchState.Terminal; } } else if (state == LaunchState.Terminal) { if ((this.Position - finalTarget.Coords).LengthSquared() <= blowDistance * blowDistance) { LogLine("Reached detonation threshold. Detonating and disabling script."); LogStatus("Detonated."); Detonate(); } } status.State = this.state; LogStatus(status.ToString()); }
private Vector3 DecelerateHorizontal(Vector3 velocity) { velocity.x = MathStuff.Damp(velocity.x, .01f, Time.fixedDeltaTime); return(velocity); }
public void CheckThatAddWorks(int x, int y, int expected) { var sut = new MathStuff(); var result = sut.Add(x, y); Assert.That(result,Is.EqualTo(expected)); }