private void CreateSubpartsConstraint(MyEntitySubpart subpart) { m_subpartsFixedData = new HkFixedConstraintData(); m_subpartsFixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_subpartsFixedData.SetInertiaStabilizationFactor(1); var matAD = MatrixD.CreateWorld(Position * CubeGrid.GridSize + Vector3D.Transform(Vector3D.Transform(m_subpartsConstraintPos, WorldMatrix), CubeGrid.PositionComp.LocalMatrix), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); matAD.Translation = CubeGrid.Physics.WorldToCluster(matAD.Translation); var matA = (Matrix)matAD; var matB = subpart.PositionComp.LocalMatrix; m_subpartsFixedData.SetInWorldSpace(ref matA, ref matB, ref matB); //Dont dispose the fixed data or we wont have access to them HkConstraintData constraintData = m_subpartsFixedData; if (Sync.IsServer) // Breakable only on server { constraintData = new HkBreakableConstraintData(m_subpartsFixedData) { Threshold = BreakOffTreshold }; } m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, subpart.Physics.RigidBody, constraintData); Debug.Assert(m_subpartsConstraint.RigidBodyA != null); m_subpartsConstraint.WantRuntime = true; }
public void Attach(MyPistonTop topBlock) { if (CubeGrid == topBlock.CubeGrid) { return; } Debug.Assert(topBlock != null, "Top block cannot be null!"); Debug.Assert(m_constraint == null, "Contraint already attached, call detach first!"); Debug.Assert(m_topBlockId.Value == topBlock.EntityId, "m_topBlockId must be set prior calling Attach!"); UpdateAnimation(); if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled && topBlock.CubeGrid.Physics != null) { m_topBlock = topBlock; m_topGrid = m_topBlock.CubeGrid; var rotorBody = m_topGrid.Physics.RigidBody; var matAD = MatrixD.CreateWorld(Vector3D.Transform(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), CubeGrid.PositionComp.WorldMatrixNormalizedInv), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); var matBD = MatrixD.CreateWorld(m_topBlock.Position * m_topBlock.CubeGrid.GridSize, m_topBlock.PositionComp.LocalMatrix.Forward, m_topBlock.PositionComp.LocalMatrix.Up); var matA = (Matrix)matAD; var matB = (Matrix)matBD; m_fixedData = new HkFixedConstraintData(); m_fixedData.SetInertiaStabilizationFactor(10); m_fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_fixedData.SetInBodySpace(matA, matB, CubeGrid.Physics, m_topGrid.Physics); var breakData = new HkBreakableConstraintData(m_fixedData); //Dont dispose the fixed data or we wont have access to them breakData.Threshold = BreakOffTreshold; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = false; m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, breakData); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); if (!m_constraint.InWorld) { Debug.Fail("Constraint was not added to world"); CubeGrid.Physics.RemoveConstraint(m_constraint); m_constraint.Dispose(); m_constraint = null; m_fixedData.Dispose(); m_fixedData = null; return; } m_constraint.Enabled = true; m_topBlock.Attach(this); m_topGrid.OnPhysicsChanged += CubeGrid_OnPhysicsChanged; OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid); m_conveyorEndpoint.Attach(topBlock.ConveyorEndpoint as MyAttachableConveyorEndpoint); UpdateText(); } }
public void Attach(MyPistonTop topBlock, bool updateSync = false) { if (m_topBlock != null) { Detach(); } if (CubeGrid.Physics == null || SafeConstraint != null) { return; } UpdateAnimation(); Debug.Assert(SafeConstraint == null); if (CubeGrid.Physics.Enabled && topBlock != null) { m_topBlock = topBlock; m_topBlockId = topBlock.EntityId; if (updateSync) { SyncObject.AttachTop(m_topBlock); } m_topGrid = m_topBlock.CubeGrid; var rotorBody = m_topGrid.Physics.RigidBody; var matAD = MatrixD.CreateWorld(Vector3D.Transform(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), CubeGrid.PositionComp.WorldMatrixNormalizedInv), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); var matBD = MatrixD.CreateWorld(m_topBlock.Position * m_topBlock.CubeGrid.GridSize, m_topBlock.PositionComp.LocalMatrix.Forward, m_topBlock.PositionComp.LocalMatrix.Up); var matA = (Matrix)matAD; var matB = (Matrix)matBD; m_fixedData = new HkFixedConstraintData(); m_fixedData.SetInertiaStabilizationFactor(10); m_fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_fixedData.SetInBodySpace(ref matA, ref matB); var breakData = new HkBreakableConstraintData(m_fixedData); //Dont dispose the fixed data or we wont have access to them breakData.Threshold = BreakOffTreshold; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = false; m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, breakData); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_topBlock.Attach(this); OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid); m_conveyorEndpoint.Attach(topBlock.ConveyorEndpoint as MyAttachableConveyorEndpoint); } }
private void CheckSubpartConstraint() { if (m_subpartsConstraint != null && (m_subpartsConstraint.RigidBodyA == null)) { if (m_subPartContraintInScene) { m_subPartContraintInScene = false; CubeGrid.Physics.RemoveConstraint(m_subpartsConstraint); } m_subpartsConstraint.Dispose(); m_subpartsConstraint = null; var breakableData = new HkBreakableConstraintData(m_subpartsFixedData); //Dont dispose the fixed data or we wont have access to them breakableData.Threshold = BreakOffTreshold; m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_subpart1.Physics.RigidBody, breakableData); Debug.Assert(m_subpartsConstraint.RigidBodyA != null); m_subpartsConstraint.WantRuntime = true; } }
private void InitSubpartsPhysics() { var subpart = m_subpart1; if (subpart == null || CubeGrid.Physics == null) { return; } subpart.Physics = new MyPhysicsBody(subpart, CubeGrid.IsStatic ? RigidBodyFlag.RBF_STATIC : (CubeGrid.GridSizeEnum == MyCubeSize.Large ? RigidBodyFlag.RBF_DOUBLED_KINEMATIC : RigidBodyFlag.RBF_DEFAULT)); HkCylinderShape shape = new HkCylinderShape(Vector3.Zero, new Vector3(0, 0, 2), CubeGrid.GridSize / 2); var mass = HkInertiaTensorComputer.ComputeCylinderVolumeMassProperties(Vector3.Zero, Vector3.One, 1, 40.0f * CubeGrid.GridSize); subpart.Physics.CreateFromCollisionObject(shape, Vector3.Zero, subpart.WorldMatrix, mass); shape.Base.RemoveReference(); subpart.Physics.RigidBody.Layer = CubeGrid.Physics.RigidBody.Layer; if (subpart.Physics.RigidBody2 != null) { subpart.Physics.RigidBody2.Layer = MyPhysics.KinematicDoubledCollisionLayer; } m_subpartsFixedData = new HkFixedConstraintData(); m_subpartsFixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); float res; var x = m_subpartsFixedData.GetInertiaStabilizationFactor(out res); m_subpartsFixedData.SetInertiaStabilizationFactor(1); var matAD = MatrixD.CreateWorld(Position * CubeGrid.GridSize + Vector3D.Transform(Vector3D.Transform(m_subpartsConstraintPos, WorldMatrix), CubeGrid.PositionComp.LocalMatrix), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); matAD.Translation = CubeGrid.Physics.WorldToCluster(matAD.Translation); var matA = (Matrix)matAD; var matB = subpart.PositionComp.LocalMatrix; m_subpartsFixedData.SetInWorldSpace(ref matA, ref matB, ref matB); var breakableData = new HkBreakableConstraintData(m_subpartsFixedData); //Dont dispose the fixed data or we wont have access to them breakableData.Threshold = BreakOffTreshold; m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, subpart.Physics.RigidBody, breakableData); m_subpartsConstraint.WantRuntime = true; m_posChanged = true; }
private void Attach(HkRigidBody body, Vector3 gearSpacePivot, Matrix otherBodySpacePivot) { if (CubeGrid.Physics.Enabled) { var entity = body.GetEntity(); Debug.Assert(m_attachedTo == null, "Already attached"); Debug.Assert(entity != null, "Landing gear is attached to body which has no entity"); Debug.Assert(m_constraint == null); if (m_attachedTo != null || entity == null || m_constraint != null) return; body.Activate(); CubeGrid.Physics.RigidBody.Activate(); m_attachedTo = entity; if (entity != null) { entity.OnPhysicsChanged += m_physicsChangedHandler; } this.OnPhysicsChanged += m_physicsChangedHandler; Matrix gearLocalSpacePivot = Matrix.Identity; gearLocalSpacePivot.Translation = gearSpacePivot; var fixedData = new HkFixedConstraintData(); if (MyFakes.OVERRIDE_LANDING_GEAR_INERTIA) { fixedData.SetInertiaStabilizationFactor(MyFakes.LANDING_GEAR_INTERTIA); } else { fixedData.SetInertiaStabilizationFactor(1); } fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); fixedData.SetInBodySpace(ref gearLocalSpacePivot, ref otherBodySpacePivot); HkConstraintData data = fixedData; if (MyFakes.LANDING_GEAR_BREAKABLE && BreakForce < MaxSolverImpulse) { var breakData = new HkBreakableConstraintData(fixedData); fixedData.Dispose(); breakData.Threshold = BreakForce; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = true; data = breakData; } if (!m_needsToRetryLock) StartSound(m_lockSound); m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, body, data); CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; LockMode = LandingGearMode.Locked; if (CanAutoLock) ResetAutolock(); OnConstraintAdded(GridLinkTypeEnum.Physical, entity); OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); var handle = StateChanged; if (handle != null) handle(true); } }
public void Attach(MyPistonTop topBlock, bool updateSync = false) { if (m_topBlock != null) Detach(); if (CubeGrid.Physics == null || SafeConstraint != null) return; UpdateAnimation(); Debug.Assert(SafeConstraint == null); if (CubeGrid.Physics.Enabled && topBlock != null) { m_topBlock = topBlock; m_topBlockId = topBlock.EntityId; if (updateSync) SyncObject.AttachTop(m_topBlock); m_topGrid = m_topBlock.CubeGrid; var rotorBody = m_topGrid.Physics.RigidBody; var matAD = MatrixD.CreateWorld(Vector3D.Transform(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), CubeGrid.PositionComp.WorldMatrixNormalizedInv), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); var matBD = MatrixD.CreateWorld(m_topBlock.Position * m_topBlock.CubeGrid.GridSize, m_topBlock.PositionComp.LocalMatrix.Forward, m_topBlock.PositionComp.LocalMatrix.Up); var matA = (Matrix)matAD; var matB = (Matrix)matBD; m_fixedData = new HkFixedConstraintData(); m_fixedData.SetInertiaStabilizationFactor(10); m_fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_fixedData.SetInBodySpace(ref matA, ref matB); var breakData = new HkBreakableConstraintData(m_fixedData); //Dont dispose the fixed data or we wont have access to them breakData.Threshold = BreakOffTreshold; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = false; m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, breakData); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_topBlock.Attach(this); OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid); m_conveyorEndpoint.Attach(topBlock.ConveyorEndpoint as MyAttachableConveyorEndpoint); } }
private void InitSubpartsPhysics() { var subpart = m_subpart1; if (subpart == null || CubeGrid.Physics == null) return; subpart.Physics = new MyPhysicsBody(subpart, CubeGrid.IsStatic ? RigidBodyFlag.RBF_STATIC : (CubeGrid.GridSizeEnum == MyCubeSize.Large ? RigidBodyFlag.RBF_DOUBLED_KINEMATIC : RigidBodyFlag.RBF_DEFAULT)); HkCylinderShape shape = new HkCylinderShape(Vector3.Zero, new Vector3(0, 0, 2), CubeGrid.GridSize / 2); var mass = HkInertiaTensorComputer.ComputeCylinderVolumeMassProperties(Vector3.Zero, Vector3.One, 1, 40.0f*CubeGrid.GridSize); subpart.Physics.CreateFromCollisionObject(shape, Vector3.Zero, subpart.WorldMatrix, mass); shape.Base.RemoveReference(); subpart.Physics.RigidBody.Layer = CubeGrid.Physics.RigidBody.Layer; if (subpart.Physics.RigidBody2 != null) subpart.Physics.RigidBody2.Layer = MyPhysics.KinematicDoubledCollisionLayer; m_subpartsFixedData = new HkFixedConstraintData(); m_subpartsFixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); float res; var x = m_subpartsFixedData.GetInertiaStabilizationFactor(out res); m_subpartsFixedData.SetInertiaStabilizationFactor(1); var matAD = MatrixD.CreateWorld(Position * CubeGrid.GridSize + Vector3D.Transform(Vector3D.Transform(m_subpartsConstraintPos, WorldMatrix), CubeGrid.PositionComp.LocalMatrix), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); matAD.Translation = CubeGrid.Physics.WorldToCluster(matAD.Translation); var matA = (Matrix)matAD; var matB = subpart.PositionComp.LocalMatrix; m_subpartsFixedData.SetInWorldSpace(ref matA, ref matB, ref matB); var breakableData = new HkBreakableConstraintData(m_subpartsFixedData); //Dont dispose the fixed data or we wont have access to them breakableData.Threshold = BreakOffTreshold; m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, subpart.Physics.RigidBody, breakableData); m_subpartsConstraint.WantRuntime = true; m_posChanged = true; }
private void Attach(MyEntity entity, Vector3 gearSpacePivot, Matrix otherBodySpacePivot) { if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled) { var body = entity.Physics.RigidBody; var handle = StateChanged; if (Sync.IsServer && entity is MyCubeGrid) { (entity as MyCubeGrid).OnGridSplit += CubeGrid_OnGridSplit; } if (MyFakes.WELD_LANDING_GEARS && CanWeldTo(entity, ref otherBodySpacePivot)) { if (m_attachedTo != null || entity == null) { return; } if (entity is MyVoxelBase) { if (CubeGrid.Physics.RigidBody.IsFixed == false) { CubeGrid.Physics.ConvertToStatic(); m_converted = true; } } else { MyWeldingGroups.Static.CreateLink(EntityId, CubeGrid, entity); } //OnConstraintAdded(GridLinkTypeEnum.LandingGear, entity); m_lockModeSync.Value = LandingGearMode.Locked; m_attachedTo = entity; m_attachedTo.OnPhysicsChanged += m_physicsChangedHandler; this.OnPhysicsChanged += m_physicsChangedHandler; if (CanAutoLock) { ResetAutolock(); } OnConstraintAdded(GridLinkTypeEnum.Physical, entity); //OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); if (!m_needsToRetryLock) { StartSound(m_lockSound); } if (handle != null) { handle(true); } return; } //var entity = body.GetBody().Entity; Debug.Assert(m_attachedTo == null, "Already attached"); Debug.Assert(entity != null, "Landing gear is attached to body which has no entity"); Debug.Assert(m_constraint == null); if (m_attachedTo != null || entity == null || m_constraint != null) { return; } body.Activate(); CubeGrid.Physics.RigidBody.Activate(); m_attachedTo = entity; m_attachedTo.OnPhysicsChanged += m_physicsChangedHandler; this.OnPhysicsChanged += m_physicsChangedHandler; Matrix gearLocalSpacePivot = Matrix.Identity; gearLocalSpacePivot.Translation = gearSpacePivot; var fixedData = new HkFixedConstraintData(); if (MyFakes.OVERRIDE_LANDING_GEAR_INERTIA) { fixedData.SetInertiaStabilizationFactor(MyFakes.LANDING_GEAR_INTERTIA); } else { fixedData.SetInertiaStabilizationFactor(1); } fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); fixedData.SetInBodySpace(gearLocalSpacePivot, otherBodySpacePivot, CubeGrid.Physics, entity.Physics as MyPhysicsBody); HkConstraintData data = fixedData; if (MyFakes.LANDING_GEAR_BREAKABLE && BreakForce < MyObjectBuilder_LandingGear.MaxSolverImpulse) { var breakData = new HkBreakableConstraintData(fixedData); fixedData.Dispose(); breakData.Threshold = BreakForce; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = true; data = breakData; } if (!m_needsToRetryLock) { StartSound(m_lockSound); } m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, body, data); CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_lockModeSync.Value = LandingGearMode.Locked; if (CanAutoLock) { ResetAutolock(); } OnConstraintAdded(GridLinkTypeEnum.Physical, entity); OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); if (handle != null) { handle(true); } } }
private void Attach(MyEntity entity, Vector3 gearSpacePivot, Matrix otherBodySpacePivot) { if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled) { var handle = StateChanged; if (Sync.IsServer && entity is MyCubeGrid) { (entity as MyCubeGrid).OnGridSplit += CubeGrid_OnGridSplit; } if (MyFakes.WELD_LANDING_GEARS && CanWeldTo(entity, ref otherBodySpacePivot)) { if (m_attachedTo != null || entity == null) return; if (entity is MyVoxelBase) { if (CubeGrid.Physics.RigidBody.IsFixed == false) { CubeGrid.Physics.ConvertToStatic(); m_converted = true; } } else { MyEntity parent = entity.GetTopMostParent(); MyWeldingGroups.Static.CreateLink(EntityId, CubeGrid, parent); } //OnConstraintAdded(GridLinkTypeEnum.LandingGear, entity); m_lockModeSync.Value = LandingGearMode.Locked; m_attachedTo = entity; m_attachedTo.OnPhysicsChanged += m_physicsChangedHandler; this.OnPhysicsChanged += m_physicsChangedHandler; if (CanAutoLock) ResetAutolock(); OnConstraintAdded(GridLinkTypeEnum.Physical, entity); //OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); if (!m_needsToRetryLock) StartSound(m_lockSound); if (handle != null) handle(true); return; } //var entity = body.GetBody().Entity; Debug.Assert(m_attachedTo == null, "Already attached"); Debug.Assert(entity != null, "Landing gear is attached to body which has no entity"); Debug.Assert(m_constraint == null); if (m_attachedTo != null || entity == null || m_constraint != null) return; var body = entity.GetTopMostParent().Physics.RigidBody; body.Activate(); CubeGrid.Physics.RigidBody.Activate(); m_attachedTo = entity; m_attachedTo.OnPhysicsChanged += m_physicsChangedHandler; this.OnPhysicsChanged += m_physicsChangedHandler; Matrix gearLocalSpacePivot = Matrix.Identity; gearLocalSpacePivot.Translation = gearSpacePivot; var fixedData = new HkFixedConstraintData(); if (MyFakes.OVERRIDE_LANDING_GEAR_INERTIA) { fixedData.SetInertiaStabilizationFactor(MyFakes.LANDING_GEAR_INTERTIA); } else { fixedData.SetInertiaStabilizationFactor(1); } fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); fixedData.SetInBodySpace(gearLocalSpacePivot, otherBodySpacePivot, CubeGrid.Physics, entity.Physics as MyPhysicsBody); HkConstraintData data = fixedData; if (MyFakes.LANDING_GEAR_BREAKABLE && BreakForce < MyObjectBuilder_LandingGear.MaxSolverImpulse) { var breakData = new HkBreakableConstraintData(fixedData); fixedData.Dispose(); breakData.Threshold = BreakForce; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = true; data = breakData; } if (!m_needsToRetryLock) StartSound(m_lockSound); m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, body, data); CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_lockModeSync.Value = LandingGearMode.Locked; if (CanAutoLock) ResetAutolock(); OnConstraintAdded(GridLinkTypeEnum.Physical, entity); OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); if (handle != null) handle(true); } }
private void Attach(HkRigidBody body, Vector3 gearSpacePivot, Matrix otherBodySpacePivot) { if (CubeGrid.Physics.Enabled) { var entity = body.GetEntity(); Debug.Assert(m_attachedTo == null, "Already attached"); Debug.Assert(entity != null, "Landing gear is attached to body which has no entity"); Debug.Assert(m_constraint == null); if (m_attachedTo != null || entity == null || m_constraint != null) { return; } body.Activate(); CubeGrid.Physics.RigidBody.Activate(); m_attachedTo = entity; if (entity != null) { entity.OnPhysicsChanged += m_physicsChangedHandler; } this.OnPhysicsChanged += m_physicsChangedHandler; Matrix gearLocalSpacePivot = Matrix.Identity; gearLocalSpacePivot.Translation = gearSpacePivot; var fixedData = new HkFixedConstraintData(); if (MyFakes.OVERRIDE_LANDING_GEAR_INERTIA) { fixedData.SetInertiaStabilizationFactor(MyFakes.LANDING_GEAR_INTERTIA); } else { fixedData.SetInertiaStabilizationFactor(1); } fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); fixedData.SetInBodySpace(ref gearLocalSpacePivot, ref otherBodySpacePivot); HkConstraintData data = fixedData; if (MyFakes.LANDING_GEAR_BREAKABLE && BreakForce < MaxSolverImpulse) { var breakData = new HkBreakableConstraintData(fixedData); fixedData.Dispose(); breakData.Threshold = BreakForce; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = true; data = breakData; } if (!m_needsToRetryLock) { StartSound(m_lockSound); } m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, body, data); CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; LockMode = LandingGearMode.Locked; if (CanAutoLock) { ResetAutolock(); } OnConstraintAdded(GridLinkTypeEnum.Physical, entity); OnConstraintAdded(GridLinkTypeEnum.NoContactDamage, entity); var handle = StateChanged; if (handle != null) { handle(true); } } }
public void Attach(MyPistonTop topBlock) { if (CubeGrid == topBlock.CubeGrid) return; Debug.Assert(topBlock != null, "Top block cannot be null!"); Debug.Assert(m_constraint == null, "Contraint already attached, call detach first!"); Debug.Assert(m_topBlockId.Value == topBlock.EntityId, "m_topBlockId must be set prior calling Attach!"); UpdateAnimation(); if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled && topBlock.CubeGrid.Physics != null) { m_topBlock = topBlock; m_topGrid = m_topBlock.CubeGrid; var rotorBody = m_topGrid.Physics.RigidBody; var matAD = MatrixD.CreateWorld(Vector3D.Transform(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), CubeGrid.PositionComp.WorldMatrixNormalizedInv), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); var matBD = MatrixD.CreateWorld(m_topBlock.Position * m_topBlock.CubeGrid.GridSize, m_topBlock.PositionComp.LocalMatrix.Forward, m_topBlock.PositionComp.LocalMatrix.Up); var matA = (Matrix)matAD; var matB = (Matrix)matBD; m_fixedData = new HkFixedConstraintData(); m_fixedData.SetInertiaStabilizationFactor(10); m_fixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_fixedData.SetInBodySpace(matA, matB, CubeGrid.Physics, m_topGrid.Physics); var breakData = new HkBreakableConstraintData(m_fixedData); //Dont dispose the fixed data or we wont have access to them breakData.Threshold = BreakOffTreshold; breakData.ReapplyVelocityOnBreak = true; breakData.RemoveFromWorldOnBrake = false; m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, breakData); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); if(!m_constraint.InWorld) { Debug.Fail("Constraint was not added to world"); CubeGrid.Physics.RemoveConstraint(m_constraint); m_constraint.Dispose(); m_constraint = null; m_fixedData.Dispose(); m_fixedData = null; return; } m_constraint.Enabled = true; m_topBlock.Attach(this); m_topGrid.OnPhysicsChanged += CubeGrid_OnPhysicsChanged; OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid); m_conveyorEndpoint.Attach(topBlock.ConveyorEndpoint as MyAttachableConveyorEndpoint); UpdateText(); } }
private void CheckSubpartConstraint() { if(m_subpartsConstraint != null && (m_subpartsConstraint.RigidBodyA == null)) { if (m_subPartContraintInScene) { m_subPartContraintInScene = false; CubeGrid.Physics.RemoveConstraint(m_subpartsConstraint); } m_subpartsConstraint.Dispose(); m_subpartsConstraint = null; var breakableData = new HkBreakableConstraintData(m_subpartsFixedData); //Dont dispose the fixed data or we wont have access to them breakableData.Threshold = BreakOffTreshold; m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_subpart1.Physics.RigidBody, breakableData); Debug.Assert(m_subpartsConstraint.RigidBodyA != null); m_subpartsConstraint.WantRuntime = true; } }