///// <summary> ///// get the damping force in a direction ///// </summary> ///// <param name="direction">the direction of force / acceleration</param> //public float GetDampingInDirection(Base6Directions.Direction direction) //{ // float dampingForce = 0; // foreach (ThrusterProperties thruster in thrustersInDirection[direction]) // if (!thruster.thruster.Closed && thruster.thruster.IsWorking) // dampingForce += thruster.dampingForce * thruster.thruster.ThrustMultiplier; // return dampingForce; //} /// <summary> /// get the force in a direction /// </summary> /// <param name="direction">the direction of force / acceleration</param> public float GetForceInDirection(Base6Directions.Direction direction) { float force = 0; foreach (ThrusterProperties thruster in thrustersInDirection[direction]) if (!thruster.thruster.Closed && thruster.thruster.IsWorking) force += thruster.force * thruster.thruster.ThrustMultiplier; return force; }
public void SetLocalPosition(Vector3I sectionStart, int sectionStartPosition, float cubeSize, Base6Directions.Direction forward, Base6Directions.Direction offset) { int segmentPosition = LinePosition - sectionStartPosition; Matrix localMatrix = PositionComp.LocalMatrix; Vector3 offsetVector = PositionComp.LocalMatrix.GetDirectionVector(forward) * segmentPosition + PositionComp.LocalMatrix.GetDirectionVector(offset) * 0.10f; localMatrix.Translation = (sectionStart + offsetVector / PositionComp.Scale.Value) * cubeSize; PositionComp.LocalMatrix = localMatrix; m_segmentDirection = forward; }
public Base6Directions.Direction GetDirection(Base6Directions.Direction direction) { switch (direction) { case Base6Directions.Direction.Right: return Right; case Base6Directions.Direction.Left: return Left; case Base6Directions.Direction.Up: return Up; case Base6Directions.Direction.Down: return Down; case Base6Directions.Direction.Backward: return Backward; case Base6Directions.Direction.Forward: default: return Forward; } }
public void SetDirection(Base6Directions.Direction dirToSet, Base6Directions.Direction newDirection) { switch (dirToSet) { case Base6Directions.Direction.Right: Right = newDirection; break; case Base6Directions.Direction.Left: Left = newDirection; break; case Base6Directions.Direction.Up: Up = newDirection; break; case Base6Directions.Direction.Down: Down = newDirection; break; case Base6Directions.Direction.Backward: Backward = newDirection; break; case Base6Directions.Direction.Forward: Forward = newDirection; break; } }
public MyBlockOrientation(ref Matrix m) { this.Forward = Base6Directions.GetForward(ref m); this.Up = Base6Directions.GetUp(ref m); }
public static void Transform(ref Vector3I value, ref MatrixI matrix, out Vector3I result) { result = ((Vector3I)(((value.X * Base6Directions.GetIntVector(matrix.Right)) + (value.Y * Base6Directions.GetIntVector(matrix.Up))) + (value.Z * Base6Directions.GetIntVector(matrix.Backward)))) + matrix.Translation; }
/// <summary> /// Sets the overrides in a direction to match a particular force ratio. /// </summary> private void SetOverrides(Base6Directions.Direction direction, float ratio) { float force = GetForceInDirection(direction) * ratio; // no need to lock thrustersInDirection, it is updated on game thread foreach (MyThrust thruster in thrustersInDirection[direction]) if (!thruster.Closed && thruster.IsWorking) { if (force <= 0f) { if (TP_ThrustOverride.GetValue(thruster) != 0f) TP_ThrustOverride.SetValue(thruster, 0f); continue; } float maxForce = GetThrusterMaxForce(thruster); if (maxForce > force) { float overrideValue = Math.Max(force / maxForce * maxThrustOverrideValue, minThrustOverrideValue); if (TP_ThrustOverride.GetValue(thruster) != overrideValue) TP_ThrustOverride.SetValue(thruster, overrideValue); //myLogger.debugLog("direction: " + direction + ", thruster: " + thruster.DisplayNameText + ", add partial force " + force + " of " + maxForce + ", overrideValue: " + overrideValue, "SetOverrides()"); force = 0f; } else { if (TP_ThrustOverride.GetValue(thruster) != maxThrustOverrideValue) TP_ThrustOverride.SetValue(thruster, maxThrustOverrideValue); force -= maxForce; //myLogger.debugLog("direction: " + direction + ", thruster at full force: " + thruster.DisplayNameText, "SetOverrides()"); } } }
private float CalcForceInDirection(Base6Directions.Direction direction) { float force = 0; using (lock_thrustersInDirection.AcquireSharedUsing()) foreach (MyThrust thruster in thrustersInDirection[direction]) if (!thruster.Closed && thruster.IsWorking) force += GetThrusterMaxForce(thruster); m_totalThrustForce[direction] = force; if (direction == m_primaryForce.Direction) { //myLogger.debugLog("updating primary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()"); m_primaryForce.Force = force; } else if (force > m_primaryForce.Force * 1.1f) { myLogger.debugLog("stronger than primary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", primary: " + m_primaryForce, Logger.severity.DEBUG); m_secondaryForce = m_primaryForce; m_primaryForce.Direction = direction; m_primaryForce.Force = force; if (m_secondaryForce.Direction == Base6Directions.GetFlippedDirection(m_primaryForce.Direction)) m_secondaryForce = new ForceInDirection() { Direction = Base6Directions.GetPerpendicular(m_primaryForce.Direction) }; myLogger.debugLog("secondary: " + m_secondaryForce); Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction); Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction); } else if (direction == m_secondaryForce.Direction) { //myLogger.debugLog("updating secondary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()"); m_secondaryForce.Force = force; } else if (force > m_secondaryForce.Force * 1.1f && direction != Base6Directions.GetFlippedDirection(m_primaryForce.Direction)) { myLogger.debugLog("stronger than secondary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", secondary: " + m_secondaryForce, Logger.severity.DEBUG); m_secondaryForce.Direction = direction; m_secondaryForce.Force = force; Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction); Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction); } return force; }
/// <summary> /// Determines if the ship has enough force to accelerate in the specified direction. Checks against gravity. /// </summary> /// <param name="accelertation">The minimum acceleration required, in m/s/s</param> public bool CanMoveDirection(Base6Directions.Direction direction, float acceleration = 1f) { Update(); return GetForceInDirection(direction, true) > Grid.Physics.Mass * acceleration; }
public Matrix GetFloatMatrix() { return(Matrix.CreateWorld(new Vector3(Translation), Base6Directions.GetVector(Forward), Base6Directions.GetVector(Up))); }
/// <summary> /// Returns the direction baseDirection will point to after transformation /// </summary> public Base6Directions.Direction TransformDirection(Base6Directions.Direction baseDirection) { Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection); int flip = ((int)baseDirection % 2); if (axis == Base6Directions.Axis.ForwardBackward) { return flip == 1 ? Base6Directions.GetFlippedDirection(Forward) : Forward; } if (axis == Base6Directions.Axis.LeftRight) { return flip == 1 ? Base6Directions.GetFlippedDirection(Left) : Left; } Debug.Assert(axis == Base6Directions.Axis.UpDown, "Axis invalid in MyBlockOrientation"); return flip == 1 ? Base6Directions.GetFlippedDirection(Up) : Up; }
private static string GetAxisIndicator(Base6Directions.Direction direction) { switch (Base6Directions.GetAxis(direction)) { case Base6Directions.Axis.LeftRight: // X return Base6Directions.GetVector(direction).X < 0 ? "-X" : "+X"; case Base6Directions.Axis.UpDown: // Y return Base6Directions.GetVector(direction).Y < 0 ? "-Y" : "+Y"; case Base6Directions.Axis.ForwardBackward: // Z return Base6Directions.GetVector(direction).Z < 0 ? "-Z" : "+Z"; } return null; }
/// <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) { // Mover will attempt to stop with normal thrust float accel = -myThrust.GetForceInDirection(Base6Directions.GetFlippedDirection(direct)) / Block.Physics.Mass; //myLogger.debugLog("dist: " + dist + ", accel: " + accel + ", max speed: " + PrettySI.makePretty(Math.Sqrt(-2 * accel * dist)), "MaximumSpeed()"); return (float)Math.Sqrt(-2 * accel * dist); }
public static bool IsValidBlockOrientation(Direction forward, Direction up) { return(forward <= Direction.Down && up <= Direction.Down && Vector3.Dot(Base6Directions.GetVector(forward), Base6Directions.GetVector(up)) == 0f); }
public MyBlockOrientation(ref Matrix m) { Forward = Base6Directions.GetForward(ref m); Up = Base6Directions.GetUp(ref m); Debug.Assert(IsValid); }
public MyBlockOrientation(ref Quaternion q) { Forward = Base6Directions.GetForward(q); Up = Base6Directions.GetUp(q); Debug.Assert(IsValid); }
public static Matrix UnpackOrthoMatrix(ref Vector4 packed) { int w = (int)packed.W; return(Matrix.CreateWorld(new Vector3(packed), Base6Directions.GetVector((int)(w / 6)), Base6Directions.GetVector((int)(w % 6)))); }
public void SetExplored(ulong packedCoord, Base6Directions.DirectionFlags directionFlags) { CellInfo info = new CellInfo(); if (m_cellInfos.TryGetValue(packedCoord, out info)) { info.ExploredDirections = directionFlags; m_cellInfos[packedCoord] = info; } else { Debug.Assert(false, "Could not find navmesh cell info for setting explored directions!"); } }
protected void SetConstraint(MyShipMergeBlock otherBlock, HkConstraint constraint, Base6Directions.Direction otherRight) { Debug.Assert(m_constraint == null && m_other == null); if (m_constraint != null || m_other != null) return; m_constraint = constraint; m_other = otherBlock; m_otherRight = otherRight; CheckEmissivity(); NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; }
/// <summary> /// Returns the direction that this orientation transforms to baseDirection /// </summary> public Base6Directions.Direction TransformDirectionInverse(Base6Directions.Direction baseDirection) { Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection); if (axis == Base6Directions.GetAxis(Forward)) { return baseDirection == Forward ? Base6Directions.Direction.Forward : Base6Directions.Direction.Backward; } if (axis == Base6Directions.GetAxis(Left)) { return baseDirection == Left ? Base6Directions.Direction.Left : Base6Directions.Direction.Right; } Debug.Assert(axis == Base6Directions.GetAxis(Up), "Direction invalid in MyBlockOrientation"); return baseDirection == Up ? Base6Directions.Direction.Up : Base6Directions.Direction.Down; }
public MyBlockOrientation(Base6Directions.Direction forward, Base6Directions.Direction up) { Forward = forward; Up = up; Debug.Assert(IsValid); }
public static int GetMountPointWallIndex(Base6Directions.Direction direction) { return m_mountPointWallIndices[(int)direction]; }
public Component(int index, Base6Directions.DirectionFlags exploredDirections) { m_componentIndex = index; m_exploredDirections = exploredDirections; }
public Vector3 MountPointLocalToBlockLocal(Vector3 coord, Base6Directions.Direction mountPointDirection) { Vector3 retval = default(Vector3); int wallIndex = m_mountPointWallIndices[(int)mountPointDirection]; TransformMountPointPosition(ref coord, wallIndex, Size, out retval); retval -= Center; return retval; }
/// <summary> /// get the force in a direction /// </summary> /// <param name="direction">the direction of force / acceleration</param> public float GetForceInDirection(Base6Directions.Direction direction, bool adjustForGravity = false) { float force; if (!m_totalThrustForce.TryGetValue(direction, out force)) force = CalcForceInDirection(direction); if (adjustForGravity) { float change = Base6Directions.GetVector(direction).Dot(LocalGravity) * myGrid.Physics.Mass; //myLogger.debugLog("For direction " + direction + ", and force " + force + ", Gravity adjusts available force by " + change + ", after adjustment: " + (force + change), "GetForceInDirection()"); force += change; } return force; //return Math.Max(force, 1f); // a minimum of 1 N prevents dividing by zero }
public Vector3 MountPointLocalNormalToBlockLocal(Vector3 normal, Base6Directions.Direction mountPointDirection) { Vector3 retval = default(Vector3); int wallIndex = m_mountPointWallIndices[(int)mountPointDirection]; Vector3.TransformNormal(ref normal, ref m_mountPointTransforms[wallIndex], out retval); return retval; }
/// <summary> /// Clears all overrides in a particular direcion. /// </summary> private void ClearOverrides(Base6Directions.Direction direction) { // no need to lock thrustersInDirection, it is updated on game thread foreach (MyThrust thruster in thrustersInDirection[direction]) if (!thruster.Closed && thruster.IsWorking && TP_ThrustOverride.GetValue(thruster) != 0f) TP_ThrustOverride.SetValue(thruster, 0f); }
private void OnChangeDirection(Base6Directions.Direction direction) { m_currentDirection.Value = direction; }
public SerializableBlockOrientation(Base6Directions.Direction forward, Base6Directions.Direction up) { Forward = forward; Up = up; }
public bool GetComponentInfo(int componentIndex, ulong cellIndex, out Base6Directions.DirectionFlags exploredDirections) { exploredDirections = (Base6Directions.DirectionFlags)0; CellInfo cellInfo; bool success = TryGetCell(cellIndex, out cellInfo); Debug.Assert(success, "Could not retrieve cell info for a cell!"); int relativeComponentIndex = componentIndex - cellInfo.StartingIndex; Debug.Assert(relativeComponentIndex >= 0 && relativeComponentIndex < cellInfo.ComponentNum, "Component index overflow! The component does not belong to this cell!"); if (relativeComponentIndex < 0 || relativeComponentIndex >= cellInfo.ComponentNum) { return false; } exploredDirections = cellInfo.ExploredDirections; return true; }
public void ChangeDirection(Base6Directions.Direction direction) { m_currentDirection.Value = direction; }
public MyBlockOrientation(ref Quaternion q) { this.Forward = Base6Directions.GetForward((Quaternion)q); this.Up = Base6Directions.GetUp((Quaternion)q); }
/// <summary> /// Initializes the orientation of the slim block according to the given forward and up vectors. /// Note that the resulting orientation can be different than the supplied orientation due to symmetries. /// This function chooses one canonical orientation for all orientations from one symetry equivalent group of orientations. /// </summary> public void InitOrientation(Base6Directions.Direction Forward, Base6Directions.Direction Up) { if (MyCubeGridDefinitions.GetCubeRotationOptions(BlockDefinition) == MyRotationOptionsEnum.None) { Orientation = MyBlockOrientation.Identity; } else { Orientation = new MyBlockOrientation(Forward, Up); } if (BlockDefinition.CubeDefinition != null) { //Ensure we have always only one distinct orientation use Orientation = MyCubeGridDefinitions.GetTopologyUniqueOrientation(BlockDefinition.CubeDefinition.CubeTopology, Orientation); } }
public MatrixI(Vector3I position, Base6Directions.Direction forward, Base6Directions.Direction up) { Translation = position; Right = Base6Directions.GetFlippedDirection(Base6Directions.GetLeft(up, forward)); Up = up; Backward = Base6Directions.GetFlippedDirection(forward); }
public void MarkExplored(ulong otherCell, Base6Directions.Direction direction) { CellInfo info = new CellInfo(); if (m_cellInfos.TryGetValue(otherCell, out info)) { info.ExploredDirections |= Base6Directions.GetDirectionFlag(direction); m_cellInfos[otherCell] = info; } else { Debug.Assert(false, "Inconsistency: Cannot find cell info to mark explored information!"); } }
public MatrixI(Base6Directions.Direction forward, Base6Directions.Direction up): this(Vector3I.Zero, forward, up) { }
public static void TransformNormal(ref Vector3I normal, ref MatrixI matrix, out Vector3I result) { result = normal.X * Base6Directions.GetIntVector(matrix.Right) + normal.Y * Base6Directions.GetIntVector(matrix.Up) + normal.Z * Base6Directions.GetIntVector(matrix.Backward); }
public static MatrixI CreateRotation(Base6Directions.Direction oldA, Base6Directions.Direction oldB, Base6Directions.Direction newA, Base6Directions.Direction newB) { Debug.Assert(Base6Directions.GetAxis(oldA) != Base6Directions.GetAxis(oldB), "Original vectors must not lie in line!"); Debug.Assert(Base6Directions.GetAxis(newA) != Base6Directions.GetAxis(newB), "Transformed vectors must not lie in line!"); MatrixI newMatrix = new MatrixI(); newMatrix.Translation = Vector3I.Zero; Base6Directions.Direction oldC = Base6Directions.GetCross(oldA, oldB); Base6Directions.Direction newC = Base6Directions.GetCross(newA, newB); newMatrix.SetDirection(oldA, newA); newMatrix.SetDirection(oldB, newB); newMatrix.SetDirection(oldC, newC); return newMatrix; }
public static float GetLengthInDirection(this IMyCubeBlock block, Base6Directions.Direction direction) { switch (direction) { case Base6Directions.Direction.Right: case Base6Directions.Direction.Left: return block.LocalAABB.Size.X; case Base6Directions.Direction.Up: case Base6Directions.Direction.Down: return block.LocalAABB.Size.Y; case Base6Directions.Direction.Backward: case Base6Directions.Direction.Forward: return block.LocalAABB.Size.Z; } VRage.Exceptions.ThrowIf<NotImplementedException>(true, "direction not implemented: " + direction); throw new Exception(); }
public MatrixI(ref Vector3I position, ref Vector3 forward, ref Vector3 up) : this(ref position, Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up)) { }