当前位置: 首页>>代码示例>>C#>>正文


C# MyPhysicsBody.UpdateMassProps方法代码示例

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


在下文中一共展示了MyPhysicsBody.UpdateMassProps方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateMassFromInventories

        public void UpdateMassFromInventories(HashSet<MySlimBlock> blocks, MyPhysicsBody rb)
        {
            if (rb.RigidBody.IsFixedOrKeyframed)
                return;

			float cargoMassMultiplier = MySession.Static.Settings.InventorySizeMultiplier;
            ProfilerShort.Begin("GridShape.UpdateMassFromInv");
            foreach (var block in blocks)
            {
                var owner = block.FatBlock as IMyInventoryOwner;
                float mass = 0;

				if (owner == null)
				{
					var cockpit = block.FatBlock as MyCockpit;
					if(cockpit == null || cockpit.Pilot == null)
						continue;

					mass = cockpit.Pilot.BaseMass + (float)cockpit.Pilot.Inventory.CurrentMass / cargoMassMultiplier;
				}
				else
				{
					for (int i = 0; i < owner.InventoryCount; i++)
					{
						mass += (float)owner.GetInventory(i).CurrentMass / cargoMassMultiplier;
					}
				}
                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, (MyPerGameSettings.Destruction ?  MyDestructionHelper.MassToHavok(mass) : mass));
                m_tmpElements.Add(new HkMassElement() { Properties = massProperties, Tranform = Matrix.CreateTranslation(center) });
            }
            HkMassProperties originalMp = new HkMassProperties();
			if (MyPerGameSettings.Destruction)
			{
				Debug.Assert(BreakableShape.IsValid(), "This routine works with breakable shape mass properties.");
				BreakableShape.BuildMassProperties(ref originalMp);
				m_tmpElements.Add(new HkMassElement() { Properties = originalMp, Tranform = Matrix.Identity });
			}
			else
			{
				m_tmpElements.Add(new HkMassElement() { Properties = m_originalMassProperties, Tranform = Matrix.Identity });
			}
            m_massProperties = HkInertiaTensorComputer.CombineMassProperties(m_tmpElements);
            m_tmpElements.Clear();
            if (rb.IsWelded || rb.WeldInfo.Children.Count != 0)
            {
                rb.WeldedRigidBody.SetMassProperties(ref m_massProperties);
                rb.WeldInfo.SetMassProps(m_massProperties);
                rb.UpdateMassProps();
            }
            else
            {
                rb.RigidBody.SetMassProperties(ref m_massProperties);
                if (!rb.RigidBody.IsActive)
                    rb.RigidBody.Activate();
            }
            ProfilerShort.End();
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:60,代码来源:MyGridShape.cs


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