public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); PowerReceiver = new MyPowerReceiver( MyConsumerGroupEnum.Utility, false, BlockDefinition.RequiredPowerInput, this.CalculateRequiredPowerInput); PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged; PowerReceiver.Update(); if (Physics != null) { Physics.Close(); } var detectorShape = new HkBoxShape(new Vector3(cubeGrid.GridSize / 3.0f)); var massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(detectorShape.HalfExtents, BlockDefinition.VirtualMass); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT); Physics.IsPhantom = false; Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.VirtualMassLayer); Physics.Enabled = IsWorking && cubeGrid.Physics != null && cubeGrid.Physics.Enabled; Physics.RigidBody.Activate(); detectorShape.Base.RemoveReference(); UpdateText(); NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
private void LoadDummies() { var finalModel = Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (dummy.Key.ToLower().Contains("detector_shiptool")) { var matrix = dummy.Value.Matrix; float radius = matrix.Scale.AbsMin(); Matrix blockMatrix = this.PositionComp.LocalMatrix; Vector3 gridDetectorPosition = Vector3.Transform(matrix.Translation, blockMatrix); m_detectorSphere = new BoundingSphere(gridDetectorPosition, radius); var phantom = new HkPhantomCallbackShape(phantom_Enter, phantom_Leave); var sphereShape = new HkSphereShape(radius); var detectorShape = new HkBvShape(sphereShape, phantom, HkReferencePolicy.TakeOwnership); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, WorldMatrix, null, MyPhysics.ObjectDetectionCollisionLayer); detectorShape.Base.RemoveReference(); break; } } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { InitializeSinkComponent(); base.Init(objectBuilder, cubeGrid); if (CubeGrid.CreatePhysics) { // Put on my fake, because it does performance issues if (MyFakes.ENABLE_GRAVITY_PHANTOM) { var shape = CreateFieldShape(); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, WorldMatrix, null, Sandbox.Engine.Physics.MyPhysics.CollisionLayers.GravityPhantomLayer); shape.Base.RemoveReference(); Physics.Enabled = IsWorking; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; ResourceSink.Update(); } m_soundEmitter = new MyEntity3DSoundEmitter(this); m_baseIdleSound.Init("BlockGravityGen"); }
private void LoadDummies() { var finalModel = Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (dummy.Key.ToLower().Contains("merge")) { var matrix = dummy.Value.Matrix; Vector3 halfExtents = matrix.Scale / 2.0f; Vector3 projectedPosition = Vector3.DominantAxisProjection(matrix.Translation / halfExtents); projectedPosition.Normalize(); m_forward = Base6Directions.GetDirection(projectedPosition); m_right = Base6Directions.GetPerpendicular(m_forward); var world = MatrixD.Normalize(matrix) * this.WorldMatrix; var detectorShape = CreateFieldShape(halfExtents); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, world, null, MyPhysics.ObjectDetectionCollisionLayer); Physics.Enabled = IsWorking; Physics.RigidBody.ContactPointCallbackEnabled = true; detectorShape.Base.RemoveReference(); break; } } }
private void RefreshPhysicsBody() { if (CubeGrid.CreatePhysics) { if (Physics != null) { Physics.Close(); } var detectorShape = new HkSphereShape(CubeGrid.GridSize * 0.5f); var massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(detectorShape.Radius, VirtualMass != 0 ? VirtualMass : 0.01f); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KEYFRAMED_REPORTING); Physics.IsPhantom = false; Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.CollisionLayers.VirtualMassLayer); UpdateIsWorking(); Physics.Enabled = IsWorking && CubeGrid.Physics != null && CubeGrid.Physics.Enabled; Physics.RigidBody.Activate(); detectorShape.Base.RemoveReference(); if (CubeGrid != null && CubeGrid.Physics != null && !CubeGrid.IsStatic) { CubeGrid.Physics.UpdateMass(); } } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); PowerReceiver = new MyPowerReceiver( MyConsumerGroupEnum.Utility, false, BlockDefinition.RequiredPowerInput, this.CalculateRequiredPowerInput); PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged; PowerReceiver.Update(); if (Physics != null) { Physics.Close(); } var detectorShape = new HkBoxShape(new Vector3(cubeGrid.GridSize / 3.0f)); var massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(detectorShape.HalfExtents, BlockDefinition.VirtualMass); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT); Physics.IsPhantom = false; Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.VirtualMassLayer); Physics.Enabled = IsWorking && cubeGrid.Physics != null && cubeGrid.Physics.Enabled; Physics.RigidBody.Activate(); detectorShape.Base.RemoveReference(); UpdateText(); NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
internal void SetupPhysics(bool isLocalPlayer) { Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = false; Vector3 center = PositionComp.LocalVolume.Center; Physics.CreateFromCollisionObject(new HkSphereShape(PLAYER_TARGET_SIZE), center, WorldMatrix, null, 0); Physics.Enabled = true; Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; Physics.RigidBody.ContactPointCallbackEnabled = true; PositionComp.LocalAABB = new BoundingBox(new Vector3(-PLAYER_TARGET_SIZE), new Vector3(PLAYER_TARGET_SIZE)); }
public void InitFromDefinition(MyObjectBuilder_EntityBase entityBuilder, MyDefinitionId definitionId) { Debug.Assert(entityBuilder != null, "Invalid arguments!"); MyPhysicalItemDefinition entityDefinition; if (!MyDefinitionManager.Static.TryGetDefinition(definitionId, out entityDefinition)) { Debug.Fail("Definition: " + DefinitionId.ToString() + " was not found!"); return; } DefinitionId = definitionId; Flags |= EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.Sync | EntityFlags.InvalidateOnMove; StringBuilder name = new StringBuilder(entityDefinition.DisplayNameText); Init(name, entityDefinition.Model, null, null, null); CreateSync(); if (entityBuilder.PositionAndOrientation.HasValue) { MatrixD worldMatrix = MatrixD.CreateWorld( (Vector3D)entityBuilder.PositionAndOrientation.Value.Position, (Vector3)entityBuilder.PositionAndOrientation.Value.Forward, (Vector3)entityBuilder.PositionAndOrientation.Value.Up); PositionComp.SetWorldMatrix(worldMatrix); } Name = name.Append("_(").Append(entityBuilder.EntityId).Append(")").ToString(); Render.UpdateRenderObject(true); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT); if (ModelCollision != null && ModelCollision.HavokCollisionShapes.Length >= 1) { HkMassProperties massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(entityDefinition.Size / 2, (MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(entityDefinition.Mass) : entityDefinition.Mass));; Physics.CreateFromCollisionObject(ModelCollision.HavokCollisionShapes[0], Vector3.Zero, WorldMatrix, massProperties); Physics.RigidBody.AngularDamping = 2; Physics.RigidBody.LinearDamping = 1; } Physics.Enabled = true; EntityId = entityBuilder.EntityId; }
private void LoadDummies() { var finalModel = VRage.Game.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (dummy.Key.ToLower().Contains("collector")) { var matrix = dummy.Value.Matrix; Vector3 halfExtents, position; Quaternion orientation; GetBoxFromMatrix(matrix, out halfExtents, out position, out orientation); //difference is small but colision detection seems more stable //if (false) //{ // var detectorShape = new HkBoxShape(halfExtents); // Physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_STATIC); // Physics.IsPhantom = true; // //Physics.ReportAllContacts = true; // Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, WorldMatrix, null, MyPhysics.CollisionLayers.CollectorCollisionLayer); // Physics.Enabled = IsWorking; // Physics.RigidBody.ContactPointCallbackEnabled = true; // Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; // detectorShape.Base.RemoveReference(); //} //else { var detectorShape = CreateFieldShape(halfExtents); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, WorldMatrix, null, MyPhysics.CollisionLayers.CollectorCollisionLayer); Physics.Enabled = true;//IsWorking; Physics.RigidBody.ContactPointCallbackEnabled = false; //Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; detectorShape.Base.RemoveReference(); } break; } } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); if (CubeGrid.CreatePhysics) { MyGravityProviderSystem.AddGravityGenerator(this); // Put on my fake, because it does performance issues if (MyFakes.ENABLE_GRAVITY_PHANTOM) { var shape = CreateFieldShape(); Physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, WorldMatrix, null, Sandbox.Engine.Physics.MyPhysics.GravityPhantomLayer); shape.Base.RemoveReference(); Physics.Enabled = IsWorking; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); if (CubeGrid.CreatePhysics) { MyGravityProviderSystem.AddGravityGenerator(this); // Put on my fake, because it does performance issues if (MyFakes.ENABLE_GRAVITY_PHANTOM) { var shape = CreateFieldShape(); Physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, WorldMatrix, null, Sandbox.Engine.Physics.MyPhysics.GravityPhantomLayer); shape.Base.RemoveReference(); Physics.Enabled = IsWorking; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { InitializeSinkComponent(); base.Init(objectBuilder, cubeGrid); if (CubeGrid.CreatePhysics) { // Put on my fake, because it does performance issues if (MyFakes.ENABLE_GRAVITY_PHANTOM) { var shape = CreateFieldShape(); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, WorldMatrix, null, Sandbox.Engine.Physics.MyPhysics.CollisionLayers.GravityPhantomLayer); shape.Base.RemoveReference(); Physics.Enabled = IsWorking; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; ResourceSink.Update(); } m_soundEmitter = new MyEntity3DSoundEmitter(this); m_baseIdleSound.Init("BlockGravityGen"); }
private void LoadDummies() { var finalModel = Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (dummy.Key.ToLower().Contains("collector")) { var matrix = dummy.Value.Matrix; Vector3 halfExtents, position; Quaternion orientation; GetBoxFromMatrix(matrix, out halfExtents, out position, out orientation); //difference is small but colision detection seems more stable //if (false) //{ // var detectorShape = new HkBoxShape(halfExtents); // Physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_STATIC); // Physics.IsPhantom = true; // //Physics.ReportAllContacts = true; // Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, WorldMatrix, null, MyPhysics.CollectorCollisionLayer); // Physics.Enabled = IsWorking; // Physics.RigidBody.ContactPointCallbackEnabled = true; // Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; // detectorShape.Base.RemoveReference(); //} //else { var detectorShape = CreateFieldShape(halfExtents); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, WorldMatrix, null, MyPhysics.CollectorCollisionLayer); Physics.Enabled = true;//IsWorking; Physics.RigidBody.ContactPointCallbackEnabled = false; //Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; detectorShape.Base.RemoveReference(); } break; } } }
private MyPhysicsBody CreatePhysicsBody(Mode mode, ref MatrixD dummyLocal, ref Vector3 center, ref Vector3 halfExtents) { // Only create physical shape for ejectors (on client and server) and for connectors on the server MyPhysicsBody physics = null; if (mode == Mode.Ejector || Sync.IsServer) { var detectorShape = CreateDetectorShape(halfExtents, mode); if (mode == Mode.Connector) { physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_BULLET); physics.IsPhantom = true; physics.CreateFromCollisionObject(detectorShape, center, dummyLocal, null, MyPhysics.ObjectDetectionCollisionLayer); } else { physics = new Engine.Physics.MyPhysicsBody(this, Engine.Physics.RigidBodyFlag.RBF_STATIC); physics.IsPhantom = true; physics.CreateFromCollisionObject(detectorShape, center, dummyLocal, null, MyPhysics.CollectorCollisionLayer); } physics.RigidBody.ContactPointCallbackEnabled = true; detectorShape.Base.RemoveReference(); } return physics; }
private void RefreshPhysicsBody() { if (CubeGrid.CreatePhysics) { if (Physics != null) { Physics.Close(); } var detectorShape = new HkSphereShape(CubeGrid.GridSize * 0.5f); var massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(detectorShape.Radius, VirtualMass != 0 ? VirtualMass : 0.01f); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KEYFRAMED_REPORTING); Physics.IsPhantom = false; Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.CollisionLayers.VirtualMassLayer); UpdateIsWorking(); Physics.Enabled = IsWorking && CubeGrid.Physics != null && CubeGrid.Physics.Enabled; Physics.RigidBody.Activate(); detectorShape.Base.RemoveReference(); if (CubeGrid != null && CubeGrid.Physics != null && !CubeGrid.IsStatic) CubeGrid.Physics.UpdateMass(); } }
private void LoadDummies() { var finalModel = Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (dummy.Key.ToLower().Contains("merge")) { var matrix = dummy.Value.Matrix; Vector3 halfExtents = matrix.Scale / 2.0f; Vector3 projectedPosition = Vector3.DominantAxisProjection(matrix.Translation / halfExtents); projectedPosition.Normalize(); m_forward = Base6Directions.GetDirection(projectedPosition); m_right = Base6Directions.GetPerpendicular(m_forward); var world = MatrixD.Normalize(matrix) * this.WorldMatrix; var detectorShape = CreateFieldShape(halfExtents); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC); Physics.IsPhantom = true; Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, world, null, MyPhysics.DefaultCollisionLayer); Physics.Enabled = IsWorking; Physics.RigidBody.ContactPointCallbackEnabled = true; detectorShape.Base.RemoveReference(); break; } } }
internal void SetupPhysics(bool isLocalPlayer) { Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_KINEMATIC); Physics.IsPhantom = false; Vector3 center = PositionComp.LocalVolume.Center; Physics.CreateFromCollisionObject(new HkSphereShape(PLAYER_TARGET_SIZE), center, WorldMatrix, null, 0); Physics.Enabled = true; Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback; Physics.RigidBody.ContactPointCallbackEnabled = true; PositionComp.LocalAABB = new BoundingBox(new Vector3(-PLAYER_TARGET_SIZE), new Vector3(PLAYER_TARGET_SIZE)); }
public void InitFromDefinition(MyObjectBuilder_EntityBase entityBuilder, MyDefinitionId definitionId) { Debug.Assert(entityBuilder != null, "Invalid arguments!"); MyPhysicalItemDefinition entityDefinition; if (!MyDefinitionManager.Static.TryGetDefinition(definitionId, out entityDefinition)) { Debug.Fail("Definition: " + DefinitionId.ToString() + " was not found!"); return; } DefinitionId = definitionId; Flags |= EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.Sync | EntityFlags.InvalidateOnMove; StringBuilder name = new StringBuilder(entityDefinition.DisplayNameText); Init(name, entityDefinition.Model, null, null, null); CreateSync(); if (entityBuilder.PositionAndOrientation.HasValue) { MatrixD worldMatrix = MatrixD.CreateWorld( (Vector3D)entityBuilder.PositionAndOrientation.Value.Position, (Vector3)entityBuilder.PositionAndOrientation.Value.Forward, (Vector3)entityBuilder.PositionAndOrientation.Value.Up); PositionComp.SetWorldMatrix(worldMatrix); } Name = name.Append("_(").Append(entityBuilder.EntityId).Append(")").ToString(); Render.UpdateRenderObject(true); Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT); if (ModelCollision != null && ModelCollision.HavokCollisionShapes.Length >= 1) { HkMassProperties massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(entityDefinition.Size / 2, (MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(entityDefinition.Mass) : entityDefinition.Mass)); ; Physics.CreateFromCollisionObject(ModelCollision.HavokCollisionShapes[0], Vector3.Zero, WorldMatrix, massProperties); Physics.RigidBody.AngularDamping = 2; Physics.RigidBody.LinearDamping = 1; } Physics.Enabled = true; EntityId = entityBuilder.EntityId; }