private void ConnectInternal(ref Matrix thisMatrix, ref Matrix otherMatrix, MyShipConnector otherConnector, bool constructor)
        {
            Debug.Assert(!m_attachableConveyorEndpoint.AlreadyAttached());
            if (m_attachableConveyorEndpoint.AlreadyAttached()) m_attachableConveyorEndpoint.DetachAll();

            m_attachableConveyorEndpoint.Attach(otherConnector.m_attachableConveyorEndpoint);

            var data = new HkFixedConstraintData();
            data.SetInWorldSpace(ref thisMatrix, ref otherMatrix, ref thisMatrix);
            var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, otherConnector.CubeGrid.Physics.RigidBody, data);

            this.Connected = true;
            this.Master = true;
            otherConnector.Connected = true;
            otherConnector.Master = false;
            if (!constructor)
            {
                this.ChangeConstraint(otherConnector, newConstraint);
                otherConnector.ChangeConstraint(this, newConstraint);
            }
            else
            {
                this.SetConstraint(otherConnector, newConstraint);
                otherConnector.SetConstraint(this, newConstraint);
            }

            AddConstraint(newConstraint);

            if (CubeGrid != otherConnector.CubeGrid)
            {
                this.OnConstraintAdded(GridLinkTypeEnum.Logical, otherConnector.CubeGrid);
                this.OnConstraintAdded(GridLinkTypeEnum.Physical, otherConnector.CubeGrid);
            }
        }
        private void CreateConstraintNosync(MyShipConnector otherConnector)
        {
            Debug.Assert(IsMaster, "Constraints should be created only master (entity with higher EntityId)");

            var posA = ConstraintPositionInGridSpace();
            var posB = otherConnector.ConstraintPositionInGridSpace();
            var axisA = ConstraintAxisGridSpace();
            var axisB = -otherConnector.ConstraintAxisGridSpace();

            var data = new HkHingeConstraintData();
            data.SetInBodySpace(posA, posB, axisA, axisB, CubeGrid.Physics, otherConnector.CubeGrid.Physics);
            var data2 = new HkMalleableConstraintData();
            data2.SetData(data);
            data.ClearHandle();
            data = null;
            data2.Strength = GetEffectiveStrength(otherConnector);

            var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, otherConnector.CubeGrid.Physics.RigidBody, data2);
            SetConstraint(otherConnector, newConstraint);
            otherConnector.SetConstraint(this, newConstraint);

            AddConstraint(newConstraint);
        }
        private void CreateConstraintNosync(MyShipConnector otherConnector, ref Vector3 posA, ref Vector3 posB, ref Vector3 axisA, ref Vector3 axisB)
        {
            var data = new HkHingeConstraintData();
            data.SetInBodySpace(ref posA, ref posB, ref axisA, ref axisB);
            var data2 = new HkMalleableConstraintData();
            data2.SetData(data);
            data.ClearHandle();
            data = null;
            data2.Strength = 0.0003f;

            var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, otherConnector.CubeGrid.Physics.RigidBody, data2);
            this.Master = true;
            otherConnector.Master = false;
            SetConstraint(otherConnector, newConstraint);
            otherConnector.SetConstraint(this, newConstraint);

            AddConstraint(newConstraint);
        }
        private void ConnectInternal(ref Matrix localSpaceA, ref Matrix localSpaceB, MyShipConnector otherConnector)
        {
            Debug.Assert(EntityId > otherConnector.EntityId, "Constraints should be created only master (entity with higher EntityId)");
            Debug.Assert(!m_attachableConveyorEndpoint.AlreadyAttached());
            if (m_attachableConveyorEndpoint.AlreadyAttached()) m_attachableConveyorEndpoint.DetachAll();

            m_attachableConveyorEndpoint.Attach(otherConnector.m_attachableConveyorEndpoint);

            var data = new HkFixedConstraintData();
            data.SetInBodySpace(localSpaceA, localSpaceB, CubeGrid.Physics, otherConnector.CubeGrid.Physics);
            var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, otherConnector.CubeGrid.Physics.RigidBody, data);

            this.Connected = true;
            otherConnector.Connected = true;
            this.SetConstraint(otherConnector, newConstraint);
            otherConnector.SetConstraint(this, newConstraint);

            AddConstraint(newConstraint);

            if (CubeGrid != otherConnector.CubeGrid)
            {
                this.OnConstraintAdded(GridLinkTypeEnum.Logical, otherConnector.CubeGrid);
                this.OnConstraintAdded(GridLinkTypeEnum.Physical, otherConnector.CubeGrid);
            }
            CubeGrid.OnPhysicsChanged += CubeGrid_OnPhysicsChanged;
        }