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


C# HkShape类代码示例

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


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

示例1: CreateCharacterShape

        public static HkShape CreateCharacterShape(float height, float width, float headHeight, float headSize, float headForwardOffset, float downOffset = 0, bool capsuleForHead = false)
        {
            HkCapsuleShape capsule = new HkCapsuleShape(Vector3.Up * (height - downOffset) / 2.0f, Vector3.Down * (height) / 2.0f, width / 2.0f);

            if (headSize > 0)
            {
                HkConvexShape headShape;

                if (capsuleForHead)
                {
                    headShape = new HkCapsuleShape(new Vector3(0, 0, -0.3f), new Vector3(0, 0, 0.3f), headSize);
                }
                else
                {
                    headShape = new HkSphereShape(headSize);
                }
                //headShape = new HkCapsuleShape(new Vector3(0, 0, -0.05f), new Vector3(0, 0, 0.05f), headSize);

                HkShape[] shapes = new HkShape[]
                {
                    capsule,
                    new HkConvexTranslateShape(headShape, Vector3.Up * (headHeight - downOffset) / 2.0f + Vector3.Forward * headForwardOffset, HkReferencePolicy.TakeOwnership),
                };
                
                return new HkListShape(shapes, shapes.Length, HkReferencePolicy.TakeOwnership);
            }
            else
            {
                return capsule;
            }
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:31,代码来源:MyCharacterProxy.cs

示例2: 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

示例3: 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

示例4: GetShapeCenter

		public static bool GetShapeCenter(HkShape shape, uint shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter)
		{
            return false; //Disabled because of bad computing shapeCenter in relation with grid (alway around grid center).
                          //Called on grid part which has havok shape (only door?).
			bool shapeSet = true;

			switch (shape.ShapeType)
			{
				case HkShapeType.List:
					var listShape = (HkListShape)shape;
					shape = listShape.GetChildByIndex((int)shapeKey);
					break;
				case HkShapeType.Mopp:
					var moppShape = (HkMoppBvTreeShape)shape;
					shape = moppShape.ShapeCollection.GetShape(shapeKey, null);
					break;
				case HkShapeType.Box:
					var boxShape = (HkBoxShape)shape;
					shape = boxShape;
					break;
				case HkShapeType.ConvexTranslate:
					var convexTranslateShape = (HkConvexShape)shape;
					shape = convexTranslateShape;
					break;
				case HkShapeType.ConvexTransform:
					var convexTransformShape = (HkConvexTransformShape)shape;
					shape = convexTransformShape;
					break;
			/*	case HkShapeType.BvTree:
					var bvTreeShape = (HkBvTreeShape)shape;
					var iterator = bvTreeShape.Base.GetContainer();
					while (iterator.CurrentValue.IsContainer() && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTranslate && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTransform)
						iterator.Next();
					if (iterator.IsValid)
						shape = iterator.CurrentValue;
					else
						shapeSet = false;
					break;*/

				default:
					shapeSet = false;
					break;
			}

			if (shapeSet)
			{
				Vector4 min4, max4;
				shape.GetLocalAABB(0.05f, out min4, out max4);
				Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix);
				Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix);
				var worldAABB = new BoundingBoxD(worldMin, worldMax);

				shapeCenter = worldAABB.Center;
			}
			return shapeSet;
		}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:56,代码来源:MyDrillSensorRaycast.cs

示例5: ReplaceShape

 private void ReplaceShape(HkShape shape)
 {
     if (shape.IsZero)
     {
         IsEmpty = true;
     }
     else
     {
         RigidBody.SetShape(shape);
         shape.RemoveReference();
         m_voxelMap.RaisePhysicsChanged();
     }
 }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:13,代码来源:MyVoxelPhysicsBody.cs

示例6: GetShapeCenter

		public static bool GetShapeCenter(HkShape shape, int shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter)
		{
			bool shapeSet = true;

			switch (shape.ShapeType)
			{
				case HkShapeType.List:
					var listShape = (HkListShape)shape;
					shape = listShape.GetChildByIndex(shapeKey);
					break;
				case HkShapeType.Mopp:
					var moppShape = (HkMoppBvTreeShape)shape;
					shape = moppShape.ShapeCollection.GetShape((uint)shapeKey, null);
					break;
				case HkShapeType.Box:
					var boxShape = (HkBoxShape)shape;
					shape = boxShape;
					break;
				case HkShapeType.ConvexTranslate:
					var convexTranslateShape = (HkConvexShape)shape;
					shape = convexTranslateShape;
					break;
				case HkShapeType.ConvexTransform:
					var convexTransformShape = (HkConvexTransformShape)shape;
					shape = convexTransformShape;
					break;
				default:
					shapeSet = false;
					break;
			}

			if (shapeSet)
			{
				Vector4 min4, max4;
				shape.GetLocalAABB(0.05f, out min4, out max4);
				Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix);
				Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix);
				var worldAABB = new BoundingBoxD(worldMin, worldMax);

				shapeCenter = worldAABB.Center;
			}
			return shapeSet;
		}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:43,代码来源:MyDrillSensorRaycast.cs

示例7: 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

示例8: TestQueryIntersection

 private static bool TestQueryIntersection(HkShape shape, MatrixD transform)
 {
     MatrixD transform1D = m_lastQueryTransform;
     MatrixD transform2D = transform;
     transform2D.Translation = transform2D.Translation - transform1D.Translation;
     transform1D.Translation = Vector3D.Zero;
     Matrix t1 = transform1D;
     Matrix t2 = transform2D;
     return MyPhysics.IsPenetratingShapeShape(m_lastQueryBox, ref t1, shape, ref t2);
 }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:10,代码来源:MyCubeGrid.Static.cs

示例9: RecreateWeldedShape

        private void RecreateWeldedShape(HkShape thisShape)
        {
            m_tmpShapeList.Add(thisShape);

            if (WeldInfo.Children.Count == 0)
            {
                RigidBody.SetShape(thisShape);
                if (RigidBody2 != null)
                    RigidBody2.SetShape(thisShape);
            }
            else
            {
                foreach (var child in WeldInfo.Children)
                {
                    var transformShape = new HkTransformShape(child.WeldedRigidBody.GetShape(), ref child.WeldInfo.Transform);
                    HkShape.SetUserData(transformShape, child.WeldedRigidBody);
                    m_tmpShapeList.Add(transformShape);
                }
                var list = new HkListShape(m_tmpShapeList.ToArray(), HkReferencePolicy.None);
                RigidBody.SetShape(list);
                if (RigidBody2 != null)
                    RigidBody2.SetShape(list);
                list.Base.RemoveReference();
                m_tmpShapeList.Clear();
            }
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:26,代码来源:MyPhysicsBody.cs

示例10: AddPhysicalShape

        private void AddPhysicalShape(HkShape shape, Matrix rdWorldMatrix)
        {
            switch (shape.ShapeType)
            {
                case Havok.HkShapeType.Box:
                    Havok.HkBoxShape box = (HkBoxShape)shape;

                    Vector3D vMin = new Vector3D(-box.HalfExtents.X, -box.HalfExtents.Y, -box.HalfExtents.Z);
                    Vector3D vMax = new Vector3D(box.HalfExtents.X, box.HalfExtents.Y, box.HalfExtents.Z);
                    BoundingBoxD boundingBox = new BoundingBoxD(vMin, vMax);

                    BoundingBoxToTranslatedTriangles(boundingBox, rdWorldMatrix);
                    break;

                case Havok.HkShapeType.List:
                    var listShape = (HkListShape)shape;
                    var iterator = listShape.GetIterator();
                    while (iterator.IsValid)
                    {
                        AddPhysicalShape(iterator.CurrentValue, rdWorldMatrix);
                        iterator.Next();
                    }
                    break;

                case HkShapeType.Mopp:
                    var compoundShape = (HkMoppBvTreeShape)shape;
                    AddPhysicalShape(compoundShape.ShapeCollection, rdWorldMatrix);
                    break;

                case HkShapeType.ConvexTransform:
                    var transformShape = (HkConvexTransformShape)shape;
                    AddPhysicalShape(transformShape.ChildShape, transformShape.Transform * rdWorldMatrix);
                    break;

                case HkShapeType.ConvexTranslate:
                    var translateShape = (HkConvexTranslateShape)shape;
                    var mat = Matrix.CreateTranslation(translateShape.Translation);
                    AddPhysicalShape((HkShape)translateShape.ChildShape, mat * rdWorldMatrix);
                    break;

                case HkShapeType.Sphere:
                    var sphereShape = (HkSphereShape)shape;
                    m_icosphereMesh.AddTrianglesToWorldVertices(rdWorldMatrix.Translation, sphereShape.Radius);
                    break;

                case HkShapeType.Capsule:
                    return;
                    ProfilerShort.Begin("Capsule");

                    var capsuleShape = (HkCapsuleShape)shape;
                    Line line = new Line(capsuleShape.VertexA, capsuleShape.VertexB);
                    m_capsuleMesh.AddTrianglesToWorldVertices(rdWorldMatrix, capsuleShape.Radius, line);

                    ProfilerShort.End();
                    break;

                case HkShapeType.ConvexVertices:
                    var convexShape = (HkConvexVerticesShape)shape;
                    HkGeometry geometry = new HkGeometry();
                    Vector3 center;
                    convexShape.GetGeometry(geometry, out center);

                    for (int i = 0; i < geometry.TriangleCount; i++)
                    {
                        int i0, i1, i2, materialIndex;
                        geometry.GetTriangle(i, out i0, out i1, out i2, out materialIndex);

                        m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i0);
                        m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i1);
                        m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i2);
                    }

                    for (int i = 0; i < geometry.VertexCount; i++)
                    {
                        Vector3 vec = geometry.GetVertex(i);
                        Vector3.Transform(ref vec, ref rdWorldMatrix, out vec);
                        m_worldVertices.Vertices.Add(vec);
                    }

                    m_worldVertices.VerticesMaxValue += geometry.VertexCount;
                    break;

                default:
                    // For breakpoint. Don't judge me :(
                    break;
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:87,代码来源:MyNavigationInputMesh.cs

示例11: GetPropertiesFromEntity

        bool GetPropertiesFromEntity(MyEntity entity,ref Vector3D position1, out Quaternion rotation2, out Vector3 posDiff, out HkShape? shape2)
        {
            rotation2 = new Quaternion();
            posDiff = Vector3.Zero;
            shape2 = null;
            if (entity.Physics == null || !entity.Physics.Enabled)
            {
                return false;
            }

            if (entity.Physics.RigidBody != null)
            {
                shape2 = entity.Physics.RigidBody.GetShape();

                var worldMatrix = entity.WorldMatrix;
                rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                posDiff = entity.PositionComp.GetPosition() - position1;
                if (entity is MyVoxelBase)
                {
                    var voxel = entity as MyVoxelBase;
                    posDiff -= voxel.Size / 2;
                }
            }
            else if (entity.GetPhysicsBody().CharacterProxy != null)
            {
                shape2 = entity.GetPhysicsBody().CharacterProxy.GetShape();
                var worldMatrix = entity.WorldMatrix;
                rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                posDiff = entity.PositionComp.GetPosition() - position1;
            }
            else
            {
                return false;
            }

            return true;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:37,代码来源:MySensorBlock.cs

示例12: CreateBreakableBody

        private HkShape CreateBreakableBody(HkShape shape, HkMassProperties? massProperties)
        {
            ProfilerShort.Begin("CreateGridBody");

            HkdBreakableShape breakable;
            HkMassProperties massProps = massProperties.HasValue ? massProperties.Value : new HkMassProperties();

            if (!Shape.BreakableShape.IsValid())
                Shape.CreateBreakableShape();

            breakable = Shape.BreakableShape;

            if (!breakable.IsValid())
            {
                breakable = new HkdBreakableShape(shape);
                if (massProperties.HasValue)
                {
                    var mp = massProperties.Value;
                    breakable.SetMassProperties(ref mp);
                }
                else
                    breakable.SetMassRecursively(50);
            }
            else
                breakable.BuildMassProperties(ref massProps);

            shape = breakable.GetShape(); //doesnt add reference
            HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();
            rbInfo.AngularDamping = m_angularDamping;
            rbInfo.LinearDamping = m_linearDamping;
            rbInfo.SolverDeactivation = m_grid.IsStatic ? InitialSolverDeactivation : HkSolverDeactivation.Low;
            rbInfo.ContactPointCallbackDelay = ContactPointDelay;
            rbInfo.Shape = shape;
            rbInfo.SetMassProperties(massProps);
            //rbInfo.Position = Entity.PositionComp.GetPosition(); //obsolete with large worlds?
            GetInfoFromFlags(rbInfo, Flags);
            if (m_grid.IsStatic)
            {
                rbInfo.MotionType = HkMotionType.Dynamic;
                rbInfo.QualityType = HkCollidableQualityType.Moving;
            }
            HkRigidBody rb = new HkRigidBody(rbInfo);
            if (m_grid.IsStatic)
            {
                rb.UpdateMotionType(HkMotionType.Fixed);
            }
            rb.EnableDeactivation = true;
            BreakableBody = new HkdBreakableBody(breakable, rb, null, Matrix.Identity);
            //DestructionBody.ConnectToWorld(HavokWorld, 0.05f);

            BreakableBody.AfterReplaceBody += FracturedBody_AfterReplaceBody;

            //RigidBody.SetWorldMatrix(Entity.PositionComp.WorldMatrix);
            //breakable.Dispose();

            ProfilerShort.End();
            return shape;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:58,代码来源:MyGridPhysics.Destruction.cs

示例13: CreateBody

        protected override void CreateBody(ref HkShape shape, HkMassProperties? massProperties)
        {
            if (MyPerGameSettings.Destruction)// && shape.ShapeType == HkShapeType.StaticCompound)
            {
                shape = CreateBreakableBody(shape, massProperties);
            }
            else
            {
                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);
                if (m_grid.IsStatic)
                {
                    rbInfo.MotionType = HkMotionType.Dynamic;
                    rbInfo.QualityType = HkCollidableQualityType.Moving;
                }
                RigidBody = new HkRigidBody(rbInfo);

                if (m_grid.IsStatic)
                {
                    RigidBody.UpdateMotionType(HkMotionType.Fixed);
                }
                //RigidBody.UpdateMotionType(HkMotionType.Dynamic);

                //base.CreateBody(ref shape, massProperties);
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:38,代码来源:MyGridPhysics.cs

示例14: FindMountPoint

        static bool FindMountPoint(HkShapeCutterUtil cutter, HkShape shape, Vector3 direction, float gridSize, List<Sandbox.Definitions.MyCubeBlockDefinition.MountPoint> mountPoints)
        {
            //VRageRender.MyRenderProxy.DebugDrawLine3D(drawMatrix.Translation, Vector3D.Transform(direction, drawMatrix), Color.Green, Color.Green, false);
            //float offset = (gridSize * 0.9f) / 2.0f;
            float offset = (gridSize * 0.75f) / 2.0f; //because fracture pieces can be bit inside the cube
            Plane plane = new Plane(-direction, offset);
            float minimumSize = 0.2f;

            Vector3 min, max;
            if (cutter.Cut(shape, new Vector4(plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D), out min, out max))
            {
                var aabb = new BoundingBox(min, max);
                aabb.InflateToMinimum(new Vector3(minimumSize));
                float centerOffset = gridSize * 0.5f;
                //    VRageRender.MyRenderProxy.DebugDrawOBB(boxC, Color.Red, 0.02f, true, false);

                MyCubeBlockDefinition.MountPoint mountPoint = new MyCubeBlockDefinition.MountPoint();
                mountPoint.Normal = new Vector3I(direction);
                mountPoint.Start = (aabb.Min + new Vector3(centerOffset)) / gridSize;
                mountPoint.End = (aabb.Max + new Vector3(centerOffset)) / gridSize;
				mountPoint.Enabled = true;
                //because it didnt work if shape wasnt realy near the edge
                var zExt = Vector3.Abs(direction) * mountPoint.Start;
                bool add = zExt.AbsMax() > 0.5f;
                mountPoint.Start -= zExt;
                mountPoint.Start -= direction * 0.04f;
                mountPoint.End -= Vector3.Abs(direction) * mountPoint.End;
                mountPoint.End += direction * 0.04f;
                if (add)
                {
                    mountPoint.Start += Vector3.Abs(direction);
                    mountPoint.End += Vector3.Abs(direction);
                }
                mountPoints.Add(mountPoint);

                return true;
            }

            return false;
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:40,代码来源:MyCubeBuilder-Draw.cs

示例15: IsPenetratingShapeShape

 public static bool IsPenetratingShapeShape(HkShape shape1, ref Matrix transform1, HkShape shape2, ref Matrix transform2)
 {
     return (Clusters.GetList().First() as HkWorld).IsPenetratingShapeShape(shape1, ref transform1, shape2, ref transform2);
 }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:4,代码来源:MyPhysics.cs


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