Exemplo n.º 1
0
        public void CalcUVCoords(gxtTextureCoordinateType uvType)
        {
            gxtDebug.Assert(texture != null);

            Vector2 topLeft = new Vector2(-texture.Width * 0.5f, -texture.Height * 0.5f);
            Vector2 oneOverSizeVector = new Vector2(1.0f / texture.Width, 1.0f / texture.Height);

            if (uvType == gxtTextureCoordinateType.CLAMP)
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    verts[i].TextureCoordinate = new Vector2(gxtMath.Clamp((verts[i].Position.X - topLeft.X) * oneOverSizeVector.X, 0.0f, 1.0f), gxtMath.Clamp((verts[i].Position.Y - topLeft.Y) * oneOverSizeVector.Y, 0.0f, 1.0f));
                }
            }
            else if (uvType == gxtTextureCoordinateType.WRAP)
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    verts[i].TextureCoordinate = new Vector2(((verts[i].Position.X - topLeft.X) * oneOverSizeVector.X) % 1.0f, ((verts[i].Position.Y - topLeft.Y) * oneOverSizeVector.Y) % 1.0f);
                }
            }
            else
            {
                gxtDebug.Assert(false, "Texture Coordinate Type Not Yet Implemented!");
            }
            vertexBuffer.SetData<VertexPositionColorTexture>(verts);
        }
Exemplo n.º 2
0
 public gxtDynamicMesh(Vector2[] verts, gxtIMaterial material, Texture2D texture, gxtTextureCoordinateType uvType = gxtTextureCoordinateType.CLAMP, bool setDefaultIndices = true)
 {
     gxtDebug.Assert(gxtRoot.SingletonIsInitialized);
     this.material = material;
     this.texture = texture;
     Vector2[] texCoords = gxtGeometry.CalculateTextureCoordinates(verts, texture.Width, texture.Height, uvType);
     SetVertices(verts, texCoords, setDefaultIndices);
 }
Exemplo n.º 3
0
        public gxtDrawablePolygon(Vector2[] vertices, Texture2D texture, gxtTextureCoordinateType uvType = gxtTextureCoordinateType.CLAMP)
        {
            gxtDebug.Assert(vertices != null && vertices.Length >= 3);
            indexBuffer = new IndexBuffer(gxtRoot.Singleton.Graphics, typeof(int), 3 + ((vertices.Length - 3) * 3), BufferUsage.WriteOnly);
            vertexBuffer = new VertexBuffer(gxtRoot.Singleton.Graphics, typeof(VertexPositionColorTexture), vertices.Length, BufferUsage.WriteOnly);

            Triangulate(vertices);
            SetupTexture(texture, uvType);
        }
Exemplo n.º 4
0
        public gxtDynamicIndexedPrimitive(Vector2[] verts, PrimitiveType primitiveType, gxtIMaterial material, Texture2D texture, gxtTextureCoordinateType uvType = gxtTextureCoordinateType.CLAMP)
        {
            gxtDebug.Assert(gxtRoot.SingletonIsInitialized);
            this.primitiveType = primitiveType;
            int indicesArraySize = CalcIndicesArraySize(verts.Length, primitiveType);

            this.material = material;
            this.texture = texture;
            Vector2[] texCoords = gxtGeometry.CalculateTextureCoordinates(verts, texture.Width, texture.Height, uvType);
            // set up vertices
            SetupVertices(verts, texCoords);
            SetupIndices(indicesArraySize, primitiveType);
            localAABB = gxtGeometry.ComputeAABB(verts);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="verts"></param>
        /// <param name="textureWidth"></param>
        /// <param name="textureHeight"></param>
        /// <param name="textureScale"></param>
        /// <param name="textureRotation"></param>
        /// <param name="uvType"></param>
        /// <param name="translateToOrigin"></param>
        /// <returns></returns>
        public static Vector2[] CalculateTextureCoordinates(Vector2[] verts, int textureWidth, int textureHeight, Vector2 textureScale, float textureRotation, gxtTextureCoordinateType uvType)
        {
            gxtDebug.Assert(verts != null && verts.Length >= 2);
            gxtDebug.Assert(textureWidth >= 0 && textureHeight >= 0);
            gxtDebug.Assert(!gxtMath.Equals(textureScale.X, 0.0f, float.Epsilon) && !gxtMath.Equals(textureScale.Y, 0.0f, float.Epsilon));

            gxtAABB vertsAABB = gxtGeometry.ComputeAABB(verts);
            Vector2 min = new Vector2(verts[0].X, verts[0].Y);
            for (int i = 1; i < verts.Length; ++i)
            {
                if (verts[i].X < min.X)
                    min.X = verts[i].X;
                if (verts[i].Y < min.Y)
                    min.Y = verts[i].Y;
            }

            float sw = textureWidth * textureScale.X;
            float sh = textureHeight * textureScale.Y;
            Vector2 oneOverSizeVector = new Vector2(1.0f / sw, 1.0f / sh);
            Vector2 xAxis, yAxis;
            gxtMath.GetAxesVectors(textureRotation, out xAxis, out yAxis);

            Vector2[] textureCoords = new Vector2[verts.Length];
            if (uvType == gxtTextureCoordinateType.CLAMP)
            {
                for (int i = 0; i < verts.Length; ++i)
                {
                    Vector2 pos = new Vector2(verts[i].X, verts[i].Y);
                    Vector2 projPos = new Vector2(Vector2.Dot(pos - min, xAxis), Vector2.Dot(pos - min, yAxis));
                    textureCoords[i] = new Vector2(gxtMath.Clamp(projPos.X * oneOverSizeVector.X, 0.0f, 1.0f), gxtMath.Clamp(projPos.Y * oneOverSizeVector.Y, 0.0f, 1.0f));
                }
            }
            else
            {
                for (int i = 0; i < verts.Length; ++i)
                {
                    Vector2 pos = new Vector2(verts[i].X, verts[i].Y);
                    Vector2 projPos = new Vector2(Vector2.Dot(pos - min, xAxis), Vector2.Dot(pos - min, yAxis));
                    textureCoords[i] = new Vector2((projPos.X * oneOverSizeVector.X), (projPos.Y * oneOverSizeVector.Y));
                }
            }
            return textureCoords;
        }
Exemplo n.º 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="verts"></param>
 /// <param name="textureWidth"></param>
 /// <param name="textureHeight"></param>
 /// <param name="uvType"></param>
 /// <param name="translateToOrigin"></param>
 /// <returns></returns>
 public static Vector2[] CalculateTextureCoordinates(Vector2[] verts, int textureWidth, int textureHeight, gxtTextureCoordinateType uvType)
 {
     return CalculateTextureCoordinates(verts, textureWidth, textureHeight, Vector2.One, 0.0f, uvType);
 }
Exemplo n.º 7
0
        public void ApplyTexture(Texture2D texture, Vector2 textureScale, float textureRotation, gxtTextureCoordinateType uvType)
        {
            gxtDebug.Assert(vertices != null, "Cannot apply a texture to a mesh with no vertices!");
            this.texture = texture;

            Vector2[] verts = new Vector2[vertices.Length];

            int i;
            for (i = 0; i < verts.Length; ++i)
            {
                verts[i] = new Vector2(vertices[i].Position.X, vertices[i].Position.Y);
            }
            Vector2[] uvCoords = gxtGeometry.CalculateTextureCoordinates(verts, texture.Width, texture.Height, textureScale, textureRotation, uvType);
            for (i = 0; i < verts.Length; ++i)
            {
                vertices[i].TextureCoordinate = uvCoords[i];
            }
            vertexBuffer.SetData<VertexPositionColorTexture>(vertices);
        }
Exemplo n.º 8
0
 // shallow copy with a different material
 public void ApplyTexture(Texture2D texture, gxtTextureCoordinateType uvType)
 {
     this.texture = texture;
     // this copy is expensive...
     Vector2[] verts = new Vector2[vertices.Length];
     int i;
     for (i = 0; i < verts.Length; ++i)
     {
         verts[i] = new Vector2(vertices[i].Position.X, vertices[i].Position.Y);
     }
     // uv coordinates
     Vector2[] uvCoords = gxtGeometry.CalculateTextureCoordinates(verts, texture.Width, texture.Height, uvType);
     for (i = 0; i < verts.Length; ++i)
     {
         vertices[i].TextureCoordinate = uvCoords[i];
     }
     vertexBuffer.SetData<VertexPositionColorTexture>(vertices);
 }
Exemplo n.º 9
0
        public void CalcUVCoords(Vector2 textureScale, float textureRotation, gxtTextureCoordinateType uvType)
        {
            gxtDebug.Assert(texture != null);
            gxtDebug.Assert(uvType == gxtTextureCoordinateType.CLAMP || uvType == gxtTextureCoordinateType.WRAP, "Texture Coordinate Type Not Yet Implemented");

            float sw = texture.Width * textureScale.X;
            float sh = texture.Height * textureScale.Y;
            Vector2 topLeft = new Vector2(-sw * 0.5f, -sh * 0.5f);  // may not be accurate when rotated, trying projection
            Vector2 oneOverSizeVector = new Vector2(1.0f / sw, 1.0f / sh);
            Vector2 xAxis, yAxis;
            gxtMath.GetAxesVectors(textureRotation, out xAxis, out yAxis);
            topLeft = new Vector2(Vector2.Dot(topLeft, xAxis), Vector2.Dot(topLeft, yAxis));

            if (uvType == gxtTextureCoordinateType.CLAMP)
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    Vector2 pos = new Vector2(verts[i].Position.X, verts[i].Position.Y);
                    Vector2 projPos = new Vector2(Vector2.Dot(pos - topLeft, xAxis), Vector2.Dot(pos - topLeft, yAxis));
                    verts[i].TextureCoordinate = new Vector2(gxtMath.Clamp(projPos.X * oneOverSizeVector.X, 0.0f, 1.0f), gxtMath.Clamp(projPos.Y * oneOverSizeVector.Y, 0.0f, 1.0f));
                }
            }
            else if (uvType == gxtTextureCoordinateType.WRAP)
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    Vector2 pos = new Vector2(verts[i].Position.X, verts[i].Position.Y);
                    Vector2 projPos = new Vector2(Vector2.Dot(pos - topLeft, xAxis), Vector2.Dot(pos - topLeft, yAxis));
                    verts[i].TextureCoordinate = new Vector2((projPos.X * oneOverSizeVector.X) % 1.0f, (projPos.Y * oneOverSizeVector.Y) % 1.0f);
                }
            }
        }
Exemplo n.º 10
0
 public void SetupTexture(Texture2D texture, gxtTextureCoordinateType uvType)
 {
     Texture = texture;
     CalcUVCoords(uvType);
 }
Exemplo n.º 11
0
        // shallow copy with a different material
        public void ApplyTexture(Texture2D texture, gxtTextureCoordinateType uvType)
        {
            this.texture = texture;
            Vector2[] verts = new Vector2[vertices.Length];

            int i;
            for (i = 0; i < verts.Length; ++i)
            {
                verts[i] = new Vector2(vertices[i].Position.X, vertices[i].Position.Y);
            }
            Vector2[] uvCoords = gxtGeometry.CalculateTextureCoordinates(verts, texture.Width, texture.Height, uvType);
            for (i = 0; i < verts.Length; ++i)
            {
                vertices[i].TextureCoordinate = uvCoords[i];
            }
        }