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


C# Plane.ToWorld方法代码示例

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


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

示例1: ComputeCollision

        public override void ComputeCollision(ContactSet contactSet, CollisionQueryType type)
        {
            // Object A should be the plane.
              // Object B should be the other object.
              IGeometricObject planeObject = contactSet.ObjectA.GeometricObject;
              IGeometricObject convexObject = contactSet.ObjectB.GeometricObject;

              // Swap objects if necessary.
              bool swapped = (convexObject.Shape is PlaneShape);
              if (swapped)
            MathHelper.Swap(ref planeObject, ref convexObject);

              PlaneShape planeShape = planeObject.Shape as PlaneShape;
              ConvexShape convexShape = convexObject.Shape as ConvexShape;

              // Check if shapes are correct.
              if (planeShape == null || convexShape == null)
            throw new ArgumentException("The contact set must contain a plane and a convex shape.", "contactSet");

              // Get transformations.
              Vector3F scalePlane = planeObject.Scale;
              Vector3F scaleB = convexObject.Scale;
              Pose planePose = planeObject.Pose;
              Pose poseB = convexObject.Pose;

              // Apply scale to plane and transform plane into world space.
              Plane planeWorld = new Plane(planeShape);
              planeWorld.Scale(ref scalePlane);         // Scale plane.
              planeWorld.ToWorld(ref planePose);        // Transform plane to world space.

              // Transform plane normal to local space of convex.
              Vector3F planeNormalLocalB = poseB.ToLocalDirection(planeWorld.Normal);

              // Get support vertex nearest to the plane.
              Vector3F supportVertexBLocal = convexShape.GetSupportPoint(-planeNormalLocalB, scaleB);

              // Transform support vertex into world space.
              Vector3F supportVertexBWorld = poseB.ToWorldPosition(supportVertexBLocal);

              // Project vertex onto separating axis (given by plane normal).
              float distance = Vector3F.Dot(supportVertexBWorld, planeWorld.Normal);

              // Check for collision.
              float penetrationDepth = planeWorld.DistanceFromOrigin - distance;
              contactSet.HaveContact = (penetrationDepth >= 0);

              if (type == CollisionQueryType.Boolean || (type == CollisionQueryType.Contacts && !contactSet.HaveContact))
              {
            // HaveContact queries can exit here.
            // GetContacts queries can exit here if we don't have a contact.
            return;
              }

              // Position is between support vertex and plane.
              Vector3F position = supportVertexBWorld + planeWorld.Normal * (penetrationDepth / 2);
              Vector3F normal = (swapped) ? -planeWorld.Normal : planeWorld.Normal;

              // Update contact set.
              Contact contact = ContactHelper.CreateContact(contactSet, position, normal, penetrationDepth, false);
              ContactHelper.Merge(contactSet, contact, type, CollisionDetection.ContactPositionTolerance);

              if (CollisionDetection.FullContactSetPerFrame
              && type == CollisionQueryType.Contacts
              && contactSet.Count > 0
              && contactSet.Count < 4)
              {
            // Special treatment for tetrahedra: Test all vertices against plane.
            IList<Vector3F> vertices = null;
            if (convexShape is ConvexHullOfPoints)
            {
              var convexHullOfPoints = (ConvexHullOfPoints)convexShape;
              vertices = convexHullOfPoints.Points;
            }
            else if (convexShape is ConvexPolyhedron)
            {
              var convexPolyhedron = (ConvexPolyhedron)convexShape;
              vertices = convexPolyhedron.Vertices;
            }

            if (vertices != null && vertices.Count <= 8)
            {
              // Convex has 8 or less vertices. Explicitly test all vertices against the plane.
              int numberOfVertices = vertices.Count;
              for (int i = 0; i < numberOfVertices; i++)
              {
            // Test is the same as above.
            var vertex = vertices[i];
            Vector3F scaledVertex = vertex * scaleB;
            if (scaledVertex != supportVertexBLocal) // supportVertexBLocal has already been added.
            {
              Vector3F vertexWorld = poseB.ToWorldPosition(scaledVertex);
              distance = Vector3F.Dot(vertexWorld, planeWorld.Normal);
              penetrationDepth = planeWorld.DistanceFromOrigin - distance;
              if (penetrationDepth >= 0)
              {
                position = vertexWorld + planeWorld.Normal * (penetrationDepth / 2);
                normal = (swapped) ? -planeWorld.Normal : planeWorld.Normal;
                contact = ContactHelper.CreateContact(contactSet, position, normal, penetrationDepth, false);
                ContactHelper.Merge(contactSet, contact, type, CollisionDetection.ContactPositionTolerance);
              }
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例2: ToWorld

        public void ToWorld()
        {
            Vector3F point0 = new Vector3F(1, 0.5f, 0.5f);
              Vector3F point1 = new Vector3F(0.5f, 1, 0.5f);
              Vector3F point2 = new Vector3F(0.5f, 0.5f, 1);
              Plane plane = new Plane(point0, point1, point2);

              Vector3F pointAbove = plane.Normal * plane.DistanceFromOrigin * 2;
              Vector3F pointBelow = plane.Normal * plane.DistanceFromOrigin * 0.5f;
              Assert.IsTrue(Vector3F.Dot(plane.Normal, pointAbove) > plane.DistanceFromOrigin);
              Assert.IsTrue(Vector3F.Dot(plane.Normal, pointBelow) < plane.DistanceFromOrigin);

              Pose pose = new Pose(new Vector3F(-5, 100, -20), Matrix33F.CreateRotation(new Vector3F(1, 2, 3), 0.123f));
              point0 = pose.ToWorldPosition(point0);
              point1 = pose.ToWorldPosition(point1);
              point2 = pose.ToWorldPosition(point2);
              pointAbove = pose.ToWorldPosition(pointAbove);
              pointBelow = pose.ToWorldPosition(pointBelow);
              plane.ToWorld(ref pose);

              Assert.IsTrue(plane.Normal.IsNumericallyNormalized);

              Vector3F dummy;
              Assert.IsTrue(GeometryHelper.GetClosestPoint(plane, point0, out dummy));
              Assert.IsTrue(GeometryHelper.GetClosestPoint(plane, point1, out dummy));
              Assert.IsTrue(GeometryHelper.GetClosestPoint(plane, point2, out dummy));
              Assert.IsTrue(Vector3F.Dot(plane.Normal, pointAbove) > plane.DistanceFromOrigin);
              Assert.IsTrue(Vector3F.Dot(plane.Normal, pointBelow) < plane.DistanceFromOrigin);
        }
开发者ID:,项目名称:,代码行数:29,代码来源:


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