public static bool InfiniteCylinderSigned(Vector3f vOrigin, Vector3f vDirection, Vector3f vCylOrigin, Vector3f vCylAxis, float fRadius, out float fRayT)
        {
            // [RMS] ugh this is shit...not even sure it works in general, but works for a ray inside cylinder

            fRayT = 0.0f;


            Vector3f AB = vCylAxis;
            Vector3f AO = (vOrigin - vCylOrigin);

            if (AO.DistanceSquared(AO.Dot(AB) * AB) > fRadius * fRadius)
            {
                return(false);
            }

            Vector3f AOxAB = AO.Cross(AB);
            Vector3f VxAB  = vDirection.Cross(AB);
            float    ab2   = AB.Dot(AB);
            float    a     = VxAB.Dot(VxAB);
            float    b     = 2 * VxAB.Dot(AOxAB);
            float    c     = AOxAB.Dot(AOxAB) - (fRadius * fRadius * ab2);

            double discrim = b * b - 4 * a * c;

            if (discrim <= 0)
            {
                return(false);
            }
            discrim = Math.Sqrt(discrim);
            fRayT   = (-b - (float)discrim) / (2 * a);
            //float t1 = (-b + (float)discrim) / (2 * a);

            return(true);
        }
Exemplo n.º 2
0
        void update_uv_upwind_expmap(GraphNode node)
        {
            int      vid = node.id;
            Vector3f pos = PositionF(vid);

            Vector2f avg_uv     = Vector2f.Zero;
            float    fWeightSum = 0;
            int      nbr_count  = 0;

            foreach (var nbr_id in NeighboursF(node.id))
            {
                GraphNode nbr_node = get_node(nbr_id, false);
                if (nbr_node.frozen)
                {
                    Vector3f nbr_pos   = PositionF(nbr_id);
                    Frame3f  nbr_frame = new Frame3f(nbr_pos, NormalF(nbr_id));
                    Vector2f nbr_uv    = propagate_uv(pos, nbr_node.uv, ref nbr_frame, ref SeedFrame);
                    float    fWeight   = 1.0f / (pos.DistanceSquared(nbr_pos) + MathUtil.ZeroTolerancef);
                    avg_uv     += fWeight * nbr_uv;
                    fWeightSum += fWeight;
                    nbr_count++;
                }
            }
            Util.gDevAssert(nbr_count > 0);

            //avg_uv /= (float)nbr_count;
            avg_uv /= fWeightSum;
            node.uv = avg_uv;
        }