Exemplo n.º 1
0
//        public static double GetCoord(double i1, double i2, double w1, double w2, double p)
//        {
//            return ((p - i1) / (i2 - i1)) * (w2 - w1) + w1;
//        }

        public override Vector2D GetTexCoord(Vector3D p, uint subIdx)
        {
            p = p - origin;

            Vector3D.RotX(1.5, ref p.Y, ref p.Z);
            Vector3D.RotZ(-2.5, ref p.X, ref p.Y);

            double phi = Math.Acos(p.Z / radius);
            double S   = Math.Sqrt(p.X * p.X + p.Y * p.Y);
            double theta;

            if (p.X > 0)
            {
                theta = Math.Asin(p.Y / S);//Atan(py/px);
            }
            else
            {
                theta = Math.PI - Math.Asin(p.Y / S);// Math.Atan(py / px);
            }
            if (theta < 0)
            {
                theta = 2.0 * Math.PI + theta;
            }

            double x1 = Vector3D.GetCoord(0.0, Math.PI * 2.0,
                                          0.0, 1 /*imgBitmap.Width - 1*/, theta);
            double y1 = Vector3D.GetCoord(0.0, Math.PI, 0.0,
                                          1 /*imgBitmap.Height - 1*/, phi);

            // NOTE: Do clamping etc. elsewhere
            return(new Vector2D(x1, y1));

            /*int i1 = (int)x1, j1 = (int)y1;
             * if (i1 >= 0 && j1 >= 0 && i1 < imgBitmap.Width &&
             *             j1 < imgBitmap.Height)
             * {
             *  Color clr = imgBitmap.GetPixel(i1, j1);
             *  color.x = clr.R;
             *  color.y = clr.G;
             *  color.z = clr.B;
             * }*/
        }
        public override Vector2D GetTexCoord(Vector3D p, uint subIdx)
        {
            double dx = 1; // imgBitmap.Width;
            double dy = 1; // imgBitmap.Height;

            Vector3D U;
            Vector3D V;
            Vector3D v2;
            double   distp = 0;

            U  = points[triangles[subIdx].P3] - points[triangles[subIdx].P2];
            v2 = p - points[triangles[subIdx].P2];

            distp = Vector3D.modv(points[triangles[subIdx].P2] - p);

            V = points[triangles[subIdx].P1] - points[triangles[subIdx].P2];

            double dU = Vector3D.modv(U);
            double dV = Vector3D.modv(V);

            U.Normalize();
            v2.Normalize();
            double cost = Vector3D.Dot(U, v2);
            double t    = Math.Acos(cost);

            double distY = 0, distX = 0;

            distY = dU - distp * Math.Cos(t);
            distX = dV - distp * Math.Sin(t);

            double x1 = 0;
            double y1 = 0;

            int tIdx = (int)subIdx * 3;

            y1 = Vector3D.GetCoord(0, dU, tCoords[tIdx + 2].Y, tCoords[tIdx + 1].Y, distY);
            x1 = Vector3D.GetCoord(0, dV, tCoords[tIdx].X, tCoords[tIdx + 1].X, distX);

            return(new Vector2D(x1, y1));
        }