/** * Gets the biggest distance component (x or y) between the two given tiles. * Also known as L-Infinity-Norm. * @param t0 the start tile * @param t1 the end tile * @return the distance */ public static uint DistanceMax(TileIndex t0, TileIndex t1) { uint dx = MathFuncs.Delta(TileX(t0), TileX(t1)); uint dy = MathFuncs.Delta(TileY(t0), TileY(t1)); return(Math.Max(dx, dy)); }
/** * Gets the biggest distance component (x or y) between the two given tiles * plus the Manhattan distance, i.e. two times the biggest distance component * and once the smallest component. * @param t0 the start tile * @param t1 the end tile * @return the distance */ public static uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1) { uint dx = (uint)MathFuncs.Delta(TileX(t0), TileX(t1)); uint dy = (uint)MathFuncs.Delta(TileY(t0), TileY(t1)); return(dx > dy ? 2 * dx + dy : 2 * dy + dx); }
/// <summary> /// by accelerometer input x set angle of camera quateration and arms of player character /// </summary> void FixedUpdate() { float accelerationValue = (Input.acceleration.x * accelerometerInputMultiplier) + 1; #if UNITY_EDITOR if (Input.GetJoystickNames().Length > 0) { accelerationValue = -1 * Input.GetAxis("Vertical2") + 1; } else { if (Input.GetAxis("Vertical") != 0) { accelerationValue = Input.GetAxis("Vertical") + 1; } } if (instantValue != -0.01f) { accelerationValue = instantValue; } #endif float angle = 90 - (float)Math.Round((float)MathFuncs.equationX(accelerationValue, 2, 180), 0); angle *= 2; angle = MathFuncs.forks(angle, 180, -180); angle = MathFuncs.getValueInRange(angle, -90, 90); float currentAngle = transform.rotation.eulerAngles.z; currentAngle = MathFuncs.forks(currentAngle, 180, -180); float angleStep = (angle - currentAngle) / 15; float targetAngle = currentAngle + angleStep; transform.rotation = Quaternion.Euler(new Vector3(0, 0, targetAngle)); playerController.setArms(targetAngle); }
/** * Gets the Manhattan distance between the two given tiles. * The Manhattan distance is the sum of the delta of both the * X and Y component. * Also known as L1-Norm * @param t0 the start tile * @param t1 the end tile * @return the distance */ public static uint DistanceManhattan(TileIndex t0, TileIndex t1) { var dx = (uint)MathFuncs.Delta(TileX(t0), TileX(t1)); var dy = (uint)MathFuncs.Delta(TileY(t0), TileY(t1)); return(dx + dy); }
static private Random random_obj = new Random();// helping for making a random order // Make the tree and tables function static public List <double> normalizeData(List <double> raw_data, int data_len, int N_LENGTH) { List <double> norm_data; norm_data = MathFuncs.zScoreNorm(raw_data, raw_data.Count); return(norm_data); }
/** * Scales the given value by the maps circumference, where the given * value is for a 256 by 256 map * @param n the value to scale * @return the scaled size */ //inline public static uint ScaleByMapSize1D(uint n) { /* Normal circumference for the X+Y is 256+256 = 1<<9 * Note, not actually taking the full circumference into account, * just half of it. */ return(MathFuncs.CeilDiv((n << (int)MapLogX()) + (n << (int)MapLogY()), 1 << 9)); }
/// <summary> /// Update all player informations: hp,mana,xp,position,etc... /// </summary> public static void UpdatePlayer() { if (_gstatus != GameStatuses.INITIALIZED) { return; } if (PlayerUpdate != null) { PlayerUpdate(); } //update last player location Player.LastLocation = Player.Location; if (PlayerWayPoint != null) { Vector3D current = Player.Location; WayPoint wpLast = (WayPointManager.Instance.NormalNodeCount > 0) ? WayPointManager.Instance.NormalPath[WayPointManager.Instance.NormalPath.Count - 1] : null; if (wpLast != null && MathFuncs.GetDistance(current, wpLast.Location, false) > 5 || wpLast == null) { PlayerWayPoint(current); } } }
protected override void DoExecute(WowPlayer Entity) { //on execute, first verify we have a waypoit to follow, else exit if (CurrentWaypoint == null) { Exit(Entity); return; } // Move on... float distance = MathFuncs.GetDistance(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint), Entity.Location, false); if (Math.Abs(distance - LastDistance) < 1.0) { TravelPath = null; // TODO: Fix the stuck detection code //Entity.Unstuck(); } /// We face our destination waypoint while we are already moving, so that it looks /// more human-like //float angle = MathFuncs.GetFaceRadian(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint), // Entity.Location); Output.Instance.Script(string.Format("Entity Location: X:{0} Y:{1} Z:{2}", Entity.Location.X, Entity.Location.Y, Entity.Location.Z), this); Output.Instance.Script(string.Format("Path Waypoint: X:{0} Y:{1} Z:{2}", CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z), this); //Entity.FaceUsingMemoryWrite(angle, true); Output.Instance.Script(string.Format("First ClickToMove(X:{0} Y:{1} Z:{2})", CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z), this); Entity.ClickToMove(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint)); Finish(Entity); Exit(Entity); }
/// <summary> /// rotate to down on death /// </summary> void deadRotate() { if (Mathf.Abs(MathFuncs.forks(transform.rotation.eulerAngles.z, 180, -180)) < 90) { transform.Rotate(Vector3.forward * Time.deltaTime * -100 * directionForward); } }
public static void HandleCombat() { //draw firing cones from guns for (int i = 0; i < objs.Count; i++) { Obj o = objs[i]; if (o.range > 0 && o.attachedTo != -1) //Is a gun, and is attached to a unit { Vector3 origin; Vector3 ang; Vector3 leftPos; Vector3 rightPos; Vector3 centerPos; origin = o.go.transform.position; ang = o.go.transform.eulerAngles; centerPos = MathFuncs.ProjectVec(origin, ang, o.range, Vector3.forward); leftPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y + o.firingConeAngle, ang.z), o.range, Vector3.forward); rightPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y - o.firingConeAngle, ang.z), o.range, Vector3.forward); Effects.DrawLine(origin, leftPos, 0.1f, Effects.Colors.White); Effects.DrawLine(leftPos, centerPos, 0.1f, Effects.Colors.White); Effects.DrawLine(centerPos, rightPos, 0.1f, Effects.Colors.White); Effects.DrawLine(rightPos, origin, 0.1f, Effects.Colors.White); } } }
/** * Find file information of a file by its name from the file list. * @param file The filename to return information about. Can be the actual name * or a numbered entry into the filename list. * @return The information on the file, or \c NULL if the file is not available. */ public FiosItem FindItem(string file) { foreach (var item in files) { if (file == item.name || file == item.title) { return(item); } } /* If no name matches, try to parse it as number */ if (int.TryParse(file, out var i) && MathFuncs.IsInsideMM(i, 0, (uint)this.files.Count)) { return(this[i]); } /* As a last effort assume it is an OpenTTD savegame and * that the ".sav" part was not given. */ var long_file = file + ".sav"; foreach (var item in files) { if (long_file == item.name || long_file == item.title) { return(item); } } return(null); }
/** * Finds the distance for the closest tile with water/land given a tile * @param tile the tile to find the distance too * @param water whether to find water or land * @return distance to nearest water (max 0x7F) / land (max 0x1FF; 0x200 if there is no land) */ uint GetClosestWaterDistance(TileIndex tile, bool water) { if (WaterMap.HasTileWaterGround(tile) == water) { return(0); } uint max_dist = (uint)(water ? 0x7F : 0x200); int x = (int)TileX(tile); int y = (int)TileY(tile); uint max_x = MapMaxX(); uint max_y = MapMaxY(); uint min_xy = (uint)(_settings_game.construction.freeform_edges ? 1 : 0); /* go in a 'spiral' with increasing manhattan distance in each iteration */ for (uint dist = 1; dist < max_dist; dist++) { /* next 'diameter' */ y--; /* going counter-clockwise around this square */ for (var dir = (int)DiagDirection.DIAGDIR_BEGIN; dir < (int)DiagDirection.DIAGDIR_END; dir++) { int dx = ddx[dir]; int dy = ddy[dir]; /* each side of this square has length 'dist' */ for (uint a = 0; a < dist; a++) { /* MP_VOID tiles are not checked (interval is [min; max) for IsInsideMM())*/ if (MathFuncs.IsInsideMM(x, min_xy, max_x) && MathFuncs.IsInsideMM(y, min_xy, max_y)) { TileIndex t = TileXY((uint)x, (uint)y); if (WaterMap.HasTileWaterGround(t) == water) { return(dist); } } x += dx; y += dy; } } } if (!water) { /* no land found - is this a water-only map? */ for (TileIndex t = 0; t < MapSize(); t++) { if (!TileMap.IsTileType(t, TileType.MP_VOID) && !TileMap.IsTileType(t, TileType.MP_WATER)) { return(0x1FF); } } } return(max_dist); }
public static void DrawText(string text, int x, int y) { SolidColorBrush dBrushBack = new SolidColorBrush(Device, Color.FromArgb(1, 1, 1).toRawColor4()); SolidColorBrush dBrush = new SolidColorBrush(Device, Settings.userSettings.VisualColors.World_Text.toRawColor4()); if (text == "Darc Euphoria") { if (_RED_TO_GREEN > 510) { dBrush.Color = Color.FromArgb(_RED_TO_GREEN - 510, 255 - (_RED_TO_GREEN - 510), 0).toRawColor4(); } else if (_RED_TO_GREEN > 255) { dBrush.Color = Color.FromArgb(0, _RED_TO_GREEN - 255, 255 - (_RED_TO_GREEN - 255)).toRawColor4(); } else { dBrush.Color = Color.FromArgb(255 - _RED_TO_GREEN, 0, _RED_TO_GREEN).toRawColor4(); } } else { Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x - 1, y), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x + 1, y), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y - 1), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y + 1), dBrushBack); } Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y), dBrush); dBrushBack.Dispose(); dBrush.Dispose(); }
void FixedUpdate() { if (!MathFuncs.isValueInRange(gameObject.transform.position.y, cameraTransform.position.y - 70, cameraTransform.position.y + 70) || !MathFuncs.isValueInRange(gameObject.transform.position.x, cameraTransform.position.x - 70, cameraTransform.position.x + 70)) { DestroyObject(); } }
internal static bool TargetAligned(Weapon weapon, Target target, out Vector3D targetPos) { Vector3 targetLinVel = Vector3.Zero; Vector3 targetAccel = Vector3.Zero; var targetCenter = weapon.Comp.TrackReticle ? weapon.Comp.Ai.DummyTarget.Position : target.Projectile?.Position ?? target.Entity.PositionComp.WorldAABB.Center; var needsPrediction = weapon.System.Prediction != Prediction.Off && (!weapon.ActiveAmmoDef.AmmoDef.Const.IsBeamWeapon && weapon.ActiveAmmoDef.AmmoDef.Const.DesiredProjectileSpeed > 0); if (needsPrediction) { if (weapon.Comp.TrackReticle) { targetLinVel = weapon.Comp.Ai.DummyTarget.LinearVelocity; targetAccel = weapon.Comp.Ai.DummyTarget.Acceleration; } else { var topMostEnt = target.Entity?.GetTopMostParent(); if (target.Projectile != null) { targetLinVel = target.Projectile.Velocity; targetAccel = target.Projectile.AccelVelocity; } else if (topMostEnt?.Physics != null) { targetLinVel = topMostEnt.Physics.LinearVelocity; targetAccel = topMostEnt.Physics.LinearAcceleration; } } if (Vector3D.IsZero(targetLinVel, 5E-03)) { targetLinVel = Vector3.Zero; } if (Vector3D.IsZero(targetAccel, 5E-03)) { targetAccel = Vector3.Zero; } targetPos = weapon.GetPredictedTargetPosition(targetCenter, targetLinVel, targetAccel); } else { targetPos = targetCenter; } var targetDir = targetPos - weapon.MyPivotPos; double rangeToTarget; Vector3D.DistanceSquared(ref targetPos, ref weapon.MyPivotPos, out rangeToTarget); var inRange = rangeToTarget <= weapon.MaxTargetDistanceSqr; var isAligned = (inRange || weapon.Comp.TrackReticle) && MathFuncs.IsDotProductWithinTolerance(ref weapon.MyPivotDir, ref targetDir, weapon.AimingTolerance); weapon.Target.TargetPos = targetPos; weapon.Target.IsAligned = isAligned; return(isAligned); }
/// <summary> /// set size of box collider depending on visible part of monster /// </summary> void setBoxColliderSize() { // 0 - h = 1.1, y = 0.25 // -0.78 h = 0.1, y = 0.3 // -0.875 h = 0, y = 0.39 float h = MathFuncs.equationX(0.875f + transform.localPosition.y, 0.875f, 1.1f); float y = -0.25f + MathFuncs.equationX(-transform.localPosition.y, 0.875f, 0.64f); boxCol.size = new Vector2(boxCol.size.x, h); boxCol.offset = new Vector2(boxCol.offset.x, y); }
private void acf_function() { List <double> data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); int data_len = data_to_calc_w.Count; int period_max = Convert.ToInt16(txt_period_max.Text); //normalize data: List <double> norm_data = MathFuncs.zScoreNorm(data_to_calc_w, data_len); ACF_Form form3 = new ACF_Form(this, norm_data, 1, period_max); //txt_period.Text = period.ToString(); }
protected override void DoExecute(WowPlayer Entity) { //if it has been more then/equal to 5 seconds since the last jump attempt, then test if (DateTime.Now.Subtract(_LastJumpCheck).TotalSeconds >= 5) { _LastJumpCheck = DateTime.Now; //if two random numbers between 1 and 5 equal each other then jump if (MathFuncs.RandomNumber(1, 5) == MathFuncs.RandomNumber(1, 5)) { Entity.PlayerCM.SendKeys(" "); } } }
/// <summary> /// We are roaming through the waypoints with nothing else to do /// </summary> protected override void DoExecute(WowPlayer entity) { WayPoint wp = null; Output.Instance.Script("Checking if we have a last waypoint defined", this); if (LastWayPoint != null) { Output.Instance.Script("We have a last waypoint. Checking if we reached it", this); float distanceFromLast = MathFuncs.GetDistance(LastWayPoint.Location, entity.Location, false); if (distanceFromLast <= 3.0f) { Output.Instance.Script("We reached the last waypoint. Let's get a new one", this); wp = WayPointManager.Instance.GetNextWayPoint(WayPointType.Normal); } else { Output.Instance.Script("We still need to reach the last waypoint. We reuse the last one.", this); wp = LastWayPoint; } } else { Output.Instance.Script("This is the first waypoint. We try to get a new one.", this); wp = WayPointManager.Instance.GetNextWayPoint(WayPointType.Normal); } // Id we do have a waypoint we actually move if (wp != null) { LastWayPoint = wp; Output.Instance.Script(string.Format("Moving to waypoint. Index:{0}", WayPointManager.Instance.CurrentNormalWayPointIndex), this); Output.Instance.Script(string.Format("WayPoint: X:{0} Y:{1} Z:{2}", wp.Location.X, wp.Location.Y, wp.Location.Z), this); //MoveTo(wp.Location); float distance = MathFuncs.GetDistance(wp.Location, entity.Location, false); if (distance > 3.0f) { var mtsTarget = new MoveToState(wp.Location, 3.0f); //request that we move to this location CallChangeStateEvent(entity, mtsTarget, true, false); return; } } else { Output.Instance.Script("We are supposed to walk through waypoints but there's no waypoints defined", this); } }
/* Check whether a point is within a cone */ public static bool CheckCone(float maxDist, float width, float angle, Vector3 coneOrigin, Vector3 pos, bool flattenToXZ) { //A unity-centric attempt at this function. if (Vector2.Distance(coneOrigin, pos) <= maxDist || maxDist == -1) //First, is it within the dist and/or is there no dist? { float angDirectlyToPos = MathFuncs.ReturnAngleTowardsVec(coneOrigin, pos, flattenToXZ); float diff = Mathf.Abs(Mathf.DeltaAngle(angDirectlyToPos, angle)); if (diff <= width) { return(true); } } return(false); }
protected override void DoExecute(BabBot.Wow.WowPlayer Entity) { //for this basic test script... lets have a 1 in 5 chance of jumping every 5 seconds. //if it has been more then/equal to 5 seconds since the last jump attempt, then test if (DateTime.Now.Subtract(_LastJumpCheck).TotalSeconds >= 5) { _LastJumpCheck = DateTime.Now; //if two random numbers between 1 and 5 equal each other then jump if (MathFuncs.RandomNumber(1, 5) == MathFuncs.RandomNumber(1, 5)) { Entity.PlayerCM.SendKeys(" "); } } }
/// <summary> /// refresh state of hourglass /// </summary> /// <returns>return time left to end counting, if lower than zero is time which expired after finnish</returns> public float refresh() { float spentTime = Time.time - timeStart; float valueTopSand = MathFuncs.equationX(spentTime, time, 1); if (valueTopSand > 1) { valueTopSand = 1; } topSand.size = 1 - valueTopSand; botSand.size = valueTopSand; fallingSand.size = 1 - valueTopSand; topSand.value = 0; botSand.value = 0; fallingSand.value = 0; return(time - spentTime); }
internal static bool CanShootTarget(Weapon weapon, ref Vector3D targetCenter, Vector3D targetLinVel, Vector3D targetAccel, out Vector3D targetPos) { var prediction = weapon.System.Values.HardPoint.AimLeadingPrediction; var trackingWeapon = weapon.TurretMode ? weapon : weapon.Comp.TrackingWeapon; if (Vector3D.IsZero(targetLinVel, 5E-03)) { targetLinVel = Vector3.Zero; } if (Vector3D.IsZero(targetAccel, 5E-03)) { targetAccel = Vector3.Zero; } var validEstimate = true; if (prediction != Prediction.Off && !weapon.ActiveAmmoDef.AmmoDef.Const.IsBeamWeapon && weapon.ActiveAmmoDef.AmmoDef.Const.DesiredProjectileSpeed > 0) { targetPos = TrajectoryEstimation(weapon, targetCenter, targetLinVel, targetAccel, out validEstimate); } else { targetPos = targetCenter; } var targetDir = targetPos - weapon.MyPivotPos; double rangeToTarget; Vector3D.DistanceSquared(ref targetPos, ref weapon.MyPivotPos, out rangeToTarget); var inRange = rangeToTarget <= weapon.MaxTargetDistanceSqr && rangeToTarget >= weapon.MinTargetDistanceSqr; bool canTrack; bool isTracking; if (weapon == trackingWeapon) { canTrack = validEstimate && MathFuncs.WeaponLookAt(weapon, ref targetDir, rangeToTarget, false, true, out isTracking); } else { canTrack = validEstimate && MathFuncs.IsDotProductWithinTolerance(ref weapon.MyPivotDir, ref targetDir, weapon.AimingTolerance); } return((inRange && canTrack) || weapon.Comp.Data.Repo.Base.State.TrackingReticle); }
private void radar_Paint(object sender, PaintEventArgs e) { center = new Point(radar.Width / 2, radar.Height / 2); using (var p = new Pen(Color.FromArgb(50, 50, 50))) { e.Graphics.DrawLine(p, radar.Width / 2, 0, radar.Width / 2, radar.Height); e.Graphics.DrawLine(p, 0, radar.Height / 2, radar.Width, radar.Height / 2); } if (!Local.InGame) { return; } try { foreach (var player in EntityList.List) { if (player.Dormant) { continue; } if (player.Health <= 0) { continue; } var dist = MathFuncs.LocationToPlayer(Local.Position, player.Position) * (float)Settings.userSettings.MiscSettings.RadarZoom; dist.x += center.X; dist.y += center.Y; Brush b = player.Team == Local.Team ? new SolidBrush(Color.Green) : new SolidBrush(Color.Red); var coord = RotatePoint( new Point((int)dist.y, (int)dist.x), Local.ViewAngle.x); e.Graphics.FillRectangle(b, coord.X - 2, coord.Y - 2, 5, 5); b.Dispose(); } } catch { } }
internal void AddProjectileTargets() // This calls AI late for fragments need to fix { for (int i = 0; i < AddTargets.Count; i++) { var p = AddTargets[i]; for (int t = 0; t < p.Info.Ai.TargetAis.Count; t++) { var targetAi = p.Info.Ai.TargetAis[t]; var addProjectile = p.Info.AmmoDef.Trajectory.Guidance != GuidanceType.None && targetAi.PointDefense; if (!addProjectile && targetAi.PointDefense) { if (Vector3.Dot(p.Info.Direction, p.Info.Origin - targetAi.MyGrid.PositionComp.WorldMatrixRef.Translation) < 0) { var targetSphere = targetAi.MyGrid.PositionComp.WorldVolume; targetSphere.Radius *= 3; var testRay = new RayD(p.Info.Origin, p.Info.Direction); var quickCheck = Vector3D.IsZero(targetAi.GridVel, 0.025) && targetSphere.Intersects(testRay) != null; if (!quickCheck) { var deltaPos = targetSphere.Center - p.Info.Origin; var deltaVel = targetAi.GridVel - p.Info.Ai.GridVel; var timeToIntercept = MathFuncs.Intercept(deltaPos, deltaVel, p.Info.AmmoDef.Const.DesiredProjectileSpeed); var predictedPos = targetSphere.Center + (float)timeToIntercept * deltaVel; targetSphere.Center = predictedPos; } if (quickCheck || targetSphere.Intersects(testRay) != null) { addProjectile = true; } } } if (addProjectile) { targetAi.DeadProjectiles.Remove(p); targetAi.LiveProjectile.Add(p); targetAi.LiveProjectileTick = Session.Tick; targetAi.NewProjectileTick = Session.Tick; p.Watchers.Add(targetAi); } } } AddTargets.Clear(); }
protected override void DoExecute(WowPlayer Entity) { //on execute, first verify we have a waypoit to follow, else exit if (CurrentWaypoint == null) { Exit(Entity); return; } //verify we are moving, if we aren't then start moving if (!Entity.IsMoving()) { Entity.MoveForward(); } //get distances to waypoint float fDistance = MathFuncs.GetDistance( WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint), Entity.Location, false); //if distance is growing instead of shrinking them face again if (fDistance > _LastDistance) { Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z)); } //if distance to current waypoint is less then / equal to our tolerance, then move to the next waypoint if it exists, else stop/finish. if (fDistance <= Tolerance) { //if another waypoint exists, then switch to it if (TravelPath.GetFirst() != null) { CurrentWaypoint = TravelPath.RemoveFirst(); Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z)); } else { Exit(Entity); Finish(Entity); } } _LastDistance = fDistance; }
public static void MoveUnits() { //Move & turn units for (int i = 0; i < objs.Count; i++) { Obj o = objs[i]; if (o.isUnit) { o.isMoving = false; //Debug.DrawLine(o.go.transform.position,o.goal, Color.green); //Is the unit far enough away from it's goal, that it should go there? if (Vector3.Distance(o.go.transform.position, o.goal) > o.stopDist) { Effects.DrawLine(o.go.transform.position, o.goal, 0.2f, Effects.Colors.Red); o.isMoving = true; //Slow turn at a flat rate Vector3 pos = o.go.transform.position; float tempSpd = o.spd; o.go.transform.rotation = Setup.SlowTurn(pos, o.go.transform.rotation, o.goal, o.turnSpd); //Is the unit pointing at it's goal? if (MathFuncs.CheckCone(-1, 15, o.go.transform.localEulerAngles.y, o.go.transform.position, o.goal, true)) { Effects.DrawLine(new Vector3(pos.x, pos.y + 1, pos.z), new Vector3(o.goal.x, o.goal.y + 1, o.goal.z), 0.3f, Effects.Colors.Cyan); tempSpd = o.spd; } else { //tempSpd = o.spd;// * 0.25f;//turning. Move at 1/4 speed tempSpd = 0; } o.go.transform.Translate(new Vector3(0, 0, tempSpd * Time.deltaTime)); } else { } o.textMesh.text = "isMoving: " + o.isMoving; } } }
private double autocorrelation_coefficient(List <double> data1, List <double> data2) { if (data1.Count != data2.Count) { throw new System.InvalidOperationException("Autocorrelation just has been calculated by two list of same length."); } double mean1 = MathFuncs.CalcMean(data1); double mean2 = MathFuncs.CalcMean(data2); double std1 = MathFuncs.CalcStd(data1, mean1); double std2 = MathFuncs.CalcStd(data2, mean2); double result = 0; for (int i = 0; i < data1.Count; i++) { result += (data1[i] - mean1) * (data2[i] - mean2); } return(result / (data1.Count * std1 * std2)); }
/** * Does this tile area contain a tile? * @param tile Tile to test for. * @return True if the tile is inside the area. */ public bool Contains(TileIndex tile) { if (w == 0) { return(false); } if (w == 0 || h == 0) { throw new InvalidOperationException("This has no width or height"); } uint left = Map.TileX(this.tile); uint top = Map.TileY(this.tile); uint tile_x = Map.TileX(tile); uint tile_y = Map.TileY(tile); return(MathFuncs.IsInsideBS((int)tile_x, left, w) && MathFuncs.IsInsideBS((int)tile_y, top, h)); }
private Vector3 GetHandTargetPosition(Vector3 posStart, Vector3 posTarget, float step) { Vector3 pos = Vector3.Lerp(posStart, posTarget, step); int insideCircle = MathFuncs.IsInsideCircle( pos.x, pos.y, pc.lengthForeArm, pc.arm_back.position.x, pc.arm_back.position.y, pc.lengthBackArm ); if (insideCircle == -1 || insideCircle == 1) { float d = insideCircle == -1 ? pc.lengthForeArm - pc.lengthBackArm + 0.1f : pc.lengthForeArm + pc.lengthBackArm - 0.1f; Vector3 dir = new Vector3(pos.x - pc.arm_back.position.x, pos.y - pc.arm_back.position.y, 0); return(dir.normalized * d + pc.arm_back.position); } return(pos); }