Esempio n. 1
0
        public override void Close()
        {
            base.Close();

            if (m_shape != null)
            {
                m_shape.Dispose();
                m_shape = null;
            }
        }
Esempio n. 2
0
        void CreateBody()
        {
            if (m_shape == null)
                m_shape = new MyGridShape(m_grid);

            // TODO: this is hack, but cannot be handled better, this fixes bug...ship won't rotate
            if (m_grid.GridSizeEnum == MyCubeSize.Large && !IsStatic)
            {
                InitialSolverDeactivation = HkSolverDeactivation.Off;
            }
            ContactPointDelay = 0;
            CreateFromCollisionObject(m_shape, Vector3.Zero, MatrixD.Identity, m_shape.MassProperties);

            ProfilerShort.Begin("Setup");
            {
                RigidBody.ContactPointCallbackEnabled = true;
                RigidBody.ContactSoundCallbackEnabled = true;
                if (!MyPerGameSettings.Destruction)
                    RigidBody.ContactPointCallback += RigidBody_ContactPointCallback;
                else
                    RigidBody.ContactPointCallback += RigidBody_ContactPointCallback_Destruction;

                RigidBody.LinearDamping = MyPerGameSettings.DefaultLinearDamping;
                RigidBody.AngularDamping = MyPerGameSettings.DefaultAngularDamping;

                RigidBody.BreakPartsHandler = BreakPartsHandler;

                if (RigidBody2 != null)
                {
                    RigidBody2.ContactPointCallbackEnabled = true;
                    if (!MyPerGameSettings.Destruction)
                        RigidBody2.ContactPointCallback += RigidBody_ContactPointCallback;
                    RigidBody2.BreakPartsHandler = BreakPartsHandler;
                }
            }

            var flags = GetFlags(m_grid);

            if (IsStatic)
            {
                RigidBody.Layer = MyPhysics.StaticCollisionLayer;
            }
            else if (m_grid.GridSizeEnum == MyCubeSize.Large)
            {
                RigidBody.MaxAngularVelocity = GetLargeShipMaxAngularVelocity();
                RigidBody.MaxLinearVelocity = LargeShipMaxLinearVelocity();
                RigidBody.Layer = flags == RigidBodyFlag.RBF_DOUBLED_KINEMATIC ? MyPhysics.DynamicDoubledCollisionLayer : MyPhysics.DefaultCollisionLayer;
            }
            else if (m_grid.GridSizeEnum == MyCubeSize.Small)
            {
                RigidBody.MaxAngularVelocity = GetSmallShipMaxAngularVelocity();
                RigidBody.MaxLinearVelocity = SmallShipMaxLinearVelocity();
                RigidBody.Layer = MyPhysics.DefaultCollisionLayer;
            }

            if (RigidBody2 != null)
            {
                RigidBody2.Layer = MyPhysics.KinematicDoubledCollisionLayer;
            }

            if (MyPerGameSettings.BallFriendlyPhysics)
            {
                RigidBody.Restitution = 0;
                if (RigidBody2 != null)
                    RigidBody2.Restitution = 0;
            }

            ProfilerShort.End();
            ProfilerShort.Begin("Enable");
            Enabled = true;
            ProfilerShort.End();
        }
Esempio n. 3
0
        public MyGridPhysics(MyCubeGrid grid, MyGridShape shape = null)
            : base(grid, GetFlags(grid))
        {
            m_grid = grid;
            m_shape = shape;
            DeformationRatio = m_grid.GridSizeEnum == MyCubeSize.Large ? LargeGridDeformationRatio : SmallGridDeformationRatio;
            MaterialType = MyMaterialType.SHIP;
            CreateBody();

            if (MyFakes.ENABLE_PHYSICS_HIGH_FRICTION)
                Friction = MyFakes.PHYSICS_HIGH_FRICTION;
        }