コード例 #1
0
 /// <summary> Map ray *from* local frame coordinates into "world" coordinates </summary>
 public Ray3f FromFrame(Ray3f r)
 {
     return(new Ray3f(FromFrameP(r.Origin), FromFrameV(r.Direction)));
 }
コード例 #2
0
 ///<summary> Map ray *into* local coordinates of Frame </summary>
 public Ray3f ToFrame(Ray3f r)
 {
     return(new Ray3f(ToFrameP(r.Origin), ToFrameV(r.Direction)));
 }
コード例 #3
0
ファイル: Frame3f.cs プロジェクト: larsbrubaker/agg-sharp
		/// <summary> Map ray *from* local frame coordinates into "world" coordinates </summary>
		public Ray3f FromFrame(ref Ray3f r)
		{
			return new Ray3f(FromFrameP(ref r.Origin), FromFrameV(ref r.Direction));
		}
コード例 #4
0
ファイル: Frame3f.cs プロジェクト: larsbrubaker/agg-sharp
		///<summary> Map ray *into* local coordinates of Frame </summary>
		public Ray3f ToFrame(ref Ray3f r)
		{
			return new Ray3f(ToFrameP(ref r.Origin), ToFrameV(ref r.Direction));
		}
コード例 #5
0
 public IntrRay3fTriangle3f(Ray3f r, Triangle3f t)
 {
     ray = r; triangle = t;
 }
コード例 #6
0
        /// <summary>
        /// minimal intersection test, computes ray-t
        /// </summary>
        public static bool Intersects(ref Ray3f ray, ref Vector3f V0, ref Vector3f V1, ref Vector3f V2, out float rayT)
        {
            // Compute the offset origin, edges, and normal.
            Vector3f diff   = ray.Origin - V0;
            Vector3f edge1  = V1 - V0;
            Vector3f edge2  = V2 - V0;
            Vector3f normal = edge1.Cross(ref edge2);

            rayT = float.MaxValue;

            // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
            // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
            //   |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
            //   |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
            //   |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
            float DdN = ray.Direction.Dot(ref normal);
            float sign;

            if (DdN > MathUtil.ZeroTolerance)
            {
                sign = 1;
            }
            else if (DdN < -MathUtil.ZeroTolerance)
            {
                sign = -1;
                DdN  = -DdN;
            }
            else
            {
                // Ray and triangle are parallel, call it a "no intersection"
                // even if the ray does intersect.
                return(false);
            }

            Vector3f cross  = diff.Cross(ref edge2);
            float    DdQxE2 = sign * ray.Direction.Dot(ref cross);

            if (DdQxE2 >= 0)
            {
                cross = edge1.Cross(ref diff);
                float DdE1xQ = sign * ray.Direction.Dot(ref cross);
                if (DdE1xQ >= 0)
                {
                    if (DdQxE2 + DdE1xQ <= DdN)
                    {
                        // Line intersects triangle, check if ray does.
                        float QdN = -sign *diff.Dot(ref normal);

                        if (QdN >= 0)
                        {
                            // Ray intersects triangle.
                            float inv = (1) / DdN;
                            rayT = QdN * inv;
                            return(true);
                        }
                        // else: t < 0, no intersection
                    }
                    // else: b1+b2 > 1, no intersection
                }
                // else: b2 < 0, no intersection
            }
            // else: b1 < 0, no intersection

            return(false);
        }