Пример #1
0
        private void CreateConstraint(MyCubeGrid other, MyShipMergeBlock block)
        {
            var data = new HkPrismaticConstraintData();

            data.MaximumLinearLimit = 0;
            data.MinimumLinearLimit = 0;
            var posA      = ConstraintPositionInGridSpace();
            var posB      = block.ConstraintPositionInGridSpace();
            var axisA     = PositionComp.LocalMatrix.GetDirectionVector(m_forward);
            var axisAPerp = PositionComp.LocalMatrix.GetDirectionVector(m_right);
            var axisB     = -block.PositionComp.LocalMatrix.GetDirectionVector(m_forward);

            Base6Directions.Direction thisRightForOther = block.WorldMatrix.GetClosestDirection(WorldMatrix.GetDirectionVector(m_right));
            Base6Directions.Direction otherRight        = WorldMatrix.GetClosestDirection(block.WorldMatrix.GetDirectionVector(block.m_right));

            var axisBPerp = block.PositionComp.LocalMatrix.GetDirectionVector(thisRightForOther);

            data.SetInBodySpace(posA, posB, axisA, axisB, axisAPerp, axisBPerp, CubeGrid.Physics, other.Physics);
            var data2 = new HkMalleableConstraintData();

            data2.SetData(data);
            data.ClearHandle();
            data           = null;
            data2.Strength = 0.00001f;

            var constraint = new HkConstraint(CubeGrid.Physics.RigidBody, other.Physics.RigidBody, data2);

            AddConstraint(constraint);

            SetConstraint(block, constraint, otherRight);
            m_other.SetConstraint(this, constraint, thisRightForOther);
        }
Пример #2
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));
        }
Пример #3
0
        private void CreateConstraint(MyCubeGrid other, MyShipMergeBlock block)
        {
            var data = new HkPrismaticConstraintData();
            data.MaximumLinearLimit = 0;
            data.MinimumLinearLimit = 0;
            var posA = ConstraintPositionInGridSpace();
            var posB = block.ConstraintPositionInGridSpace();
            var axisA = PositionComp.LocalMatrix.GetDirectionVector(m_forward);
            var axisAPerp = PositionComp.LocalMatrix.GetDirectionVector(m_right);
            var axisB = -block.PositionComp.LocalMatrix.GetDirectionVector(m_forward);

            Base6Directions.Direction thisRightForOther = block.WorldMatrix.GetClosestDirection(WorldMatrix.GetDirectionVector(m_right));
            Base6Directions.Direction otherRight = WorldMatrix.GetClosestDirection(block.WorldMatrix.GetDirectionVector(block.m_right));

            var axisBPerp = block.PositionComp.LocalMatrix.GetDirectionVector(thisRightForOther);

            data.SetInBodySpace(ref posA, ref posB, ref axisA, ref axisB, ref axisAPerp, ref axisBPerp);
            var data2 = new HkMalleableConstraintData();
            data2.SetData(data);
            data.ClearHandle();
            data = null;
            data2.Strength = 0.00001f;

            var constraint = new HkConstraint(CubeGrid.Physics.RigidBody, other.Physics.RigidBody, data2);
            AddConstraint(constraint);

            SetConstraint(block, constraint, otherRight);
            m_other.SetConstraint(this, constraint, thisRightForOther);
        }