Ejemplo n.º 1
0
        public void TestReadjustSize()
        {
            Texture texture = new MockTexture(100, 50);
            Quad    quad    = new Quad(10, 20);

            quad.Texture = texture;

            AssertAreEqualWithSmallError(quad.Width, 10, "", E);
            AssertAreEqualWithSmallError(quad.Height, 20, "", E);
            Assert.AreEqual(texture, quad.Texture);

            quad.ReadjustSize();

            AssertAreEqualWithSmallError(quad.Width, texture.FrameWidth, "", E);
            AssertAreEqualWithSmallError(quad.Height, texture.FrameHeight, "", E);

            float newWidth  = 64;
            float newHeight = 32;

            quad.ReadjustSize(newWidth, newHeight);

            AssertAreEqualWithSmallError(quad.Width, newWidth, "", E);
            AssertAreEqualWithSmallError(quad.Height, newHeight, "", E);

            quad.Texture = null;
            quad.ReadjustSize(); // shouldn't change anything

            AssertAreEqualWithSmallError(quad.Width, newWidth, "", E);
            AssertAreEqualWithSmallError(quad.Height, newHeight, "", E);
        }
Ejemplo n.º 2
0
        public void TestTexCoords()
        {
            Texture rootTexture = new MockTexture(100, 100);
            Texture subTexture  = Texture.FromTexture(rootTexture, Rectangle.Create(50, 50, 50, 50));

            VertexData vertexData = new VertexData();

            vertexData.SetPoint(0, 0, 0);
            vertexData.SetPoint(1, 1, 0);
            vertexData.SetPoint(2, 0, 1);
            vertexData.SetPoint(3, 1, 1);
            vertexData.SetTexCoords(0, 0, 0);
            vertexData.SetTexCoords(1, 1, 0);
            vertexData.SetTexCoords(2, 0, 1);
            vertexData.SetTexCoords(3, 1, 1);

            IndexData indexData = new IndexData();

            indexData.AddQuad(0, 1, 2, 3);

            Mesh mesh = new Mesh(vertexData, indexData);

            ComparePoints(Point.Create(0, 0), mesh.GetTexCoords(0));
            ComparePoints(Point.Create(1, 1), mesh.GetTexCoords(3));

            mesh.Texture = subTexture; // should change internal texture coordinates

            ComparePoints(Point.Create(0, 0), mesh.GetTexCoords(0));
            ComparePoints(Point.Create(1, 1), mesh.GetTexCoords(3));

            ComparePoints(Point.Create(0.5f, 0.5f), vertexData.GetTexCoords(0));
            ComparePoints(Point.Create(1.0f, 1.0f), vertexData.GetTexCoords(3));

            mesh.SetTexCoords(2, 0.25f, 0.75f);

            ComparePoints(Point.Create(0.25f, 0.75f), mesh.GetTexCoords(2));
            ComparePoints(Point.Create(0.625f, 0.875f), vertexData.GetTexCoords(2));

            mesh.Texture = rootTexture;

            ComparePoints(Point.Create(0f, 0f), mesh.GetTexCoords(0));
            ComparePoints(Point.Create(1f, 1f), mesh.GetTexCoords(3));

            ComparePoints(Point.Create(0f, 0f), vertexData.GetTexCoords(0));
            ComparePoints(Point.Create(1f, 1f), vertexData.GetTexCoords(3));
            ComparePoints(Point.Create(0.25f, 0.75f), vertexData.GetTexCoords(2));
        }