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


C# HkMassProperties类代码示例

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


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

示例1: ScalePhysicsShape

 public virtual void ScalePhysicsShape(ref HkMassProperties massProperties)
 {
     var debriModel = Entity.Render.GetModel();
     HkShape shape;
     if (debriModel.HavokCollisionShapes != null && debriModel.HavokCollisionShapes.Length > 0)
     {
         shape = debriModel.HavokCollisionShapes[0];
         Vector4 min, max;
         shape.GetLocalAABB(0.1f, out min, out max);
         Vector3 he = new Vector3((max - min) * 0.5f);
         massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(he, he.Volume * 50);
         massProperties.CenterOfMass = new Vector3((min + max) * 0.5f);
     }
     else
     {
         var transformShape = (HkTransformShape)RigidBody.GetShape();
         var boxShape = (HkBoxShape)transformShape.ChildShape;
         boxShape.HalfExtents = ((debriModel.BoundingBox.Max - debriModel.BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value;
         massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, boxShape.HalfExtents.Volume * 0.5f);
         massProperties.CenterOfMass = transformShape.Transform.Translation;
         shape = transformShape;
     }
     RigidBody.SetShape(shape);
     RigidBody.SetMassProperties(ref massProperties);
     RigidBody.UpdateShape();
 }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:26,代码来源:MyDebrisBase.cs

示例2: AllocateForDefinition

 public void AllocateForDefinition(string model, MyPhysicalModelDefinition definition, int count)
 {
     if (string.IsNullOrEmpty(model))
         return;
     ProfilerShort.Begin("Clone");
     var data = MyModels.GetModelOnlyData(model);
     if (MyFakes.LAZY_LOAD_DESTRUCTION && data.HavokBreakableShapes == null)
     {
         MyDestructionData.Static.LoadModelDestruction(model, definition, data.BoundingBoxSize);
     }               
     if (data.HavokBreakableShapes != null && data.HavokBreakableShapes.Length > 0)
     {
         if (!m_pools.ContainsKey(definition.Id))
             m_pools[definition.Id] = new Dictionary<string, ConcurrentQueue<HkdBreakableShape>>();
         if(!m_pools[definition.Id].ContainsKey(model))
             m_pools[definition.Id][model] = new ConcurrentQueue<HkdBreakableShape>();
         var queue = m_pools[definition.Id][model];
         for (int i = 0; i < count; i++)
         {
             var shape = data.HavokBreakableShapes[0].Clone();
             queue.Enqueue(shape);
             if (i == 0)
             {
                 var mp = new HkMassProperties();
                 shape.BuildMassProperties(ref mp);
                 if (!mp.InertiaTensor.IsValid())
                 {
                     MyLog.Default.WriteLine(string.Format("Block with wrong destruction! (q.isOk): {0}", definition.Model));
                     break;
                 }
             }
         }
     }
     ProfilerShort.End();
 }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:35,代码来源:MyBreakableShapeManager.cs

示例3: CreatePhysicsShape

 public override void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
 {
     var sphereShape = new HkSphereShape(((MyEntity)Entity).Render.GetModel().BoundingSphere.Radius * Entity.PositionComp.Scale.Value);
     shape = sphereShape;
     var mass = SphereMass(sphereShape.Radius, VoxelDensity);
     massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(sphereShape.Radius, mass);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyDebrisVoxel.cs

示例4: CreatePhysicsShape

 public virtual void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
 {
     var boxShape = new HkBoxShape(((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value);
     var pos = ((((MyEntity)Entity).Render.GetModel().BoundingBox.Max + ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2);
     shape = new HkTransformShape(boxShape, ref pos, ref Quaternion.Identity);
     //shape = boxShape;
     massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, boxShape.HalfExtents.Volume * 0.5f);
     massProperties.CenterOfMass = pos;
 }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:9,代码来源:MyDebrisBase.cs

示例5: UpdateMassProps

 internal void UpdateMassProps(HkRigidBody rb)
 {
     var mp = new HkMassProperties();
     mp.InertiaTensor = rb.InertiaTensor;
     mp.Mass = rb.Mass;
     mp.CenterOfMass = rb.CenterOfMassLocal;
     MassElement = new HkMassElement();
     MassElement.Properties = mp;
     MassElement.Tranform = Transform;
     //MassElement.Tranform.Translation = Vector3.Transform(rb.CenterOfMassLocal, Transform);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:11,代码来源:MyPhysicsBody.Welding.cs

示例6: ScalePhysicsShape

            public override void ScalePhysicsShape(ref HkMassProperties massProperties)
            {
                var shape = RigidBody.GetShape();
                var sphereShape = (HkSphereShape)shape;
                sphereShape.Radius = ((MyEntity)Entity).Render.GetModel().BoundingSphere.Radius * Entity.PositionComp.Scale.Value;
                massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(sphereShape.Radius, 1);

                RigidBody.SetShape(sphereShape);
                RigidBody.SetMassProperties(ref massProperties);
                RigidBody.UpdateShape();
            }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:11,代码来源:MyDebrisVoxel.cs

示例7: ScalePhysicsShape

            public virtual void ScalePhysicsShape(ref HkMassProperties massProperties)
            {
                var shape = RigidBody.GetShape();
                var boxShape = (HkBoxShape)shape;
                boxShape.HalfExtents = ((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value;
                massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, massProperties.Mass);

                RigidBody.SetShape(boxShape);
                RigidBody.SetMassProperties(ref massProperties);
                RigidBody.UpdateShape();
            }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:11,代码来源:MyDebrisBase.cs

示例8: CreatePhysicsShape

 public virtual void CreatePhysicsShape(out HkShape shape, ref HkMassProperties massProperties)
 {
     var boxShape = new HkBoxShape(((((MyEntity)Entity).Render.GetModel().BoundingBox.Max - ((MyEntity)Entity).Render.GetModel().BoundingBox.Min) / 2) * Entity.PositionComp.Scale.Value);
     shape = boxShape;
     massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(boxShape.HalfExtents, massProperties.Mass);
 }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:6,代码来源:MyDebrisBase.cs

示例9: Init

            /// <summary>
            /// One time initialization for debris entity. These are settings that do not change 
            /// when this debris entity is pulled from the pool.
            /// Also note that this is the only way Debris should be initialized. It calls other Init methods with 
            /// correct arguments.
            /// </summary>
            public virtual void Init(MyDebrisBaseDescription desc)
            {
                base.Init(null, desc.Model, null, 1.0f);
                m_randomScale = MyUtils.GetRandomFloat(desc.ScaleMin, desc.ScaleMax);
                Container.Entity.PositionComp.Scale = m_randomScale;
                m_lifespanInMiliseconds = MyUtils.GetRandomInt(desc.LifespanMinInMiliseconds, desc.LifespanMaxInMiliseconds);

                HkShape shape;
                m_massProperties = new HkMassProperties();
                m_massProperties.Mass = 50;
                Container.Entity.Physics = GetPhysics(RigidBodyFlag.RBF_DEBRIS);
                (Container.Entity.Physics as MyDebrisPhysics).CreatePhysicsShape(out shape, ref m_massProperties);
                (Container.Entity.Physics as MyDebrisPhysics).CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, m_massProperties, MyPhysics.DebrisCollisionLayer);
                Container.Entity.Physics.Enabled = false;
                shape.RemoveReference();

                m_entity.Save = false;
                Container.Entity.Physics.PlayCollisionCueEnabled = true;
                NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
                m_onCloseCallback = desc.OnCloseAction;
            }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:27,代码来源:MyDebrisBase.cs

示例10: FindFractureComponentBlocks

        /// <summary>
        /// Searches for blocks which will create fracture components from cached m_fracturedSlimBlocksShapes
        /// </summary>
        private void FindFractureComponentBlocks()
        {
            Debug.Assert(MyFakes.ENABLE_FRACTURE_COMPONENT);

            foreach (var pair in m_fracturedSlimBlocksShapes)
            {
                var slimBlock = pair.Key;
                var shapeList = pair.Value;

                if (slimBlock.FatBlock.Components.Has<MyFractureComponentBase>())
                {
                    // Block has fracture component - ignore
                    continue;
                }
                else
                {
                    int totalBreakableShapesCountForModel = slimBlock.GetTotalBreakableShapeChildrenCount();
                    Debug.Assert(shapeList.Count <= totalBreakableShapesCountForModel);
                    // No removed pieces? Then ignore.
                    if (slimBlock.BlockDefinition.CreateFracturedPieces && totalBreakableShapesCountForModel == shapeList.Count)
                        continue;

                    foreach (var s in shapeList)
                    {
                        s.SetTransform(ref Matrix.Identity);
                    }
                    ProfilerShort.Begin("CreateShapeComponent");
                    HkdBreakableShape compound = new HkdCompoundBreakableShape(null, shapeList);
                    ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
                    var mp = new HkMassProperties();
                    compound.BuildMassProperties(ref mp);
                    HkdBreakableShape shape = compound;
                    var sh = compound.GetShape();
                    shape = new HkdBreakableShape(sh, ref mp);
                    //shape.SetMassProperties(mp); //important! pass mp to constructor
                    foreach (var si in shapeList)
                    {
                        var siRef = si;
                        shape.AddShape(ref siRef);
                    }
                    compound.RemoveReference();

                    ProfilerShort.BeginNextBlock("Connect");
                    //shape.SetChildrenParent(shape);
                    ConnectPiecesInBlock(shape, shapeList);

                    MyFractureComponentBase.Info info = new MyFractureComponentBase.Info()
                    {
                        Entity = slimBlock.FatBlock,
                        Shape = shape,
                        Compound = true
                    };

                    m_fractureBlockComponentsCache.Add(info);

                    ProfilerShort.End();
                }
            }

            m_fracturedSlimBlocksShapes.Clear();
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:64,代码来源:MyGridPhysics.Destruction.cs

示例11: FindFracturedBlocks

        private void FindFracturedBlocks(HkdBreakableBodyInfo b)
        {
            ProfilerShort.Begin("DBHelper");
            var dbHelper = new HkdBreakableBodyHelper(b);
            ProfilerShort.BeginNextBlock("GetRBMatrix");
            var bodyMatrix = dbHelper.GetRigidBodyMatrix();
            ProfilerShort.BeginNextBlock("SearchChildren");
            dbHelper.GetChildren(m_children);
            foreach (var child in m_children)
            {
                if (!child.IsFracturePiece())
                    continue;
                //var blockPosWorld = ClusterToWorld(Vector3.Transform(child.GetTransform().Translation, bodyMatrix));
                var bShape = child.Shape;
                HkVec3IProperty pProp = bShape.GetProperty(HkdBreakableShape.PROPERTY_GRID_POSITION);
                var blockPos = pProp.Value; //Vector3I.Round(child.GetTransform().Translation / m_grid.GridSize);
                if (!m_grid.CubeExists(blockPos))
                {
                    //Debug.Fail("FindFracturedBlocks:Fracture piece missing block");//safe to ignore
                    continue;
                }

                if (MyFakes.ENABLE_FRACTURE_COMPONENT)
                {
                    var block = m_grid.GetCubeBlock(blockPos);
                    if (block == null)
                        continue;

                    if (!FindFractureComponentBlocks(block, child))
                        continue;
                }
                else
                {
                    if (!m_fracturedBlocksShapes.ContainsKey(blockPos))
                        m_fracturedBlocksShapes[blockPos] = new List<HkdShapeInstanceInfo>();
                    m_fracturedBlocksShapes[blockPos].Add(child);
                }
            }
            ProfilerShort.BeginNextBlock("CreateFreacturedBlocks");
            if (!MyFakes.ENABLE_FRACTURE_COMPONENT)
            {
                foreach (var key in m_fracturedBlocksShapes.Keys)
                {
                    HkdBreakableShape shape;
                    var shapeList = m_fracturedBlocksShapes[key];
                    foreach (var s in shapeList)
                    {
                        var matrix = s.GetTransform();
                        matrix.Translation = Vector3.Zero;
                        s.SetTransform(ref matrix);
                    }
                    ProfilerShort.Begin("CreateShape");
                    HkdBreakableShape compound = new HkdCompoundBreakableShape(null, shapeList);
                    ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
                    var mp = new HkMassProperties();
                    compound.BuildMassProperties(ref mp);
                    shape = compound;
                    var sh = compound.GetShape();
                    shape = new HkdBreakableShape(sh, ref mp);
                    //shape.SetMassProperties(mp); //important! pass mp to constructor
                    foreach (var si in shapeList)
                    {
                        var siRef = si;
                        shape.AddShape(ref siRef);
                    }
                    compound.RemoveReference();
                    ProfilerShort.BeginNextBlock("Connect");
                    //shape.SetChildrenParent(shape);
                    ConnectPiecesInBlock(shape, shapeList);
                    ProfilerShort.End();

                    var info = new MyFracturedBlock.Info()
                    {
                        Shape = shape,
                        Position = key,
                        Compound = true,
                    };
                    var originalBlock = m_grid.GetCubeBlock(key);
                    if (originalBlock == null)
                    {
                        //Debug.Fail("Missing fracture piece original block.");//safe to ignore
                        shape.RemoveReference();
                        continue;
                    }
                    Debug.Assert(originalBlock != null);
                    if (originalBlock.FatBlock is MyFracturedBlock)
                    {
                        var fractured = originalBlock.FatBlock as MyFracturedBlock;
                        info.OriginalBlocks = fractured.OriginalBlocks;
                        info.Orientations = fractured.Orientations;
                        info.MultiBlocks = fractured.MultiBlocks;
                    }
                    else if (originalBlock.FatBlock is MyCompoundCubeBlock)
                    {
                        info.OriginalBlocks = new List<MyDefinitionId>();
                        info.Orientations = new List<MyBlockOrientation>();
                        MyCompoundCubeBlock compoundBlock = originalBlock.FatBlock as MyCompoundCubeBlock;
                        bool hasMultiBlockPart = false;
                        var blocksInCompound = compoundBlock.GetBlocks();
                        foreach (var block in blocksInCompound)
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridPhysics.Destruction.cs

示例12: CreateBlockShape

        private HkdBreakableShape? CreateBlockShape(Sandbox.Game.Entities.Cube.MySlimBlock b, out Matrix blockTransform)
        {
            ProfilerShort.Begin("CreateBlockShape");
            blockTransform = Matrix.Identity;
            if (b.FatBlock == null)
            {
                Debug.Fail("Armor blocks are not allowed in medieval");
                ProfilerShort.End();
                return null;
            }

            HkdBreakableShape breakableShape;
            Matrix compoundChildTransform = Matrix.Identity;

            if (b.FatBlock is MyCompoundCubeBlock)
            {
                ProfilerShort.Begin("Cmpnd");
                blockTransform.Translation = b.FatBlock.PositionComp.LocalMatrix.Translation;
                var cb = b.FatBlock as MyCompoundCubeBlock;
                if (cb.GetBlocksCount() == 1)
                {
                    ProfilerShort.Begin("SingleBlock");
                    var block = cb.GetBlocks()[0];
                    var defId = block.FatBlock.BlockDefinition;
                    Matrix m;
                    var model = block.CalculateCurrentModel(out m);
                    if (MyFakes.LAZY_LOAD_DESTRUCTION || HasBreakableShape(model, defId))
                    {
                        ProfilerShort.Begin("Clone");
                        breakableShape = GetBreakableShape(model, defId);
                        ProfilerShort.End();
                    }

                    block.Orientation.GetMatrix(out compoundChildTransform);
                    blockTransform = compoundChildTransform * blockTransform;
                    ProfilerShort.End();
                }
                else
                {
                    var pos = b.Position * m_grid.GridSize;

                    float mass = 0;
                    ProfilerShort.Begin("GetBlocks");
                    foreach (var block in cb.GetBlocks())
                    {
                        block.Orientation.GetMatrix(out compoundChildTransform);
                        compoundChildTransform.Translation = Vector3.Zero;
                        var blockDef = block.BlockDefinition;
                        Matrix m;
                        var model = block.CalculateCurrentModel(out m);
                        if (MyFakes.LAZY_LOAD_DESTRUCTION || HasBreakableShape(model, blockDef))
                        {
                            ProfilerShort.Begin("Clone");

                            breakableShape = GetBreakableShape(model, blockDef);
                            breakableShape.UserObject |= (uint)HkdBreakableShape.Flags.FRACTURE_PIECE;
                            System.Diagnostics.Debug.Assert(breakableShape.IsValid(), "Invalid breakableShape");

                            ProfilerShort.End();
                            mass += blockDef.Mass;
                            m_shapeInfosList2.Add(new HkdShapeInstanceInfo(breakableShape, compoundChildTransform));
                        }
                    }

                    if (m_shapeInfosList2.Count == 0)
                    {
                        ProfilerShort.End();
                        return null;
                    }

                    ProfilerShort.BeginNextBlock("CreateCompoundBlockShape");
                    //HkShape hkpShape = new HkListShape(m_khpShapeList.ToArray(), m_khpShapeList.Count, HkReferencePolicy.None);
                    //m_khpShapeList.Clear();
                    HkdBreakableShape compound = new HkdCompoundBreakableShape(null, m_shapeInfosList2);
                    ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
                    var mp = new HkMassProperties();
                    compound.BuildMassProperties(ref mp);
                    breakableShape = new HkdBreakableShape(compound.GetShape(), ref mp);
                    compound.RemoveReference();
                    foreach (var si in m_shapeInfosList2)
                    {
                        var siRef = si;
                        breakableShape.AddShape(ref siRef);
                    }

                    ProfilerShort.BeginNextBlock("Connect");
                    //slow slow slow
                    //breakableShape.AutoConnect(MyDestructionData.Static.TemporaryWorld);
                    //slow wrong
                    //breakableShape.ConnectSemiAccurate(MyDestructionData.Static.TemporaryWorld);
                    //fast frong
                    for (int i = 0; i < m_shapeInfosList2.Count; i++)
                    {
                        for (int j = 0; j < m_shapeInfosList2.Count; j++)
                        {
                            if (i != j)
                            {
                                ConnectShapesWithChildren(breakableShape, m_shapeInfosList2[i].Shape, m_shapeInfosList2[j].Shape);
                            }
                        }
//.........这里部分代码省略.........
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridShape.cs

示例13: CreateBody

        protected virtual void CreateBody(ref HkShape shape, HkMassProperties? massProperties)
        {
            ProfilerShort.Begin("CreateBody");
            HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();

            rbInfo.AngularDamping = m_angularDamping;
            rbInfo.LinearDamping = m_linearDamping;
            rbInfo.Shape = shape;
            rbInfo.SolverDeactivation = InitialSolverDeactivation;
            rbInfo.ContactPointCallbackDelay = ContactPointDelay;

            if (massProperties.HasValue)
            {
                rbInfo.SetMassProperties(massProperties.Value);
            }

            GetInfoFromFlags(rbInfo, Flags);

            RigidBody = new HkRigidBody(rbInfo);

            ProfilerShort.End();
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:22,代码来源:MyPhysicsBody.cs

示例14: CheckVolumeMassRec

 private bool CheckVolumeMassRec(HkdBreakableShape bShape, float minVolume, float minMass)
 {
     if (bShape.Name.Contains("Fake"))
         return true;
     if (bShape.Volume <= minVolume)
         return false;
     HkMassProperties mp = new HkMassProperties();
     bShape.BuildMassProperties(ref mp);
     if (mp.Mass <= minMass)
         return false;
     if (mp.InertiaTensor.M11 == 0 || mp.InertiaTensor.M22 == 0 || mp.InertiaTensor.M33 == 0)
         return false;
     for (int i = 0; i < bShape.GetChildrenCount(); i++)
     {
         if (!CheckVolumeMassRec(bShape.GetChildShape(i), minVolume, minMass))
             return false;
     }
     return true;
 }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:19,代码来源:MyDestructionData.cs

示例15: GetPhysicsShape

            // Don't call remove reference on this, this shape is pooled
            protected virtual HkShape GetPhysicsShape(HkMassProperties massProperties, float mass, float scale)
            {
                const bool SimpleShape = false;

                Vector3 halfExtents = (Entity.Render.GetModel().BoundingBox.Max - Entity.Render.GetModel().BoundingBox.Min) / 2;
                HkShapeType shapeType;

                if (VoxelMaterial != null)
                {
                    shapeType = HkShapeType.Sphere;
                    massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(Entity.Render.GetModel().BoundingSphere.Radius * scale, mass);
                }
                else
                {
                    shapeType = HkShapeType.Box;
                    massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(halfExtents, mass);
                }

                return MyDebris.Static.GetDebrisShape(Entity.Render.GetModel(), SimpleShape ? shapeType : HkShapeType.ConvexVertices);
            }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:21,代码来源:MyMeteor.cs


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