getU() public method

public getU ( float xPercent ) : float
xPercent float
return float
Example #1
0
        /// <summary>
        /// Used to generate a ring of vertices with the uvMapping appropriate for a cylinder wall (increments in +x)
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="faces"></param>
        /// <param name="radius"></param>
        /// <param name="height"></param>
        /// <param name="startAngle"></param>
        /// <param name="endAngle"></param>
        /// <param name="v"></param>
        /// <param name="area"></param>
        /// <param name="yCos"></param>
        /// <param name="ySin"></param>
        /// <returns></returns>
        public List<Vertex> generateRadialVerticesFlatUVs(Vector3 offset, int faces, float radius, float height, float startAngle, float endAngle, float v, UVArea area, float yCos, float ySin)
        {
            List<Vertex> verts = new List<Vertex>();
            float startRad = startAngle * Mathf.Deg2Rad;
            float endRad = endAngle * Mathf.Deg2Rad;
            float totalRad = endRad - startRad;
            float radPerFace = (float)((2.0 * Math.PI) / faces);
            float radPerSub = radPerFace / subdivision;
            int numOfFaces = (int)Math.Round(totalRad / radPerFace, 0);

            float rads, xCos, zSin, nx, ny, nz, x, y, z, percentTotalAngle;
            float subRads, x2 = 0, z2 = 0, x3, z3, xCos2 = 0, zSin2 = 0, nextRads = 0, nextPerc=0, subPerc, lerp;

            y = height + offset.y;
            ny = ySin;

            for (int i = 0; i < numOfFaces + 1; i++)
            {
                if (i > 0)//vars were caled last round for the interpolation
                {
                    rads = nextRads;
                    percentTotalAngle = nextPerc;
                    xCos = xCos2;
                    zSin = zSin2;
                    x = x2;
                    z = z2;
                }
                else
                {
                    rads = startRad + (radPerFace * i);
                    percentTotalAngle = (rads - startRad) / totalRad;
                    xCos = Mathf.Cos(rads);
                    zSin = Mathf.Sin(rads);
                    x = xCos * radius + offset.x;
                    z = zSin * radius + offset.z;
                }

                nx = xCos * yCos;
                nz = zSin * yCos;
                verts.Add(addVertex(new Vector3(x, y, z), new Vector3(nx, ny, nz), new Vector2(area.getU(percentTotalAngle), v)));

                //calculate the points/etc for the next panel face, to lerp between positions; data is re-used next iteration if present
                nextRads = startRad + (radPerFace * (i + 1));
                nextPerc = (nextRads - startRad) / totalRad;
                xCos2 = Mathf.Cos(nextRads);
                zSin2 = Mathf.Sin(nextRads);
                x2 = xCos2 * radius + offset.x;
                z2 = zSin2 * radius + offset.z;

                //do not add subdivision panel if the next vertex is the last one in the ring
                if (i == numOfFaces) { break; }
                //if was the last vert... do not add subs
                for (int k = 1; k < subdivision; k++)
                {
                    lerp = (float)k / subdivision;
                    x3 = Mathf.Lerp(x, x2, lerp);
                    z3 = Mathf.Lerp(z, z2, lerp);
                    subRads = rads + (radPerSub * k);//subangle used for normal calc... position calculated from interpolation to maintain cylinder side matching
                    subPerc = (subRads - startRad) / totalRad;
                    xCos = Mathf.Cos(subRads);
                    zSin = Mathf.Sin(subRads);
                    nx = xCos * yCos;
                    nz = zSin * yCos;
                    verts.Add(addVertex(new Vector3(x3, y, z3), new Vector3(nx, ny, nz), new Vector2(area.getU(subPerc), v)));
                }
            }
            return verts;
        }
Example #2
0
        public List<Vertex> generateRadialVerticesFlatUVs(Vector3 offset, int faces, float radius, float height, float startAngle, float endAngle, float v, UVArea area, float yCos, float ySin)
        {
            List<Vertex> verts = new List<Vertex>();
            float totalAngle = endAngle - startAngle;
            float anglePerFace = 360f / faces;
            int numOfFaces = (int)(totalAngle / anglePerFace);

            float anglePerVert = totalAngle / (float)(numOfFaces + 1);

            float angle, xCos, zSin, nx, ny, nz, x, y, z, percentTotalAngle;

            for (int i = 0; i < numOfFaces + 1; i++)
            {
                angle = startAngle + anglePerFace * i;
                percentTotalAngle = (angle - startAngle) / totalAngle;

                xCos = Mathf.Cos(angle * Mathf.Deg2Rad);
                zSin = Mathf.Sin(angle * Mathf.Deg2Rad);
                x = xCos * radius + offset.x;
                y = height + offset.y;
                z = zSin * radius + offset.z;
                nx = xCos * yCos;
                ny = ySin;
                nz = zSin * yCos;
                verts.Add(addVertex(new Vector3(x, y, z), new Vector3(nx, ny, nz), new Vector2(area.getU(percentTotalAngle), v)));
            }
            return verts;
        }
Example #3
0
        /// <summary>
        /// Used to generate a ring of vertices with the uvMapping appropriate for a cylinder wall (increments in +x)
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="faces"></param>
        /// <param name="radius"></param>
        /// <param name="height"></param>
        /// <param name="startAngle"></param>
        /// <param name="endAngle"></param>
        /// <param name="v"></param>
        /// <param name="area"></param>
        /// <param name="yCos"></param>
        /// <param name="ySin"></param>
        /// <returns></returns>
        public List <Vertex> generateRadialVerticesFlatUVs(Vector3 offset, int faces, float radius, float height, float startAngle, float endAngle, float v, UVArea area, float yCos, float ySin)
        {
            List <Vertex> verts      = new List <Vertex>();
            float         startRad   = startAngle * Mathf.Deg2Rad;
            float         endRad     = endAngle * Mathf.Deg2Rad;
            float         totalRad   = endRad - startRad;
            float         radPerFace = (float)((2.0 * Math.PI) / faces);
            float         radPerSub  = radPerFace / subdivision;
            int           numOfFaces = (int)Math.Round(totalRad / radPerFace, 0);

            float rads, xCos, zSin, nx, ny, nz, x, y, z, percentTotalAngle;
            float subRads, x2 = 0, z2 = 0, x3, z3, xCos2 = 0, zSin2 = 0, nextRads = 0, nextPerc = 0, subPerc, lerp;

            y  = height + offset.y;
            ny = ySin;

            for (int i = 0; i < numOfFaces + 1; i++)
            {
                if (i > 0)//vars were caled last round for the interpolation
                {
                    rads = nextRads;
                    percentTotalAngle = nextPerc;
                    xCos = xCos2;
                    zSin = zSin2;
                    x    = x2;
                    z    = z2;
                }
                else
                {
                    rads = startRad + (radPerFace * i);
                    percentTotalAngle = (rads - startRad) / totalRad;
                    xCos = Mathf.Cos(rads);
                    zSin = Mathf.Sin(rads);
                    x    = xCos * radius + offset.x;
                    z    = zSin * radius + offset.z;
                }

                nx = xCos * yCos;
                nz = zSin * yCos;
                verts.Add(addVertex(new Vector3(x, y, z), new Vector3(nx, ny, nz), new Vector2(area.getU(percentTotalAngle), v)));

                //calculate the points/etc for the next panel face, to lerp between positions; data is re-used next iteration if present
                nextRads = startRad + (radPerFace * (i + 1));
                nextPerc = (nextRads - startRad) / totalRad;
                xCos2    = Mathf.Cos(nextRads);
                zSin2    = Mathf.Sin(nextRads);
                x2       = xCos2 * radius + offset.x;
                z2       = zSin2 * radius + offset.z;

                //do not add subdivision panel if the next vertex is the last one in the ring
                if (i == numOfFaces)
                {
                    break;
                }
                //if was the last vert... do not add subs
                for (int k = 1; k < subdivision; k++)
                {
                    lerp    = (float)k / subdivision;
                    x3      = Mathf.Lerp(x, x2, lerp);
                    z3      = Mathf.Lerp(z, z2, lerp);
                    subRads = rads + (radPerSub * k);//subangle used for normal calc... position calculated from interpolation to maintain cylinder side matching
                    subPerc = (subRads - startRad) / totalRad;
                    xCos    = Mathf.Cos(subRads);
                    zSin    = Mathf.Sin(subRads);
                    nx      = xCos * yCos;
                    nz      = zSin * yCos;
                    verts.Add(addVertex(new Vector3(x3, y, z3), new Vector3(nx, ny, nz), new Vector2(area.getU(subPerc), v)));
                }
            }
            return(verts);
        }