private void calcOrientationFromBlockDirection(IMyCubeBlock block) { if (CNS.match_direction != null) { log("already have an orientation: " + CNS.match_direction + ":" + CNS.match_roll, "calcOrientationFromBlockDirection()", Logger.severity.TRACE); return; } Base6Directions.Direction?landDirLocal; if (!landingDirectionLocal(block, out landDirLocal)) { log("could not get landing direction from block: " + block.DefinitionDisplayNameText, "calcOrientationFromBlockDirection()", Logger.severity.INFO); return; } Base6Directions.Direction?blockDirection; direction_RCfromGrid(landDirLocal, out blockDirection); switch (blockDirection) { case Base6Directions.Direction.Forward: CNS.match_direction = Base6Directions.GetFlippedDirection((Base6Directions.Direction)CNS.landDirection); //CNS.match_direction = Base6Directions.Direction.Backward; // roll is irrelevant break; case Base6Directions.Direction.Backward: CNS.match_direction = CNS.landDirection; //CNS.match_direction = Base6Directions.Direction.Forward; // roll is irrelevant break; case Base6Directions.Direction.Up: CNS.match_direction = Base6Directions.GetPerpendicular((Base6Directions.Direction)CNS.landDirection); //CNS.match_direction = Base6Directions.Direction.Up; CNS.match_roll = Base6Directions.GetFlippedDirection((Base6Directions.Direction)CNS.landDirection); //CNS.match_roll = Base6Directions.Direction.Backward; break; case Base6Directions.Direction.Down: CNS.match_direction = Base6Directions.GetPerpendicular((Base6Directions.Direction)CNS.landDirection); //CNS.match_direction = Base6Directions.Direction.Down; CNS.match_roll = CNS.landDirection; //CNS.match_direction = Base6Directions.Direction.Forward; break; case Base6Directions.Direction.Left: CNS.match_direction = Base6Directions.GetPerpendicular((Base6Directions.Direction)CNS.landDirection); //CNS.match_roll = Base6Directions.Direction.Up; CNS.match_roll = Base6Directions.GetFlippedDirection(Base6Directions.GetCross((Base6Directions.Direction)CNS.match_direction, (Base6Directions.Direction)CNS.landDirection)); //CNS.match_direction = Base6Directions.Direction.Left; break; case Base6Directions.Direction.Right: CNS.match_direction = Base6Directions.GetPerpendicular((Base6Directions.Direction)CNS.landDirection); //CNS.match_roll = Base6Directions.Direction.Up; CNS.match_roll = Base6Directions.GetCross((Base6Directions.Direction)CNS.match_direction, (Base6Directions.Direction)CNS.landDirection); //CNS.match_direction = Base6Directions.Direction.Right; break; } log("landDirection = " + landDirLocal + ", blockDirection = " + blockDirection + ", match_direction = " + CNS.match_direction + ", match_roll = " + CNS.match_roll, "calcOrientationFromBlockDirection()", Logger.severity.DEBUG); }
public void Burn(ZACommons commons, EventDriver eventDriver) { if (ShouldAbort(commons, eventDriver, Modes.Burning, false)) { return; } var shipControl = (ShipControlCommons)commons; var controller = GetShipController(shipControl); if (controller == null) { return; } var gravity = controller.GetNaturalGravity(); if (gravity.LengthSquared() > 0.0) { // Override gyro, disable "bottom" thrusters shipControl.Reset(gyroOverride: true, thrusterEnable: true, thrusterCondition: ThrusterCondition); shipControl.ThrustControl.Enable(Base6Directions.GetFlippedDirection(BrakeDirection), false); var down = shipControl.ShipBlockOrientation.TransformDirection(BrakeDirection); seeker.Init(shipControl, shipUp: Base6Directions.GetPerpendicular(down), shipForward: down); if (Autodrop) { // "forward" & "right" var forward = Base6Directions.GetPerpendicular(BrakeDirection); var right = Base6Directions.GetCross(forward, BrakeDirection); // Actual orientations don't matter // Just as long as they're planar & perpendicular to down LongCruiser.Init(shipControl, localForward: forward); LatCruiser.Init(shipControl, localForward: right); } Mode = Modes.Gliding; eventDriver.Schedule(FramesPerRun, Glide); } else { cruiser.Cruise(shipControl, VTVLHELPER_BURN_SPEED, condition: ThrusterCondition); eventDriver.Schedule(FramesPerRun, Burn); } }
public void GetTransforms(PartMountPointBlock other, HashSet <MatrixI> cache) { var dirSelf = Base6Directions.GetOppositeDirection(MountDirection6); var dirOther = other.MountDirection6; if (other.BiasDirection6.HasValue && BiasDirection6.HasValue) { // Simple case. Only one possible transform. var tmp = new MatrixI(); // Mount directions need to be aligned tmp.SetDirection(dirOther, dirSelf); // Bias directions must be aligned var biasSelf = BiasDirection6.Value; var biasOther = other.BiasDirection6.Value; tmp.SetDirection(biasOther, biasSelf); // Final alignment tmp.SetDirection(Base6Directions.GetCross(dirOther, biasOther), Base6Directions.GetCross(dirSelf, biasSelf)); // Check secondary alignment when present. If it fails just return. These will never work. if (other.SecondBiasDirection6.HasValue && SecondBiasDirection6.HasValue && tmp.GetDirection(other.SecondBiasDirection6.Value) != SecondBiasDirection6.Value) { return; } tmp.Translation = AnchorLocation - Vector3I.TransformNormal(other.MountLocation, ref tmp); cache.Add(tmp); return; } // Complicated case. 4 possibilities // Perp. axis using +2 // Base direction for axis (first entry) using ~1 var dirSelfI = ((int)dirSelf & ~1) + 2; var dirOtherI = ((int)dirOther & ~1) + 2; for (var i = 0; i < 4; i++) { var tmp = new MatrixI(); tmp.SetDirection(dirOther, dirSelf); // Align one of the 4 perp. vectors with another perp vector var biasSelf = Base6Directions.EnumDirections[dirSelfI % 6]; var biasOther = Base6Directions.EnumDirections[(dirOtherI + i) % 6]; tmp.SetDirection(biasOther, biasSelf); // Complete the matrix tmp.SetDirection(Base6Directions.GetCross(dirOther, biasOther), Base6Directions.GetCross(dirSelf, biasSelf)); tmp.Translation = AnchorLocation - Vector3I.TransformNormal(other.MountLocation, ref tmp); cache.Add(tmp); } }
public void SetMatrixOrientation(Base6Directions.Direction forward, Base6Directions.Direction up) { if (forward == up || forward == Base6Directions.GetFlippedDirection(up)) { Log.AlwaysLog("incompatible directions, for2: " + forward + ", up2: " + up, Logger.severity.FATAL); throw new ArgumentException("forward is not perpendicular to up"); } Matrix localMatrix = LocalMatrix; localMatrix.Forward = Base6Directions.GetVector(forward); localMatrix.Up = Base6Directions.GetVector(up); localMatrix.Right = Base6Directions.GetVector(Base6Directions.GetCross(forward, up)); this.LocalMatrix = localMatrix; }
/// <summary> /// Creates a PseudoBlock from a block and an orientation. /// </summary> /// <param name="block">The block to calculate the local matrix from.</param> /// <param name="forward">The direction the block should face towards the target.</param> /// <param name="up">A direction perpendicular to forward.</param> public PseudoBlock(IMyCubeBlock block, Base6Directions.Direction?forward, Base6Directions.Direction?up) : this(block) { Base6Directions.Direction for2 = forward ?? block.FirstFaceDirection(); Base6Directions.Direction up2 = up ?? (for2 == Base6Directions.Direction.Forward ? Base6Directions.Direction.Up : Base6Directions.GetPerpendicular(for2)); if (for2 == up2 || for2 == Base6Directions.GetFlippedDirection(up2)) { Log.DebugLog("incompatible directions, for2: " + for2 + ", up2: " + up2); up2 = Base6Directions.GetPerpendicular(for2); } this.LocalMatrix = new Matrix() { Forward = block.LocalMatrix.GetDirectionVector(for2), Up = block.LocalMatrix.GetDirectionVector(up2), Right = block.LocalMatrix.GetDirectionVector(Base6Directions.GetCross(for2, up2)), M41 = block.LocalMatrix.M41, M42 = block.LocalMatrix.M42, M43 = block.LocalMatrix.M43, M44 = block.LocalMatrix.M44 }; }
public void Init(MyObjectBuilder_CubeBlock block, string piece, IEnumerable <string> args) { Piece = piece; MountDirection6 = Base6Directions.GetOppositeDirection(Base6Directions.GetCross(block.BlockOrientation.Up, block.BlockOrientation.Forward)); AnchorLocation = block.Min; AdjacencyRule = AdjacencyRule.Any; BiasDirection6 = null; SecondBiasDirection6 = null; var blockOrientation = new MatrixI(block.BlockOrientation); foreach (var arg in args) { if (arg.StartsWithICase(PartDummyUtils.ArgumentMountDirection)) { Base6Directions.Direction tmpMountDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentMountDirection.Length), out tmpMountDirection)) { MountDirection6 = blockOrientation.GetDirection(tmpMountDirection); } else { Logging.Error("Failed to parse mount point direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentBiasDirection)) { Base6Directions.Direction tmpBiasDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentBiasDirection.Length), out tmpBiasDirection)) { BiasDirection6 = blockOrientation.GetDirection(tmpBiasDirection); } else { Logging.Error("Failed to parse bias direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentSecondBiasDirection)) { Base6Directions.Direction tmpBiasDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentSecondBiasDirection.Length), out tmpBiasDirection)) { SecondBiasDirection6 = blockOrientation.GetDirection(tmpBiasDirection); } else { Logging.Error("Failed to parse second bias direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentAnchorPoint)) { Vector3I anchor; if (PartDummyUtils.TryParseVector(arg.Substring(PartDummyUtils.ArgumentAnchorPoint.Length), out anchor)) { AnchorLocation = block.Min + anchor; continue; } Logging.Error("Failed to parse anchor location argument \"{0}\"", arg); } else if (arg.StartsWithICase(PartDummyUtils.ArgumentAdjacencyRule)) // Adjacency Rule { AdjacencyRule rule; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentAdjacencyRule.Length), out rule)) { AdjacencyRule = rule; } else { Logging.Error("Failed to parse adjacency rule argument \"{0}\"", arg); } } else { Logging.Error("Failed to parse mount point argument \"{0}\"", arg); } } // ReSharper disable once InvertIf if (SecondBiasDirection6.HasValue && !BiasDirection6.HasValue) { BiasDirection6 = SecondBiasDirection6; SecondBiasDirection6 = null; } }