コード例 #1
0
ファイル: MyShipMergeBlock.cs プロジェクト: feiyuren233/vrage
        private void CalculateMergeData(ref MergeData data)
        {
            var   mergeBlockDefinition = this.BlockDefinition as MyMergeBlockDefinition;
            float maxStrength          = mergeBlockDefinition != null ? mergeBlockDefinition.Strength : 0.1f;

            data.Distance = (float)(WorldMatrix.Translation - m_other.WorldMatrix.Translation).Length() - CubeGrid.GridSize;

            data.StrengthFactor = (float)Math.Exp(-data.Distance / CubeGrid.GridSize);
            // Debug.Assert(x <= 1.0f); // This is not so important, but testers kept reporting it, so let's leave it commented out :-)
            float strength = MathHelper.Lerp(0.0f, maxStrength * (CubeGrid.GridSizeEnum == MyCubeSize.Large ? 0.005f : 0.1f), data.StrengthFactor); // 0.005 for large grid, 0.1 for small grid!?

            Vector3 thisVelocity  = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition());
            Vector3 otherVelocity = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition());

            data.RelativeVelocity = otherVelocity - thisVelocity;
            float velocityFactor = 1.0f;

            // The quicker the ships move towards each other, the weaker the constraint strength
            float rvLength = data.RelativeVelocity.Length();

            velocityFactor          = Math.Max(3.6f / (rvLength > 0.1f ? rvLength : 0.1f), 1.0f);
            data.ConstraintStrength = strength / velocityFactor;

            Vector3 toOther = m_other.PositionComp.GetPosition() - PositionComp.GetPosition();
            Vector3 forward = WorldMatrix.GetDirectionVector(m_forward);

            data.Distance   = (toOther).Length();
            data.PositionOk = data.Distance < CubeGrid.GridSize + 0.17f; // 17 cm is tested working value. 15 cm was too few

            data.AxisDelta = (float)(forward + m_other.WorldMatrix.GetDirectionVector(m_forward)).Length();
            data.AxisOk    = data.AxisDelta < 0.1f;

            data.RotationDelta = (float)(WorldMatrix.GetDirectionVector(m_right) - m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight)).Length();
            data.RotationOk    = data.RotationDelta < 0.08f;
        }
コード例 #2
0
ファイル: MyShipMergeBlock.cs プロジェクト: feiyuren233/vrage
        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);
        }
コード例 #3
0
ファイル: MyShipMergeBlock.cs プロジェクト: feiyuren233/vrage
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (SafeConstraint != null)
            {
                if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_CONNECTORS_AND_MERGE_BLOCKS && CustomName.ToString() == "DEBUG")
                {
                    DebugDrawInfo(new Vector2(0.0f, 0.0f));
                    m_other.DebugDrawInfo(new Vector2(0.0f, 120.0f));

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_right) * 10.0f, Color.Red, Color.Red, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight) * 10.0f, Color.Red, Color.Red, false);

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_otherRight) * 5.0f, Color.Yellow, Color.Yellow, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_right) * 5.0f, Color.Yellow, Color.Yellow, false);
                }

                Vector3 thisVelocity     = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition());
                Vector3 otherVelocity    = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition());
                Vector3 relativeVelocity = otherVelocity - thisVelocity;

                // Damping to avoid too quick approach
                if (relativeVelocity.Length() > 0.5f)
                {
                    CubeGrid.Physics.LinearVelocity         += relativeVelocity * 0.05f;
                    m_other.CubeGrid.Physics.LinearVelocity -= relativeVelocity * 0.05f;
                }
            }
        }
コード例 #4
0
ファイル: MyShipMergeBlock.cs プロジェクト: feiyuren233/vrage
 private Vector3 GetMergeNormalWorld()
 {
     return(WorldMatrix.GetDirectionVector(m_forward));
 }