private void RecreateConstraints(VRage.Game.Entity.MyEntity obj, bool refreshInPlace) { if ((((((obj != null) && !obj.MarkedForClose) && (obj.GetPhysicsBody() != null)) && (!obj.IsPreview && (base.CubeGrid.Projector == null))) && ((this.m_leftSubpart == null) || (!this.m_leftSubpart.MarkedForClose && !this.m_leftSubpart.Closed))) && ((this.m_rightSubpart == null) || (!this.m_rightSubpart.MarkedForClose && !this.m_rightSubpart.Closed))) { Matrix?nullable; MyCubeGridRenderCell orAddCell = base.CubeGrid.RenderData.GetOrAddCell((Vector3)(base.Position * base.CubeGrid.GridSize), true); if (this.m_leftSubpart != null) { nullable = null; this.m_leftSubpart.Render.SetParent(0, orAddCell.ParentCullObject, nullable); } if (this.m_rightSubpart != null) { nullable = null; this.m_rightSubpart.Render.SetParent(0, orAddCell.ParentCullObject, nullable); } base.DisposeSubpartConstraint(ref this.m_leftConstraint, ref this.m_leftConstraintData); base.DisposeSubpartConstraint(ref this.m_rightConstraint, ref this.m_rightConstraintData); if ((base.InScene && (base.CubeGrid.Physics != null)) && (base.CubeGrid.Physics.IsInWorld || ((MyPhysicsBody)base.CubeGrid.Physics).IsInWorldWelded())) { this.CreateConstraints(); } if (obj.Physics != null) { this.UpdateHavokCollisionSystemID(obj.GetPhysicsBody().HavokCollisionSystemID, refreshInPlace); } this.UpdateSlidingDoorsPosition(); } }
private void UpdateHavokCollisionSystemID(VRage.Game.Entity.MyEntity obj) { if ((((obj != null) && (!obj.MarkedForClose && (obj.GetPhysicsBody() != null))) && (this.m_subparts[0].GetPhysicsBody() != null)) && (obj.GetPhysicsBody().HavokCollisionSystemID != this.m_subparts[0].GetPhysicsBody().HavokCollisionSystemID)) { this.UpdateHavokCollisionSystemID(obj.GetPhysicsBody().HavokCollisionSystemID); } }
protected void CreateSubpartConstraint(VRage.Game.Entity.MyEntity subpart, out HkFixedConstraintData constraintData, out HkConstraint constraint) { constraintData = null; constraint = null; if (base.CubeGrid.Physics != null) { HkRigidBody rigidBody; uint info = HkGroupFilter.CalcFilterInfo(subpart.GetPhysicsBody().RigidBody.Layer, base.CubeGrid.GetPhysicsBody().HavokCollisionSystemID, 1, 1); subpart.Physics.RigidBody.SetCollisionFilterInfo(info); subpart.Physics.Enabled = true; constraintData = new HkFixedConstraintData(); constraintData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); constraintData.SetInertiaStabilizationFactor(1f); if ((base.CubeGrid.Physics.RigidBody2 == null) || !base.CubeGrid.Physics.Flags.HasFlag(RigidBodyFlag.RBF_DOUBLED_KINEMATIC)) { rigidBody = base.CubeGrid.Physics.RigidBody; } else { rigidBody = base.CubeGrid.Physics.RigidBody2; } constraint = new HkConstraint(rigidBody, subpart.Physics.RigidBody, constraintData); constraint.WantRuntime = true; } }
bool GetPropertiesFromEntity(MyEntity entity,ref Vector3D position1, out Quaternion rotation2, out Vector3 posDiff, out HkShape? shape2) { rotation2 = new Quaternion(); posDiff = Vector3.Zero; shape2 = null; if (entity.Physics == null || !entity.Physics.Enabled) { return false; } if (entity.Physics.RigidBody != null) { shape2 = entity.Physics.RigidBody.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; if (entity is MyVoxelBase) { var voxel = entity as MyVoxelBase; posDiff -= voxel.Size / 2; } } else if (entity.GetPhysicsBody().CharacterProxy != null) { shape2 = entity.GetPhysicsBody().CharacterProxy.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; } else { return false; } return true; }