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


C# Plane.Raycast方法代码示例

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


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

示例1: Raycast

		public int Raycast(Ray ray, uint[] triangles, Vector3f[] vertices, List<int> triangleMap)
		{
			double closestDist = double.MaxValue;
			int closestHit = -1;
			for (int i = 0; i < triangles.Length; i += 3)
			{
				Vector3 p0 = (Vector3)vertices[triangles[i+0]];
				Vector3 p1 = (Vector3)vertices[triangles[i+1]];
				Vector3 p2 = (Vector3)vertices[triangles[i+2]];
				
				Plane plane = new Plane(p0, p1, p2);
				//Console.WriteLine(i+" "+plane);
				double dist;
				if (plane.Raycast(ray, out dist))
				{
					Vector3 hitPoint = ray.origin+ray.direction*dist;
					Vector3 bary = MathUtil.Barycentric(p0, p1, p2, hitPoint);

					if (MathUtil.BarycentricIsInside(bary))
					{
						if (dist < closestDist)
						{
							closestDist = dist;
							closestHit = triangleMap[i/3];
						}
					}
				}
			}

			return closestHit;
		}
开发者ID:KurtLoeffler,项目名称:EnvyEngine,代码行数:31,代码来源:PolyMesh.cs

示例2: ScreenToCanvas

        private Vector3 ScreenToCanvas(Vector3 screenPosition)
        {
            Vector3 localPosition;
            Vector2 min;
            Vector2 max;
            var canvasSize = m_canvasRectTransform.sizeDelta;

            if (m_canvas.renderMode == RenderMode.ScreenSpaceOverlay || (m_canvas.renderMode == RenderMode.ScreenSpaceCamera && m_canvas.worldCamera == null))
            {
                localPosition = screenPosition;

                min = Vector2.zero;
                max = canvasSize;
            }
            else
            {
                var ray = m_canvas.worldCamera.ScreenPointToRay(screenPosition);
                var plane = new Plane(m_canvasRectTransform.forward, m_canvasRectTransform.position);

                float distance;
                if (plane.Raycast(ray, out distance) == false)
                {
                    throw new Exception("Is it practically possible?");
                };
                var worldPosition = ray.origin + ray.direction * distance;
                localPosition = m_canvasRectTransform.InverseTransformPoint(worldPosition);

                min = -Vector2.Scale(canvasSize, m_canvasRectTransform.pivot);
                max = Vector2.Scale(canvasSize, Vector2.one - m_canvasRectTransform.pivot);
            }

            // keep window inside canvas
            localPosition.x = Mathf.Clamp(localPosition.x, min.x + KeepWindowInCanvas, max.x - KeepWindowInCanvas);
            localPosition.y = Mathf.Clamp(localPosition.y, min.y + KeepWindowInCanvas, max.y - KeepWindowInCanvas);

            return localPosition;
        }
开发者ID:illvisation,项目名称:cellVIEW_bdbox,代码行数:37,代码来源:UIWindowBase.cs

示例3: PlaneTest

        public static bool PlaneTest(this Ray ray, Vector3 planeCenter, Quaternion planeRot, Vector2 planeSize, out Vector3 hitPosition, float gridSize = 0.0f, bool edge = true)
        {
            Plane plane = new Plane(planeRot * Vector3.up, planeCenter);

            hitPosition = Vector3.zero;
            float hitDistance = 0.0f;

            if (!plane.Raycast(ray, out hitDistance))
            {
                return false;
            }

            hitPosition = ray.origin + ray.direction * hitDistance;

            Vector3 hitOffset = hitPosition - planeCenter;

            float distanceLf = Vector3.Dot(hitOffset, planeRot * Vector3.left);
            float distanceUp = Vector3.Dot(hitOffset, planeRot * Vector3.forward);

            if (gridSize > 0.0f)
            {
                if (edge)
                {
                    distanceLf = distanceLf.SnapToEdge(gridSize);
                    distanceUp = distanceUp.SnapToEdge(gridSize);
                }
                else
                {
                    distanceLf = distanceLf.SnapToCenter(gridSize);
                    distanceUp = distanceUp.SnapToCenter(gridSize);
                }
            }

            hitPosition = planeCenter;
            hitPosition += (planeRot * Vector3.left) * distanceLf;
            hitPosition += (planeRot * Vector3.forward) * distanceUp;

            return true;
        }
开发者ID:katalist5296,项目名称:SanAndreasUnity,代码行数:39,代码来源:MathEx.cs


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