예제 #1
0
 public bool GetTransform(out MatrixI transform)
 {
     transform = new MatrixI();
     if (this.Blocks.Count != 0)
     {
         MySlimBlock block = this.Blocks.First <MySlimBlock>();
         if (block.MultiBlockIndex < this.MultiBlockDefinition.BlockDefinitions.Length)
         {
             MyMultiBlockDefinition.MyMultiBlockPartDefinition definition = this.MultiBlockDefinition.BlockDefinitions[block.MultiBlockIndex];
             transform             = MatrixI.CreateRotation(definition.Forward, definition.Up, block.Orientation.Forward, block.Orientation.Up);
             transform.Translation = block.Position - Vector3I.TransformNormal(definition.Min, ref transform);
             return(true);
         }
     }
     return(false);
 }
        public bool GetTransform(out MatrixI transform)
        {
            transform = default(MatrixI);

            if (Blocks.Count != 0)
            {
                var refBlock = Blocks.First();
                Debug.Assert(refBlock.MultiBlockIndex < MultiBlockDefinition.BlockDefinitions.Length);
                if (refBlock.MultiBlockIndex < MultiBlockDefinition.BlockDefinitions.Length)
                {
                    var refBlockDefInfo = MultiBlockDefinition.BlockDefinitions[refBlock.MultiBlockIndex];
                    transform             = MatrixI.CreateRotation(refBlockDefInfo.Forward, refBlockDefInfo.Up, refBlock.Orientation.Forward, refBlock.Orientation.Up);
                    transform.Translation = refBlock.Position - Vector3I.TransformNormal(refBlockDefInfo.Min, ref transform);
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        private Vector3I CalculateOtherGridOffset()
        {
            Debug.Assert(m_other != null);

            Vector3 myConstraint    = ConstraintPositionInGridSpace() / this.CubeGrid.GridSize;
            Vector3 otherConstraint = -m_other.ConstraintPositionInGridSpace() / m_other.CubeGrid.GridSize;

            Base6Directions.Direction thisRight   = Orientation.TransformDirection(m_right);   // Where does this block's right point to
            Base6Directions.Direction thisForward = Orientation.TransformDirection(m_forward); // Where does this block's forward point to

            Base6Directions.Direction otherBackward = Base6Directions.GetFlippedDirection(m_other.Orientation.TransformDirection(m_other.m_forward));
            Base6Directions.Direction otherRight    = m_other.CubeGrid.WorldMatrix.GetClosestDirection(CubeGrid.WorldMatrix.GetDirectionVector(thisRight));

            Vector3 toOtherOrigin;
            MatrixI rotation = MatrixI.CreateRotation(otherRight, otherBackward, thisRight, thisForward);

            Vector3.Transform(ref otherConstraint, ref rotation, out toOtherOrigin);

            return(Vector3I.Round(myConstraint + toOtherOrigin));
        }
예제 #4
0
        public static Vector3I CalculateOffset(IMyCubeBlock pad1, IMyCubeBlock pad2)
        {
            Vector3 pad1local = pad1.Position;  // ConstraintPositionInGridSpace(pad1) / pad1.CubeGrid.GridSize;
            Vector3 pad2local = -pad2.Position; // -ConstraintPositionInGridSpace(pad2) / pad2.CubeGrid.GridSize;

            // I dunno why it works but it seems to do in the tests I made xD
            pad1local += Base6Directions.GetVector(pad1.Orientation.TransformDirection(Base6Directions.GetOppositeDirection(WeldPad.DirForward)));
            //pad2local += Base6Directions.GetVector(pad2.Orientation.TransformDirection(Base6Directions.GetOppositeDirection(WeldPad.DIR_FORWARD)));

            Base6Directions.Direction direction = pad1.Orientation.TransformDirection(WeldPad.DirRight);

            MatrixI matrix = MatrixI.CreateRotation(
                newB: pad1.Orientation.TransformDirection(WeldPad.DirForward),
                oldB: Base6Directions.GetFlippedDirection(pad2.Orientation.TransformDirection(WeldPad.DirForward)),
                oldA: pad2.CubeGrid.WorldMatrix.GetClosestDirection(pad1.CubeGrid.WorldMatrix.GetDirectionVector(direction)),
                newA: direction);

            Vector3 offset;

            Vector3.Transform(ref pad2local, ref matrix, out offset);
            return(Vector3I.Round(pad1local + offset));
        }