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


C# ConvexShape.GetSweptLocalBoundingBox方法代码示例

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


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

示例1: ConvexCast

        /// <summary>
        /// Casts a convex shape against the collidable.
        /// </summary>
        /// <param name="castShape">Shape to cast.</param>
        /// <param name="startingTransform">Initial transform of the shape.</param>
        /// <param name="sweep">Sweep to apply to the shape.</param>
        /// <param name="hit">Hit data, if any.</param>
        /// <returns>Whether or not the cast hit anything.</returns>
        public override bool ConvexCast(ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweep, out RayHit hit)
        {
            if (Shape.solidity == MobileMeshSolidity.Solid)
            {
                //If the convex cast is inside the mesh and the mesh is solid, it should return t = 0.
                var ray = new Ray() { Position = startingTransform.Position, Direction = Toolbox.UpVector };
                if (Shape.IsLocalRayOriginInMesh(ref ray, out hit))
                {

                    hit = new RayHit() { Location = startingTransform.Position, Normal = new Vector3(), T = 0 };
                    return true;
                }
            }
            hit = new RayHit();
            BoundingBox boundingBox;
            var transform = new AffineTransform {Translation = worldTransform.Position};
            Matrix3x3.CreateFromQuaternion(ref worldTransform.Orientation, out transform.LinearTransform);
            castShape.GetSweptLocalBoundingBox(ref startingTransform, ref transform, ref sweep, out boundingBox);
            var tri = PhysicsResources.GetTriangle();
            var hitElements = CommonResources.GetIntList();
            if (this.Shape.TriangleMesh.Tree.GetOverlaps(boundingBox, hitElements))
            {
                hit.T = float.MaxValue;
                for (int i = 0; i < hitElements.Count; i++)
                {
                    Shape.TriangleMesh.Data.GetTriangle(hitElements[i], out tri.vA, out tri.vB, out tri.vC);
                    AffineTransform.Transform(ref tri.vA, ref transform, out tri.vA);
                    AffineTransform.Transform(ref tri.vB, ref transform, out tri.vB);
                    AffineTransform.Transform(ref tri.vC, ref transform, out tri.vC);
                    Vector3 center;
                    Vector3.Add(ref tri.vA, ref tri.vB, out center);
                    Vector3.Add(ref center, ref tri.vC, out center);
                    Vector3.Multiply(ref center, 1f / 3f, out center);
                    Vector3.Subtract(ref tri.vA, ref center, out tri.vA);
                    Vector3.Subtract(ref tri.vB, ref center, out tri.vB);
                    Vector3.Subtract(ref tri.vC, ref center, out tri.vC);
                    tri.maximumRadius = tri.vA.LengthSquared();
                    float radius = tri.vB.LengthSquared();
                    if (tri.maximumRadius < radius)
                        tri.maximumRadius = radius;
                    radius = tri.vC.LengthSquared();
                    if (tri.maximumRadius < radius)
                        tri.maximumRadius = radius;
                    tri.maximumRadius = (float)Math.Sqrt(tri.maximumRadius);
                    tri.collisionMargin = 0;
                    var triangleTransform = new RigidTransform {Orientation = Quaternion.Identity, Position = center};
                    RayHit tempHit;
                    if (MPRToolbox.Sweep(castShape, tri, ref sweep, ref Toolbox.ZeroVector, ref startingTransform, ref triangleTransform, out tempHit) && tempHit.T < hit.T)
                    {
                        hit = tempHit;
                    }
                }
                tri.maximumRadius = 0;
                PhysicsResources.GiveBack(tri);
                CommonResources.GiveBack(hitElements);
                return hit.T != float.MaxValue;
            }
            PhysicsResources.GiveBack(tri);
            CommonResources.GiveBack(hitElements);
            return false;
        }
开发者ID:Indiefreaks,项目名称:igf,代码行数:69,代码来源:MobileMeshCollidable.cs

示例2: ConvexCastAgainstStatic

        /// <summary>
        /// 
        /// </summary>
        /// <param name="szx"></param>
        /// <param name="szy"></param>
        /// <param name="szz"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="normal"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public bool ConvexCastAgainstStatic( ConvexShape shape, Matrix xform, Vector3 initOffset, Vector3 sweep, out Vector3 normal, out Vector3 pos )
        {
            BoundingBox		bbox;
            AffineTransform identity	= AffineTransform.Identity;
            RigidTransform	transform	= new RigidTransform( xform.Translation + initOffset, Quaternion.CreateFromRotationMatrix(xform) );

            normal	= Vector3.Zero;
            pos		= xform.Translation + initOffset + sweep;

            shape.GetSweptLocalBoundingBox( ref transform, ref identity, ref sweep, out bbox );

            var candidates = Resources.GetCollisionEntryList();
            Space.BroadPhase.QueryAccelerator.BroadPhase.QueryAccelerator.GetEntries( bbox, candidates );

            float minT = float.MaxValue;
            bool  hit  = false;

            foreach ( var candidate in candidates )	{

                if ( candidate as ConvexCollidable != null ) {
                    continue;
                }

                RayHit rayHit;
                bool r = candidate.ConvexCast( shape, ref transform, ref sweep, out rayHit );

                if (!r) continue;

                if ( minT > rayHit.T ) {
                    hit   	= true;
                    minT	= rayHit.T;
                    normal	= rayHit.Normal;
                    pos		= rayHit.Location;
                }
            }

            return hit;
        }
开发者ID:demiurghg,项目名称:ShooterDemo,代码行数:49,代码来源:MPWorld.Casting.cs


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