Ejemplo n.º 1
0
        public void getUV(V3 P, out float u, out float v)
        {
            V3 AB = B - A;
            V3 AC = C - A;

            V3 AP = P - A;

            //alfa
            u = V3.prod_scal(ref AP, ref AB) / AB.Norme2();
            //beta
            V3 aux = AP - u * AB;

            v = V3.prod_scal(ref aux, ref AC) / AC.Norme2();
        }
Ejemplo n.º 2
0
        public bool intersection_RayObject(V3 R0, V3 Rd, out V3 P, out V3 N, out float t)
        {
            V3 R0A;

            P = new V3(0, 0, 0);
            float aux1;

            V3 AB = B - A;
            V3 AC = C - A;

            N = AB ^ AC;
            N.Normalize();

            R0A = A - R0;

            t    = V3.prod_scal(ref R0A, ref N);
            aux1 = V3.prod_scal(ref Rd, ref N);

            if (aux1 == 0)
            {
                t = -1;
                return(false);
            }

            t /= aux1;

            if (t < MIN_DISTANCE)
            {
                return(false);
            }

            P = R0 + t * Rd;

            getUV(P, out float u, out float v);
            if (u < 0 || u > 1 || v < 0 || v > 1)
            {
                P = new V3(0, 0, 0);
                t = -1;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool intersection_RayObject(V3 R0, V3 Rd, out V3 P, out V3 N, out float t)
        {
            V3    CR0;
            float A, B, C, delta, t1, t2;

            P = new V3(0, 0, 0);
            N = new V3(0, 0, 0);
            t = -1;

            CR0 = R0 - Center;

            // (t^2) rd^2 + 2*t*rd*b +b^2 = R^2
            A = Rd.Norme2();
            B = 2f * V3.prod_scal(ref Rd, ref CR0);
            C = CR0.Norme2() - (R * R);

            delta = (B * B) - (4 * A * C);
            if (delta < 0)
            {
                return(false);
            }

            t1 = (-B + (float)Math.Sqrt(delta)) / (2 * A);
            t2 = (-B - (float)Math.Sqrt(delta)) / (2 * A);
            t  = (t1 > 0 && t1 < t2) ? t1 : t2;
            if (t < MIN_DISTANCE)
            {
                return(false);
            }

            P = R0 + t * Rd;
            N = getPixelSphereNormal(P);


            return(true);
        }