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


C# Ray.ToWorld方法代码示例

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


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

示例1: ToWorld

        public void ToWorld()
        {
            Vector3F startPoint = new Vector3F(10, 20, -40);
              Vector3F endPoint = new Vector3F(-22, 34, 45);
              Ray ray = new Ray(startPoint, (endPoint - startPoint).Normalized, (endPoint - startPoint).Length);

              Pose pose = new Pose(new Vector3F(-5, 100, -20), Matrix33F.CreateRotation(new Vector3F(1, 2, 3), 0.123f));
              startPoint = pose.ToWorldPosition(startPoint);
              endPoint = pose.ToWorldPosition(endPoint);
              ray.ToWorld(ref pose);

              Assert.IsTrue(Vector3F.AreNumericallyEqual(startPoint, ray.Origin));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(endPoint, ray.Origin + ray.Direction * ray.Length));
        }
开发者ID:,项目名称:,代码行数:14,代码来源:

示例2: ComputeCollision

        public override void ComputeCollision(ContactSet contactSet, CollisionQueryType type)
        {
            if (type == CollisionQueryType.ClosestPoints)
              {
            // Just use normal composite shape algorithm.
            _triangleMeshAlgorithm.ComputeCollision(contactSet, type);
            return;
              }

              Debug.Assert(type != CollisionQueryType.ClosestPoints, "Closest point queries should have already been handled!");

              // Mesh = A, Ray = B
              IGeometricObject meshObject = contactSet.ObjectA.GeometricObject;
              IGeometricObject rayObject = contactSet.ObjectB.GeometricObject;

              // Object A should be the mesh, swap objects if necessary.
              bool swapped = (meshObject.Shape is RayShape);
              if (swapped)
            MathHelper.Swap(ref rayObject, ref meshObject);

              RayShape rayShape = rayObject.Shape as RayShape;
              TriangleMeshShape meshShape = meshObject.Shape as TriangleMeshShape;

              // Check if shapes are correct.
              if (rayShape == null || meshShape == null)
            throw new ArgumentException("The contact set must contain a ray and a triangle mesh shape.", "contactSet");

              // Assume no contact.
              contactSet.HaveContact = false;

              // Get transformations.
              Vector3F rayScale = rayObject.Scale;
              Pose rayPose = rayObject.Pose;
              Vector3F meshScale = meshObject.Scale;
              Pose meshPose = meshObject.Pose;

              // Ray in world space.
              Ray rayWorld = new Ray(rayShape);
              rayWorld.Scale(ref rayScale);     // Scale ray.
              rayWorld.ToWorld(ref rayPose);    // Transform ray to world space.

              // Ray in local scaled space of the mesh.
              Ray ray = rayWorld;
              ray.ToLocal(ref meshPose);   // Transform ray to local space of composite.

              // Ray in local unscaled space of the mesh.
              Ray rayUnscaled = ray;
              var inverseCompositeScale = Vector3F.One / meshScale;
              rayUnscaled.Scale(ref inverseCompositeScale);

              ITriangleMesh triangleMesh = meshShape.Mesh;
              bool isTwoSided = meshShape.IsTwoSided;

              if (meshShape.Partition != null)
              {
            // ----- Mesh with BVH vs. Ray -----
            foreach (var childIndex in meshShape.Partition.GetOverlaps(rayUnscaled))
            {
              Triangle triangle = triangleMesh.GetTriangle(childIndex);

              AddContact(contactSet, swapped, type, ref rayWorld, ref ray, ref triangle, childIndex, ref meshPose, ref meshScale, isTwoSided);

              if (type == CollisionQueryType.Boolean && contactSet.HaveContact)
            break; // We can abort early.
            }
              }
              else
              {
            // ----- Mesh vs. Ray -----
            var rayUnscaledDirectionInverse = new Vector3F(
            1 / rayUnscaled.Direction.X,
            1 / rayUnscaled.Direction.Y,
            1 / rayUnscaled.Direction.Z);

            float epsilon = Numeric.EpsilonF * (1 + meshObject.Aabb.Extent.Length);

            int numberOfTriangles = triangleMesh.NumberOfTriangles;
            for (int i = 0; i < numberOfTriangles; i++)
            {
              Triangle triangle = triangleMesh.GetTriangle(i);

              // Make ray vs AABB check first. We could skip this because the ray vs. triangle test
              // is also fast. But experiments (ray vs sphere mesh) have shown that making an
              // additional ray vs. AABB test first makes the worst case more than 20% faster.
              if (GeometryHelper.HaveContact(triangle.Aabb, rayUnscaled.Origin, rayUnscaledDirectionInverse, rayUnscaled.Length, epsilon))
              {
            AddContact(contactSet, swapped, type, ref rayWorld, ref ray, ref triangle, i, ref meshPose, ref meshScale, isTwoSided);

            // We have contact and stop for boolean queries.
            if (contactSet.HaveContact && type == CollisionQueryType.Boolean)
              break;
              }
            }
              }
        }
开发者ID:,项目名称:,代码行数:95,代码来源:


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