/// <summary> /// Calculate the force ratio from acceleration. /// </summary> /// <param name="blockAccel">Acceleration</param> /// <returns>Force ratio</returns> private Vector3 ToForceRatio(Vector3 blockAccel) { Vector3 result = Vector3.Zero; if (blockAccel.X > 0f) { result.X = blockAccel.X * Block.Physics.Mass / Thrust.GetForceInDirection(Base6Directions.GetFlippedDirection(Block.CubeBlock.Orientation.Left)); } else if (blockAccel.X < 0f) { result.X = blockAccel.X * Block.Physics.Mass / Thrust.GetForceInDirection(Block.CubeBlock.Orientation.Left); } if (blockAccel.Y > 0f) { result.Y = blockAccel.Y * Block.Physics.Mass / Thrust.GetForceInDirection(Block.CubeBlock.Orientation.Up); } else if (blockAccel.Y < 0f) { result.Y = blockAccel.Y * Block.Physics.Mass / Thrust.GetForceInDirection(Base6Directions.GetFlippedDirection(Block.CubeBlock.Orientation.Up)); } if (blockAccel.Z > 0f) { result.Z = blockAccel.Z * Block.Physics.Mass / Thrust.GetForceInDirection(Base6Directions.GetFlippedDirection(Block.CubeBlock.Orientation.Forward)); } else if (blockAccel.Z < 0f) { result.Z = blockAccel.Z * Block.Physics.Mass / Thrust.GetForceInDirection(Block.CubeBlock.Orientation.Forward); } //Log.DebugLog("accel: " + localAccel + ", force ratio: " + result + ", mass: " + Block.Physics.Mass, "ToForceRatio()"); return(result); }
/// <summary> /// Calculates the maximum speed that will allow the grid to stop at the destination. /// </summary> /// <param name="dist">The distance to the destination</param> /// <param name="direct">The directional thrusters to use</param> /// <returns>The maximum speed that will allow the grid to stop at the destination.</returns> private float MaximumSpeed(float dist, Base6Directions.Direction direct) { if (dist < 0.01f) { return(0f); } direct = Block.CubeBlock.Orientation.TransformDirection(direct); float force = Thrust.GetForceInDirection(direct, true) * AvailableForceRatio; if (force < 1f) { //Log.DebugLog("No thrust available in direction: " + direct + ", dist: " + dist, "MaximumSpeed()", Logger.severity.DEBUG); return(dist * 0.1f); } float accel = -force / Block.Physics.Mass; //Log.DebugLog("direction: " + direct + ", dist: " + dist + ", max accel: " + accel + ", mass: " + Block.Physics.Mass + ", max speed: " + PrettySI.makePretty(Math.Sqrt(-2f * accel * dist)) + " m/s" + ", cap: " + dist * 0.5f + " m/s", "MaximumSpeed()"); //return Math.Min((float)Math.Sqrt(-2f * accel * dist), dist * 0.25f); // capped for the sake of autopilot's reaction time return((float)Math.Sqrt(-2f * accel * dist)); }