private HkConstraintData CreateFixedConstraintData(ref Matrix otherLocalMatrix, float headDistance) { m_fixedConstraintData = new HkFixedConstraintData(); Matrix headPivotLocalMatrix; GetHeadPivotLocalMatrix(headDistance, out headPivotLocalMatrix); m_fixedConstraintData.SetInBodySpace(otherLocalMatrix, headPivotLocalMatrix, m_otherPhysicsBody, OwnerVirtualPhysics); if (MyFakes.MANIPULATION_TOOL_VELOCITY_LIMIT) { m_fixedConstraintData.MaximumLinearImpulse = 0.5f; m_fixedConstraintData.MaximumAngularImpulse = 0.5f; HkMalleableConstraintData mcData = new HkMalleableConstraintData(); mcData.SetData(m_fixedConstraintData); mcData.Strength = 0.0001f; m_fixedConstraintData.Dispose(); return(mcData); } else { m_fixedConstraintData.MaximumLinearImpulse = 0.005f; //7500 * MyDestructionHelper.MASS_REDUCTION_COEF * (MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED); m_fixedConstraintData.MaximumAngularImpulse = 0.005f; //7500 * MyDestructionHelper.MASS_REDUCTION_COEF * (MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED); } return(m_fixedConstraintData); //HkBreakableConstraintData bcData = new HkBreakableConstraintData(m_fixedConstraintData); //bcData.ReapplyVelocityOnBreak = false; //bcData.RemoveFromWorldOnBrake = true; //bcData.Threshold = /*100000;*/ 2500 * MyDestructionHelper.MASS_REDUCTION_COEF; //return bcData; }
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); }
private HkConstraintData CreateBallAndSocketConstraintData(ref Matrix otherLocalMatrix, ref Matrix headPivotLocalMatrix) { HkBallAndSocketConstraintData data = new HkBallAndSocketConstraintData(); Vector3 otherPivot = otherLocalMatrix.Translation; Vector3 headPivot = headPivotLocalMatrix.Translation; data.SetInBodySpace(otherPivot, headPivot, m_otherPhysicsBody, OwnerVirtualPhysics); HkMalleableConstraintData mcData = new HkMalleableConstraintData(); mcData.SetData(data); mcData.Strength = 0.00006f; data.Dispose(); return(mcData); }
private static HkConstraintData CreateBallAndSocketConstraintData(ref Matrix otherLocalMatrix, ref Matrix headPivotLocalMatrix) { HkBallAndSocketConstraintData data = new HkBallAndSocketConstraintData(); Vector3 otherPivot = otherLocalMatrix.Translation; Vector3 headPivot = headPivotLocalMatrix.Translation; data.SetInBodySpace(ref otherPivot, ref headPivot); HkMalleableConstraintData mcData = new HkMalleableConstraintData(); mcData.SetData(data); mcData.Strength = 0.0003f; data.Dispose(); return(mcData); }
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); }
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 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); }
void CubeGrid_OnPhysicsChanged(MyEntity obj) { if (Sync.IsServer && m_welding == false && InConstraint && m_welded == false) { if (m_hasConstraint) { if (MyPhysicsBody.IsConstraintValid(m_constraint) == false && m_constraint.IsDisposed == false) { RemoveConstraint(m_other, m_constraint); this.m_constraint = null; m_other.m_constraint = null; m_hasConstraint = false; m_other.m_hasConstraint = false; if (m_connectionState.Value.MasterToSlave.HasValue == false && CubeGrid.Physics != null && m_other.CubeGrid.Physics != null) { var posA = ConstraintPositionInGridSpace(); var posB = m_other.ConstraintPositionInGridSpace(); var axisA = ConstraintAxisGridSpace(); var axisB = -m_other.ConstraintAxisGridSpace(); var data = new HkHingeConstraintData(); data.SetInBodySpace(posA, posB, axisA, axisB, CubeGrid.Physics, m_other.CubeGrid.Physics); var data2 = new HkMalleableConstraintData(); data2.SetData(data); data.ClearHandle(); data = null; data2.Strength = GetEffectiveStrength(m_other); var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_other.CubeGrid.Physics.RigidBody, data2); this.SetConstraint(m_other, newConstraint); m_other.SetConstraint(this, newConstraint); AddConstraint(newConstraint); } } } } }
void CubeGrid_OnPhysicsChanged(MyEntity obj) { if (m_hasConstraint) { if (MyPhysicsBody.IsConstraintValid(m_constraint) == false && m_constraint.IsDisposed == false) { RemoveConstraint(m_other, m_constraint); if (m_connectionState.Value.MasterToSlave.HasValue) { Matrix localSpaceA = Matrix.CreateTranslation(m_connectionPosition); Matrix localSpaceB = localSpaceA * m_connectionState.Value.MasterToSlave.Value; localSpaceA = localSpaceA * this.PositionComp.LocalMatrix; localSpaceB = localSpaceB * m_other.PositionComp.LocalMatrix; var data = new HkFixedConstraintData(); data.SetInBodySpace(localSpaceA, localSpaceB, CubeGrid.Physics, m_other.CubeGrid.Physics); var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_other.CubeGrid.Physics.RigidBody, data); this.SetConstraint(m_other, newConstraint); m_other.SetConstraint(this, newConstraint); AddConstraint(newConstraint); } else { var posA = ConstraintPositionInGridSpace(); var posB = m_other.ConstraintPositionInGridSpace(); var axisA = ConstraintAxisGridSpace(); var axisB = -m_other.ConstraintAxisGridSpace(); var data = new HkHingeConstraintData(); data.SetInBodySpace(posA, posB, axisA, axisB, CubeGrid.Physics, m_other.CubeGrid.Physics); var data2 = new HkMalleableConstraintData(); data2.SetData(data); data.ClearHandle(); data = null; data2.Strength = GetEffectiveStrength(m_other); var newConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_other.CubeGrid.Physics.RigidBody, data2); this.SetConstraint(m_other, newConstraint); m_other.SetConstraint(this, newConstraint); AddConstraint(newConstraint); } } } }