public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true) { if (CubeGrid.Physics == null || SafeConstraint != null) { return(false); } Debug.Assert(SafeConstraint == null); if (CubeGrid.Physics.Enabled && rotor != null) { m_rotorBlock = rotor; m_rotorBlockId = rotor.EntityId; if (updateSync) { SyncObject.AttachRotor(m_rotorBlock); } m_rotorGrid = m_rotorBlock.CubeGrid; if (m_rotorGrid.Physics == null) { return(false); } var rotorBody = m_rotorGrid.Physics.RigidBody; var data = new HkLimitedHingeConstraintData(); m_motor = new HkVelocityConstraintMotor(1.0f, 1000000f); data.SetSolvingMethod(HkSolvingMethod.MethodStabilized); data.Motor = m_motor; data.DisableLimits(); var posA = DummyPosition; var posB = rotor.Position * rotor.CubeGrid.GridSize; var axisA = PositionComp.LocalMatrix.Up; var axisAPerp = PositionComp.LocalMatrix.Forward; var axisB = rotor.PositionComp.LocalMatrix.Up; var axisBPerp = rotor.PositionComp.LocalMatrix.Forward; data.SetInBodySpace(ref posA, ref posB, ref axisA, ref axisB, ref axisAPerp, ref axisBPerp); m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, data); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; SetAngleToPhysics(); m_rotorBlock.Attach(this); if (updateGroup) { OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid); } m_isAttached = true; return(true); } return(false); }
public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true) { if (CubeGrid.Physics == null || SafeConstraint != null) { return(false); } Debug.Assert(SafeConstraint == null); if (CubeGrid.Physics.Enabled && rotor != null) { m_rotorBlock = rotor; m_rotorBlockId = rotor.EntityId; if (updateSync) { SyncObject.AttachRotor(m_rotorBlock); } m_rotorGrid = m_rotorBlock.CubeGrid; var rotorBody = m_rotorGrid.Physics.RigidBody; HkWheelConstraintData data = new HkWheelConstraintData(); var suspensionAx = PositionComp.LocalMatrix.Forward; var posA = DummyPosition + (suspensionAx * m_height); var posB = rotor.DummyPosLoc; var axisA = PositionComp.LocalMatrix.Up; var axisAPerp = PositionComp.LocalMatrix.Forward; var axisB = rotor.PositionComp.LocalMatrix.Up; //empirical values because who knows what havoc sees behind this //docs say one value should mean same effect for 2 ton or 200 ton vehicle //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity data.SetSuspensionDamping(Damping); data.SetSuspensionStrength(Strength); //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel); data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel); data.SetInBodySpace(ref posB, ref posA, ref axisB, ref axisA, ref suspensionAx, ref suspensionAx); m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_rotorBlock.Attach(this); UpdateIsWorking(); if (updateGroup) { OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid); } return(true); } return(false); }
public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true) { if (CubeGrid.Physics == null || SafeConstraint != null) { return(false); } Debug.Assert(SafeConstraint == null); if (CubeGrid.Physics.Enabled && rotor != null) { m_rotorBlock = rotor; m_rotorBlockId = rotor.EntityId; if (updateSync) { SyncObject.AttachRotor(m_rotorBlock); } m_rotorGrid = m_rotorBlock.CubeGrid; var rotorBody = m_rotorGrid.Physics.RigidBody; rotorBody.MaxAngularVelocity = float.MaxValue; rotorBody.AngularDamping *= 4; if (MyFakes.WHEEL_SOFTNESS) { HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio, MyPhysicsConfig.WheelSoftnessVelocity); } var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer, CubeGrid.Physics.HavokCollisionSystemID, 1, 1); rotorBody.SetCollisionFilterInfo(info); HkWheelConstraintData data = new HkWheelConstraintData(); var suspensionAx = PositionComp.LocalMatrix.Forward; var posA = DummyPosition + (suspensionAx * m_height); var posB = rotor.DummyPosLoc; var axisA = PositionComp.LocalMatrix.Up; var axisAPerp = PositionComp.LocalMatrix.Forward; var axisB = rotor.PositionComp.LocalMatrix.Up; //empirical values because who knows what havoc sees behind this //docs say one value should mean same effect for 2 ton or 200 ton vehicle //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity data.SetSuspensionDamping(Damping); data.SetSuspensionStrength(Strength); //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel); data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel); data.SetInBodySpace(posB, posA, axisB, axisA, suspensionAx, suspensionAx, RotorGrid.Physics, CubeGrid.Physics); m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data); m_constraint.WantRuntime = true; CubeGrid.Physics.AddConstraint(m_constraint); m_constraint.Enabled = true; m_rotorBlock.Attach(this); PropagateFriction(m_friction); UpdateIsWorking(); if (updateGroup) { OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid); OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid); } return(true); } return(false); }