• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Physics.MyPhysicsBody类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Sandbox.Engine.Physics.MyPhysicsBody的典型用法代码示例。如果您正苦于以下问题:C# MyPhysicsBody类的具体用法?C# MyPhysicsBody怎么用?C# MyPhysicsBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MyPhysicsBody类属于Sandbox.Engine.Physics命名空间,在下文中一共展示了MyPhysicsBody类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Init

        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            ResourceSink = new MyResourceSinkComponent();
            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);

            base.Init(objectBuilder, cubeGrid);

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.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 Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
            Physics.IsPhantom = false;
            Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.CollisionLayers.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;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:33,代码来源:MyVirtualMass.cs


示例2: MyCameraSpring

 public MyCameraSpring(MyPhysicsBody attachedTo)
 {
     m_limitedVelocity = Vector3.Zero;
     m_physics = attachedTo;
     m_linearVelocity = Vector3.Zero;
     m_localTranslation = Vector3.Zero;
 }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:7,代码来源:MyCameraSpring.cs


示例3: Init

        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 Sandbox.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, true);
            m_baseIdleSound.Init("BlockGravityGen");
			
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:25,代码来源:MyGravityGeneratorBase.cs


示例4: SetInBodySpace

        public static void SetInBodySpace(this HkFixedConstraintData data, Matrix pivotA, Matrix pivotB, MyPhysicsBody bodyA, MyPhysicsBody bodyB)
        {
            if (bodyA.IsWelded)
                pivotA = pivotA * bodyA.WeldInfo.Transform;
            if (bodyB.IsWelded)
                pivotB = pivotB * bodyB.WeldInfo.Transform;

            data.SetInBodySpaceInternal(ref pivotA, ref pivotB);
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:9,代码来源:MyPhysicsExtensions.Constraints.cs


示例5: InitInternal

        private void InitInternal()
        {
            base.Init(null, m_definition.Model, null, null);
            Render.ColorMaskHsv = m_definition.ColorHSV;
            Render.Transparency = 0.25f;
            Render.AddRenderObjects();

			List<MyTextureChange> textureChanges = new List<MyTextureChange>();
			textureChanges.Add(new MyTextureChange { TextureName = m_definition.ColorMetalTexture, MaterialSlot = "ColorMetalTexture" });
			textureChanges.Add(new MyTextureChange { TextureName = m_definition.AddMapsTexture, MaterialSlot = "AddMapsTexture" });

            VRageRender.MyRenderProxy.ChangeMaterialTexture(Render.RenderObjectIDs[0], "BotFlag", textureChanges); // TODO: change the material name

            m_localActivationMatrix = MatrixD.CreateScale(this.PositionComp.LocalAABB.HalfExtents * 2.0f) * MatrixD.CreateTranslation(this.PositionComp.LocalAABB.Center);

            var shape = new HkBoxShape(m_localActivationMatrix.Scale);
            Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DISABLE_COLLISION_RESPONSE);
            Physics.CreateFromCollisionObject(shape, Vector3.Zero, WorldMatrix, null, MyPhysics.ObjectDetectionCollisionLayer);
            Physics.Enabled = true;

            Components.Add<MyPlaceArea>(new MySpherePlaceArea(10.0f, m_definition.Id.SubtypeId)); // TODO: Add radius to the definition

            MyHud.LocationMarkers.RegisterMarker(this, new MyHudEntityParams() {
                FlagsEnum = MyHudIndicatorFlagsEnum.SHOW_TEXT,
                Text = m_definition.DisplayNameEnum.HasValue ? MyTexts.Get(m_definition.DisplayNameEnum.Value) : new StringBuilder(),
                TargetMode = MyRelationsBetweenPlayerAndBlock.Neutral,
                MaxDistance = 200.0f,
                MustBeDirectlyVisible = true
            } );
        }
开发者ID:caomw,项目名称:SpaceEngineers,代码行数:30,代码来源:MyAreaMarker.cs


示例6: InitInternal

        private void InitInternal()
        {
            // TODO: This will be fixed and made much more simple once ore models are done
            // https://app.asana.com/0/6594565324126/10473934569658

            var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

            string model = physicalItem.Model;

            VoxelMaterial = null;
            float scale = 1.0f;

            if (Item.Content is MyObjectBuilder_Ore)
            {
                string oreSubTypeId = physicalItem.Id.SubtypeId.ToString();
                foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if (oreSubTypeId == mat.MinedOre)
                    {
                        VoxelMaterial = mat;
                        model = MyDebris.GetRandomDebrisVoxel();
                        scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
                        break;
                    }
                }

                scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
            }

            if (scale < 0.05f)
                Close();
            else if (scale < 0.15f)
                scale = 0.15f;

            FormatDisplayName(m_displayedText, Item);
            Init(m_displayedText, model, null, null, null);

            PositionComp.Scale = scale; // Must be set after init


            var massProperties = new HkMassProperties();
            HkShape shape = GetPhysicsShape(physicalItem.Mass * (float)Item.Amount, scale, out massProperties);
            var scaleMatrix = Matrix.CreateScale(scale);

            if (Physics != null)
                Physics.Close();
            Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);

            if (VoxelMaterial != null)
            {
                HkConvexTransformShape transform = new HkConvexTransformShape((HkConvexShape)shape, ref scaleMatrix, HkReferencePolicy.None);
        
                Physics.CreateFromCollisionObject(transform, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);
               
                Physics.Enabled = true;
                transform.Base.RemoveReference();
            }
            else
            {
                Physics.CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);
                Physics.Enabled = true;
            }

            Physics.MaterialType = VoxelMaterial != null ? MyMaterialType.ROCK : MyMaterialType.METAL;
            Physics.PlayCollisionCueEnabled = true;

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
        }
开发者ID:martejj,项目名称:SpaceEngineers,代码行数:68,代码来源:MyFloatingObject.cs


示例7: IsCharacter

        private static bool IsCharacter(HkRigidBody rb, MyPhysicsBody character)
        {
            if (character == null)
                return false;

            var c = character.Entity as MyCharacter;
            if (c == null) return false;
            if (c.Physics == null) return false;    // Physics may have been already released / Entity removed from the world?
            if (c.Physics.CharacterProxy != null)
                return c.Physics.CharacterProxy.GetHitRigidBody() == rb;
            return (c.Physics.RigidBody == rb);     // Otherwise we do proper check
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:12,代码来源:MyVoxelPhysicsBody.cs


示例8: Weld

        public void Weld(MyPhysicsBody other, bool recreateShape = true)
        {
            if (other.WeldInfo.Parent == this) //already welded to this
                return;

            if(other.IsWelded && !IsWelded)
            {
                other.Weld(this);
                return;
            }

            if(IsWelded)
            {
                WeldInfo.Parent.Weld(other);
                return;
            }
            
            HkShape thisShape;
            if (WeldInfo.Children.Count == 0)
            {
                thisShape = RigidBody.GetShape();
                HkShape.SetUserData(thisShape, RigidBody);
                Entity.OnPhysicsChanged += WeldedEntity_OnPhysicsChanged;
                //Entity.OnClose += Entity_OnClose;
            }
            else
                thisShape = GetShape();

            other.Deactivate();

            var transform = other.RigidBody.GetRigidBodyMatrix() * Matrix.Invert(RigidBody.GetRigidBodyMatrix());
            other.WeldInfo.Transform = transform;
            other.WeldedRigidBody = other.RigidBody;
            other.RigidBody = RigidBody;
            other.WeldInfo.Parent = this;

            WeldInfo.Children.Add(other);

            if(recreateShape)
                RecreateWeldedShape(thisShape);

            other.Entity.OnPhysicsChanged += WeldedEntity_OnPhysicsChanged;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:43,代码来源:MyPhysicsBody.cs


示例9: InitDeadBodyPhysics

        private void InitDeadBodyPhysics()
        {
            Vector3 velocity = Vector3.Zero;

            RadioBroadcaster.BroadcastRadius = 5;

            if (Physics != null)
            {
                velocity = Physics.LinearVelocity;

                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            //if (Physics == null)
            {
                var massProperties = new HkMassProperties();
                massProperties.Mass = 500;

                HkShape shape;
                // CH: Need to rethink this. It does not belong here, but I don't want to add "DeadCharacterBodyCenterOfMass" to the character definition either...
                // MZ: See ticket "Correct dying for characters", https://app.asana.com/0/64822442925263/75411538582998
                //     dead body shape can now be specified in character's SBC
                if (Definition.DeadBodyShape != null)
                {
                    HkBoxShape bshape = new HkBoxShape(PositionComp.LocalAABB.HalfExtents * Definition.DeadBodyShape.BoxShapeScale);
                    massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(bshape.HalfExtents, massProperties.Mass);
                    massProperties.CenterOfMass = bshape.HalfExtents * Definition.DeadBodyShape.RelativeCenterOfMass;
                    shape = bshape;

                    Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
                    Vector3D offset = PositionComp.LocalAABB.HalfExtents * Definition.DeadBodyShape.RelativeShapeTranslation;
                    MatrixD pos = MatrixD.CreateTranslation(offset);
                    Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center + offset, pos, massProperties, MyPhysics.CollisionLayers.FloatingObjectCollisionLayer);
                    Physics.Friction = Definition.DeadBodyShape.Friction;
                    Physics.RigidBody.MaxAngularVelocity = MathHelper.PiOver2;
                    Physics.LinearVelocity = velocity;
                    shape.RemoveReference();

                    Physics.Enabled = true;
                }
                else // no special definition => use AABB
                {
                    HkBoxShape bshape = new HkBoxShape(PositionComp.LocalAABB.HalfExtents);
                    massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(bshape.HalfExtents, massProperties.Mass);
                    massProperties.CenterOfMass = new Vector3(bshape.HalfExtents.X, 0, 0);
                    shape = bshape;

                    Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
                    Physics.CreateFromCollisionObject(shape, PositionComp.LocalVolume.Center, MatrixD.Identity, massProperties, MyPhysics.CollisionLayers.FloatingObjectCollisionLayer);
                    Physics.Friction = 0.5f;
                    Physics.RigidBody.MaxAngularVelocity = MathHelper.PiOver2;
                    Physics.LinearVelocity = velocity;
                    shape.RemoveReference();

                    Physics.Enabled = true;
                }
            }

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:62,代码来源:MyCharacter.cs


示例10: Components_ComponentAdded

 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = c as MyPhysicsBody;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = c as MySyncComponentBase;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = c as MyGameLogicComponent;
     else if (t == typeof(MyPositionComponentBase))
         m_position = c as MyPositionComponentBase;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:17,代码来源:MyEntity.cs


示例11: Init


//.........这里部分代码省略.........
            {
                var child = m_children[i];
                Func<MyObjectBuilder_FracturedPiece.Shape, bool> x = s => s.Name == child.ShapeName;
                var result = m_shapes.Where(x);
                if (result.Count() > 0)
                {
                    var found = result.First();
                    var m = Matrix.CreateFromQuaternion(found.Orientation);
                    if (!offset.HasValue && found.Name == m_shapes[0].Name)
                    {
                        offset = child.GetTransform().Translation;
                        shapeAtZero = m_shapeInfos.Count;
                    }
                    m.Translation = child.GetTransform().Translation;
                    var si = new HkdShapeInstanceInfo(child.Shape.Clone(), m);
                    if(found.Fixed)
                        si.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                    m_shapeInfos.Add(si);
                    m_shapes.Remove(found);
                }
                else
                {
                    child.GetChildren(m_children);
                }
            }

            if (m_shapeInfos.Count == 0)
            {
                List<string> shapesToLoad = new List<string>();
                foreach (var obShape in ob.Shapes)
                    shapesToLoad.Add(obShape.Name);

                var shapesStr = shapesToLoad.Aggregate((str1, str2) => str1 + ", " + str2);
                var blocksStr = OriginalBlocks.Aggregate("", (str, defId) => str + ", " + defId.ToString());
                var failMsg = "No relevant shape was found for fractured piece. It was probably reexported and names changed. Shapes: " + shapesStr + ". Original blocks: " + shapesStr;

                Debug.Fail(failMsg);
                //HkdShapeInstanceInfo si = new HkdShapeInstanceInfo(new HkdBreakableShape((HkShape)new HkBoxShape(Vector3.One)), Matrix.Identity);
                //m_shapeInfos.Add(si);
                throw new Exception(failMsg);
            }

            if (offset.HasValue)
            {
                for (int i = 0; i < m_shapeInfos.Count; i++)
                {
                    var m = m_shapeInfos[i].GetTransform();
                    m.Translation -= offset.Value;
                    m_shapeInfos[i].SetTransform(ref m);
                }
                {
                    var m = m_shapeInfos[shapeAtZero].GetTransform();
                    m.Translation = Vector3.Zero;
                    m_shapeInfos[shapeAtZero].SetTransform(ref m);
                }
            }

            if (m_shapeInfos.Count > 0)
            {
                if (m_shapeInfos.Count == 1)
                    Shape = m_shapeInfos[0].Shape;
                else
                {
                    Shape = new HkdCompoundBreakableShape(null, m_shapeInfos);
                    ((HkdCompoundBreakableShape)Shape).RecalcMassPropsFromChildren();
                }
                Shape.SetStrenght(MyDestructionConstants.STRENGTH);
                var mp = new HkMassProperties();
                Shape.BuildMassProperties(ref mp);
                Shape.SetChildrenParent(Shape);
                Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);
                Physics.CanUpdateAccelerations = true;
                Physics.InitialSolverDeactivation = HkSolverDeactivation.High;
                Physics.CreateFromCollisionObject(Shape.GetShape(), Vector3.Zero, PositionComp.WorldMatrix, mp);
                Physics.BreakableBody = new HkdBreakableBody(Shape, Physics.RigidBody, null, (Matrix)PositionComp.WorldMatrix);
                Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody;

                if (OriginalBlocks.Count > 0)
                {
                    MyPhysicalModelDefinition def;
                    if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(OriginalBlocks[0], out def))
                        Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
                }


                var rigidBody = Physics.RigidBody;
                bool isFixed = MyDestructionHelper.IsFixed(Physics.BreakableBody.BreakableShape);
                if (isFixed)
                {
                    rigidBody.UpdateMotionType(HkMotionType.Fixed);
                    rigidBody.LinearVelocity = Vector3.Zero;
                    rigidBody.AngularVelocity = Vector3.Zero;
                }


                Physics.Enabled = true;
            }
            m_children.Clear();
            m_shapeInfos.Clear();
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MyFracturedPiece.cs


示例12: UpdateMassFromInventories

 public void UpdateMassFromInventories(HashSet<MySlimBlock> blocks, MyPhysicsBody rb)
 {
     if (rb.RigidBody.IsFixedOrKeyframed)
         return;
     ProfilerShort.Begin("GridShape.UpdateMassFromInv");
     Debug.Assert(BreakableShape.IsValid(), "This routine works with breakable shape mass properties.");
     foreach (var block in blocks)
     {
         var owner = block.FatBlock as IMyInventoryOwner;
         if (owner == null) continue;
         float mass = 0;
         for (int i = 0; i < owner.InventoryCount; i++)
         {
             mass += (float)owner.GetInventory(i).CurrentMass;
         }
         var size = (block.Max - block.Min + Vector3I.One) * block.CubeGrid.GridSize;
         var center = (block.Min + block.Max) * 0.5f * block.CubeGrid.GridSize;
         HkMassProperties massProperties = new HkMassProperties();
         massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(size / 2, mass);
         m_tmpElements.Add(new HkMassElement() { Properties = massProperties, Tranform = Matrix.CreateTranslation(center) });
     }
     HkMassProperties originalMp = new HkMassProperties();
     BreakableShape.BuildMassProperties(ref originalMp);
     m_tmpElements.Add(new HkMassElement() { Properties = originalMp, Tranform = Matrix.Identity });
     var mp = HkInertiaTensorComputer.CombineMassProperties(m_tmpElements);
     m_tmpElements.Clear();
     rb.RigidBody.SetMassProperties(ref mp);
     if (!rb.RigidBody.IsActive)
         rb.RigidBody.Activate();
     ProfilerShort.End();
 }
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:31,代码来源:MyGridShape.cs


示例13: OnUnwelded

 protected override void OnUnwelded(MyPhysicsBody other)
 {
     base.OnUnwelded(other);
     Shape.RefreshMass();
     m_grid.HavokSystemIDChanged(HavokCollisionSystemID);
 }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:6,代码来源:MyGridPhysics.cs


示例14: AddObject

        /// <summary>
        /// Try add object to some subspace.
        /// Create new subspace if allowed (!SingleCluster.HasValue) and needed (object is outside of existing subspaces).
        /// If not allowed, mark object as left the world.
        /// </summary>
        /// <param name="bbox"></param>
        /// <param name="velocity"></param>
        /// <param name="activationHandler"></param>
        /// <param name="customId"></param>
        /// <returns></returns>
        public static ulong AddObject(BoundingBoxD bbox, Vector3 velocity, MyPhysicsBody activationHandler, ulong? customId)
        {
            ulong tmp = Clusters.AddObject(bbox, velocity, activationHandler, customId);

            if (tmp == MyHavokCluster.CLUSTERED_OBJECT_ID_UNITIALIZED)
            {
                HavokWorld_EntityLeftWorld(activationHandler.RigidBody);
                return MyHavokCluster.CLUSTERED_OBJECT_ID_UNITIALIZED;
            }
            return tmp;
            
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:22,代码来源:MyPhysics.cs


示例15: RefreshPhysicsBody

        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 Sandbox.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();
            }
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:24,代码来源:MySpaceBall.cs


示例16: PrepareItemsPhysics

        /// <summary>
        /// Prepares data for renderer and physics. Must be called after all items has been added.
        /// </summary>
      
        private void PrepareItemsPhysics(HkStaticCompoundShape sectorRootShape, ref BoundingBoxD aabbWorld, Dictionary<MyStringHash, HkShape> subtypeIdToShape)
        {
            foreach (var item in m_itemsData)
            {
                if (!item.Value.Enabled)
                    continue;

                int physicsShapeInstanceId;
                MatrixD transform = item.Value.Transform.TransformMatrix;
                if (AddPhysicsShape(item.Value.SubtypeId, item.Value.Model, ref transform, sectorRootShape, subtypeIdToShape, out physicsShapeInstanceId))
                {
                    // Map to data index - note that itemData is added after this to its list!
                    m_physicsShapeInstanceIdToLocalId[physicsShapeInstanceId] = item.Value.Id;
                    m_localIdToPhysicsShapeInstanceId[item.Value.Id] = physicsShapeInstanceId;

                }
            }

            PositionComp.WorldAABB = aabbWorld;

            if (sectorRootShape.InstanceCount > 0)
            {
                Debug.Assert(m_physicsShapeInstanceIdToLocalId.Count > 0);

                Physics = new Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC)
                {
                    MaterialType = m_definition.Material,
                    AngularDamping = MyPerGameSettings.DefaultAngularDamping,
                    LinearDamping = MyPerGameSettings.DefaultLinearDamping,
                    IsStaticForCluster = true,
                };

                sectorRootShape.Bake();
                HkMassProperties massProperties = new HkMassProperties();
                MatrixD matrix = MatrixD.CreateTranslation(CellsOffset);
                Physics.CreateFromCollisionObject((HkShape)sectorRootShape, Vector3.Zero, matrix, massProperties);

                Physics.ContactPointCallback += Physics_ContactPointCallback;
                Physics.RigidBody.ContactPointCallbackEnabled = true;

                Physics.Enabled = true;
            }           
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:47,代码来源:MyEnvironmentItems.cs


示例17: OnWelded

        protected override void OnWelded(MyPhysicsBody other)
        {
            base.OnWelded(other);
            Shape.RefreshMass();

            if (m_grid.BlocksDestructionEnabled)
            {
                if (HavokWorld != null)
                    HavokWorld.BreakOffPartsUtil.MarkEntityBreakable(RigidBody, Shape.BreakImpulse);
                if (Sync.IsServer)
                {
                    if (RigidBody.BreakLogicHandler == null)
                        RigidBody.BreakLogicHandler = BreakLogicHandler;
                    if (RigidBody.BreakPartsHandler == null)
                        RigidBody.BreakPartsHandler = BreakPartsHandler;
                }
            }
            m_grid.HavokSystemIDChanged(other.HavokCollisionSystemID);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:19,代码来源:MyGridPhysics.cs


示例18: Unweld

        public void Unweld(MyPhysicsBody other, bool insertToWorld = true, bool recreateShape = true)
        {
            Debug.Assert(other.IsWelded, "Invalid state");
            if(IsWelded)
            {
                WeldInfo.Parent.Unweld(other, insertToWorld, recreateShape);
                return;
            }
            other.Entity.OnPhysicsChanged -= WeldedEntity_OnPhysicsChanged;

            other.WeldInfo.Parent = null;
            Debug.Assert(WeldInfo.Children.Contains(other));
            WeldInfo.Children.Remove(other);
            var body = other.RigidBody;
            other.RigidBody = other.WeldedRigidBody;
            other.RigidBody.SetWorldMatrix(other.WeldInfo.Transform * body.GetRigidBodyMatrix());
            other.RigidBody.LinearVelocity = body.LinearVelocity;
            if(insertToWorld)
                other.Activate();

            if(WeldInfo.Children.Count == 0)
            {
                Entity.OnPhysicsChanged -= WeldedEntity_OnPhysicsChanged;
                Entity.OnClose -= Entity_OnClose;
            }
            if(RigidBody != null && recreateShape)
                RecreateWeldedShape(GetShape());
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:28,代码来源:MyPhysicsBody.cs


示例19: OnUnwelded

 protected override void OnUnwelded(MyPhysicsBody other)
 {
     base.OnUnwelded(other);
     Shape.RefreshMass();
     m_grid.HavokSystemIDChanged(HavokCollisionSystemID);
     if(m_grid.IsStatic == false)
     {
         m_grid.RecalculateGravity();
     }
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:10,代码来源:MyGridPhysics.cs


示例20: LoadDummies

        private void LoadDummies()
        {
            var finalModel = VRage.Game.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 Sandbox.Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC);
                    Physics.IsPhantom = true;
                    Physics.CreateFromCollisionObject(detectorShape, matrix.Translation, world, null, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer);
                    Physics.Enabled = IsWorking;
                    Physics.RigidBody.ContactPointCallbackEnabled = true;
                    detectorShape.Base.RemoveReference();

                    break;
                }
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:29,代码来源:MyShipMergeBlock.cs



注:本文中的Sandbox.Engine.Physics.MyPhysicsBody类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Entities.MyCubeBlock类代码示例发布时间:2022-05-26
下一篇:
C# Definitions.MyVoxelMaterialDefinition类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap