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


C# Plane.Scale方法代码示例

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


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

示例1: NegativeUniformScaling

        public void NegativeUniformScaling()
        {
            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;

              Vector3F scale = new Vector3F(-3.5f);
              point0 *= scale;
              point1 *= scale;
              point2 *= scale;
              pointAbove *= scale;
              pointBelow *= scale;
              plane.Scale(ref scale);

              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:,项目名称:,代码行数:27,代码来源:

示例2: ComputeCollision

        public override void ComputeCollision(ContactSet contactSet, CollisionQueryType type)
        {
            Debug.Assert(contactSet.Count <= 1, "Ray vs. plane should have at max 1 contact.");

              // Object A should be the plane.
              // Object B should be the ray.
              IGeometricObject planeObject = contactSet.ObjectA.GeometricObject;
              IGeometricObject rayObject = contactSet.ObjectB.GeometricObject;

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

              PlaneShape planeShape = planeObject.Shape as PlaneShape;
              RayShape rayShape = rayObject.Shape as RayShape;

              // Check if A is really a plane and B is a ray.
              if (planeShape == null || rayShape == null)
            throw new ArgumentException("The contact set must contain a plane and a ray.", "contactSet");

              // Get transformations.
              Vector3F planeScale = planeObject.Scale;
              Vector3F rayScale = rayObject.Scale;
              Pose rayPose = rayObject.Pose;
              Pose planePose = planeObject.Pose;

              // Apply scale to plane.
              Plane plane = new Plane(planeShape);
              plane.Scale(ref planeScale);

              // Apply scale to ray and transform ray into local space of plane.
              Ray ray = new Ray(rayShape);
              ray.Scale(ref rayScale);      // Scale ray.
              ray.ToWorld(ref rayPose);     // Transform ray to world space.
              ray.ToLocal(ref planePose);   // Transform ray to local space of plane.

              // Convert ray into a line segment.
              LineSegment segment = new LineSegment { Start = ray.Origin, End = ray.Origin + ray.Direction * ray.Length };

              // Check if ray origin is inside the plane. Otherwise call plane vs. ray query.
              Vector3F linePoint;
              Vector3F planePoint = Vector3F.Zero;
              if (Vector3F.Dot(segment.Start, plane.Normal) <= plane.DistanceFromOrigin)
              {
            // The origin of the ray is below the plane.
            linePoint = segment.Start;
            contactSet.HaveContact = true;
              }
              else
              {
            // The origin of the ray is above the plane.
            contactSet.HaveContact = GeometryHelper.GetClosestPoints(plane, segment, out linePoint, out planePoint);
              }

              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;
              }

              // ----- Create contact info.
              Vector3F position;
              float penetrationDepth;
              if (contactSet.HaveContact)
              {
            // We have a contact.
            position = planePose.ToWorldPosition(linePoint);
            penetrationDepth = (linePoint - segment.Start).Length;
              }
              else
              {
            // Closest points, but separated.
            position = planePose.ToWorldPosition((planePoint + linePoint) / 2);
            penetrationDepth = -(linePoint - planePoint).Length;
              }

              Vector3F normal = planePose.ToWorldDirection(plane.Normal);
              if (swapped)
            normal = -normal;

              Contact contact = ContactHelper.CreateContact(contactSet, position, normal, penetrationDepth, contactSet.HaveContact);
              ContactHelper.Merge(contactSet, contact, type, CollisionDetection.ContactPositionTolerance);
        }
开发者ID:,项目名称:,代码行数:85,代码来源:


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