Esempio n. 1
0
        public override void calculateVertexPoints()
        {
            int   i;
            float contentSizeInPixels = this.m_pTexture.ContentSizeInPixels.width;
            float single = this.m_pTexture.ContentSizeInPixels.height;
            float contentSizeInPixels1 = this.m_pTexture.ContentSizeInPixels.height;
            int   mSGridSize           = this.m_sGridSize.x * this.m_sGridSize.y;

            this.m_pVertices         = new ccQuad3[mSGridSize];
            this.m_pOriginalVertices = new ccQuad3[mSGridSize];
            this.m_pTexCoordinates   = new ccQuad2[mSGridSize];
            this.m_pIndices          = new short[mSGridSize * 6];
            ccQuad3[] mPVertices       = this.m_pVertices;
            ccQuad2[] mPTexCoordinates = this.m_pTexCoordinates;
            short[]   mPIndices        = this.m_pIndices;
            int       num = 0;

            for (i = 0; i < this.m_sGridSize.x; i++)
            {
                for (int j = 0; j < this.m_sGridSize.y; j++)
                {
                    float mObStep  = (float)i * this.m_obStep.x;
                    float mObStep1 = mObStep + this.m_obStep.x;
                    float single1  = (float)j * this.m_obStep.y;
                    float mObStep2 = single1 + this.m_obStep.y;
                    mPVertices[num]    = new ccQuad3();
                    mPVertices[num].bl = new ccVertex3F(mObStep, single1, 0f);
                    mPVertices[num].br = new ccVertex3F(mObStep1, single1, 0f);
                    mPVertices[num].tl = new ccVertex3F(mObStep, mObStep2, 0f);
                    mPVertices[num].tr = new ccVertex3F(mObStep1, mObStep2, 0f);
                    float single2 = single1;
                    float single3 = mObStep2;
                    if (!this.m_bIsTextureFlipped)
                    {
                        single2 = contentSizeInPixels1 - single1;
                        single3 = contentSizeInPixels1 - mObStep2;
                    }
                    mPTexCoordinates[num]    = new ccQuad2();
                    mPTexCoordinates[num].bl = new ccVertex2F(mObStep / contentSizeInPixels, single2 / single);
                    mPTexCoordinates[num].br = new ccVertex2F(mObStep1 / contentSizeInPixels, single2 / single);
                    mPTexCoordinates[num].tl = new ccVertex2F(mObStep / contentSizeInPixels, single3 / single);
                    mPTexCoordinates[num].tr = new ccVertex2F(mObStep1 / contentSizeInPixels, single3 / single);
                    num++;
                }
            }
            for (i = 0; i < mSGridSize; i++)
            {
                mPIndices[i * 6]     = (short)(i * 4);
                mPIndices[i * 6 + 1] = (short)(i * 4 + 2);
                mPIndices[i * 6 + 2] = (short)(i * 4 + 1);
                mPIndices[i * 6 + 3] = (short)(i * 4 + 1);
                mPIndices[i * 6 + 4] = (short)(i * 4 + 2);
                mPIndices[i * 6 + 5] = (short)(i * 4 + 3);
            }
            Array.Copy(this.m_pVertices, this.m_pOriginalVertices, mSGridSize);
        }
Esempio n. 2
0
        public override void blit()
        {
            int           mSGridSize = this.m_sGridSize.x * this.m_sGridSize.y;
            CCApplication texture2D  = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            texture2D.basicEffect.Texture            = this.m_pTexture.getTexture2D();
            texture2D.basicEffect.TextureEnabled     = true;
            texture2D.GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            texture2D.basicEffect.VertexColorEnabled = true;
            List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>();

            for (int i = 0; i < mSGridSize; i++)
            {
                ccQuad3 mPVertices       = this.m_pVertices[i];
                ccQuad2 mPTexCoordinates = this.m_pTexCoordinates[i];
                if (mPVertices != null)
                {
                    VertexPositionColorTexture vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.bl.x, mPVertices.bl.y, mPVertices.bl.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.bl.x, mPTexCoordinates.bl.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.br.x, mPVertices.br.y, mPVertices.br.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.br.x, mPTexCoordinates.br.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.tl.x, mPVertices.tl.y, mPVertices.tl.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.tl.x, mPTexCoordinates.tl.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.tr.x, mPVertices.tr.y, mPVertices.tr.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.tr.x, mPTexCoordinates.tr.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                }
            }
            foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, this.m_pIndices, 0, (int)this.m_pIndices.Length / 3);
            }
        }
Esempio n. 3
0
        public override void calculateVertexPoints()
        {
            float width = m_pTexture.ContentSizeInPixels.width;// (float)m_pTexture.PixelsWide;
            float height = m_pTexture.ContentSizeInPixels.height;// (float)m_pTexture.PixelsHigh;
            float imageH = m_pTexture.ContentSizeInPixels.height;

            int numQuads = m_sGridSize.x * m_sGridSize.y;

            m_pVertices = new ccQuad3[numQuads];
            m_pOriginalVertices = new ccQuad3[numQuads];
            m_pTexCoordinates = new ccQuad2[numQuads];
            m_pIndices = new short[numQuads * 6];

            ccQuad3[] vertArray = m_pVertices;
            ccQuad2[] texArray = m_pTexCoordinates;
            short[] idxArray = m_pIndices;

            int x, y;
            int index = 0;

            for (x = 0; x < m_sGridSize.x; x++)
            {
                for (y = 0; y < m_sGridSize.y; y++)
                {
                    float x1 = x * m_obStep.x;
                    float x2 = x1 + m_obStep.x;
                    float y1 = y * m_obStep.y;
                    float y2 = y1 + m_obStep.y;

                    vertArray[index] = new ccQuad3();
                    vertArray[index].bl = new ccVertex3F(x1, y1, 0);
                    vertArray[index].br = new ccVertex3F(x2, y1, 0);
                    vertArray[index].tl = new ccVertex3F(x1, y2, 0);
                    vertArray[index].tr = new ccVertex3F(x2, y2, 0);

                    float newY1 = y1;
                    float newY2 = y2;

                    if (!m_bIsTextureFlipped)
                    {
                        newY1 = imageH - y1;
                        newY2 = imageH - y2;
                    }

                    texArray[index] = new ccQuad2();
                    texArray[index].bl = new ccVertex2F(x1 / width, newY1 / height);
                    texArray[index].br = new ccVertex2F(x2 / width, newY1 / height);
                    texArray[index].tl = new ccVertex2F(x1 / width, newY2 / height);
                    texArray[index].tr = new ccVertex2F(x2 / width, newY2 / height);

                    index++;
                }
            }

            for (x = 0; x < numQuads; x++)
            {
                idxArray[x * 6 + 0] = (short)(x * 4 + 0);
                idxArray[x * 6 + 1] = (short)(x * 4 + 2);
                idxArray[x * 6 + 2] = (short)(x * 4 + 1);

                idxArray[x * 6 + 3] = (short)(x * 4 + 1);
                idxArray[x * 6 + 4] = (short)(x * 4 + 2);
                idxArray[x * 6 + 5] = (short)(x * 4 + 3);
            }

            Array.Copy(m_pVertices, m_pOriginalVertices, numQuads);
        }
Esempio n. 4
0
        public override void calculateVertexPoints()
        {
            float width  = m_pTexture.ContentSizeInPixels.width;  // (float)m_pTexture.PixelsWide;
            float height = m_pTexture.ContentSizeInPixels.height; // (float)m_pTexture.PixelsHigh;
            float imageH = m_pTexture.ContentSizeInPixels.height;

            int numQuads = m_sGridSize.x * m_sGridSize.y;

            m_pVertices         = new ccQuad3[numQuads];
            m_pOriginalVertices = new ccQuad3[numQuads];
            m_pTexCoordinates   = new ccQuad2[numQuads];
            m_pIndices          = new short[numQuads * 6];

            ccQuad3[] vertArray = m_pVertices;
            ccQuad2[] texArray  = m_pTexCoordinates;
            short[]   idxArray  = m_pIndices;

            int x, y;
            int index = 0;

            for (x = 0; x < m_sGridSize.x; x++)
            {
                for (y = 0; y < m_sGridSize.y; y++)
                {
                    float x1 = x * m_obStep.x;
                    float x2 = x1 + m_obStep.x;
                    float y1 = y * m_obStep.y;
                    float y2 = y1 + m_obStep.y;

                    vertArray[index]    = new ccQuad3();
                    vertArray[index].bl = new ccVertex3F(x1, y1, 0);
                    vertArray[index].br = new ccVertex3F(x2, y1, 0);
                    vertArray[index].tl = new ccVertex3F(x1, y2, 0);
                    vertArray[index].tr = new ccVertex3F(x2, y2, 0);

                    float newY1 = y1;
                    float newY2 = y2;

                    if (!m_bIsTextureFlipped)
                    {
                        newY1 = imageH - y1;
                        newY2 = imageH - y2;
                    }

                    texArray[index]    = new ccQuad2();
                    texArray[index].bl = new ccVertex2F(x1 / width, newY1 / height);
                    texArray[index].br = new ccVertex2F(x2 / width, newY1 / height);
                    texArray[index].tl = new ccVertex2F(x1 / width, newY2 / height);
                    texArray[index].tr = new ccVertex2F(x2 / width, newY2 / height);

                    index++;
                }
            }

            for (x = 0; x < numQuads; x++)
            {
                idxArray[x * 6 + 0] = (short)(x * 4 + 0);
                idxArray[x * 6 + 1] = (short)(x * 4 + 2);
                idxArray[x * 6 + 2] = (short)(x * 4 + 1);

                idxArray[x * 6 + 3] = (short)(x * 4 + 1);
                idxArray[x * 6 + 4] = (short)(x * 4 + 2);
                idxArray[x * 6 + 5] = (short)(x * 4 + 3);
            }

            Array.Copy(m_pVertices, m_pOriginalVertices, numQuads);
        }
Esempio n. 5
0
        public override void blit()
        {
            int n = m_sGridSize.x * m_sGridSize.y;

            // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
            // Unneeded states: GL_COLOR_ARRAY
            //glDisableClientState(GL_COLOR_ARRAY);

            //glVertexPointer(3, GL_FLOAT, 0, m_pVertices);
            //glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates);
            //glDrawElements(GL_TRIANGLES, (GLsizei)n * 6, GL_UNSIGNED_SHORT, m_pIndices);

            //// restore default GL state
            //glEnableClientState(GL_COLOR_ARRAY);


            CCApplication app  = CCApplication.sharedApplication();
            CCSize        size = CCDirector.sharedDirector().getWinSize();

            //app.basicEffect.World = app.worldMatrix *TransformUtils.CGAffineToMatrix( this.nodeToWorldTransform());
            app.basicEffect.Texture            = this.m_pTexture.getTexture2D();
            app.basicEffect.TextureEnabled     = true;
            app.GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            app.basicEffect.VertexColorEnabled = true;

            List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>();

            for (int i = 0; i < n; i++)
            {
                ccQuad3 quad    = this.m_pVertices[i];
                ccQuad2 texQuad = this.m_pTexCoordinates[i];
                if (quad != null)
                {
                    VertexPositionColorTexture vt = new VertexPositionColorTexture();
                    vt.Position          = new Vector3(quad.bl.x, quad.bl.y, quad.bl.z);
                    vt.Color             = Color.White;
                    vt.TextureCoordinate = new Vector2(texQuad.bl.x, texQuad.bl.y);
                    vertices.Add(vt);

                    vt                   = new VertexPositionColorTexture();
                    vt.Position          = new Vector3(quad.br.x, quad.br.y, quad.br.z);
                    vt.Color             = Color.White;
                    vt.TextureCoordinate = new Vector2(texQuad.br.x, texQuad.br.y);
                    vertices.Add(vt);

                    vt                   = new VertexPositionColorTexture();
                    vt.Position          = new Vector3(quad.tl.x, quad.tl.y, quad.tl.z);
                    vt.Color             = Color.White;
                    vt.TextureCoordinate = new Vector2(texQuad.tl.x, texQuad.tl.y);
                    vertices.Add(vt);

                    vt                   = new VertexPositionColorTexture();
                    vt.Position          = new Vector3(quad.tr.x, quad.tr.y, quad.tr.z);
                    vt.Color             = Color.White;
                    vt.TextureCoordinate = new Vector2(texQuad.tr.x, texQuad.tr.y);
                    vertices.Add(vt);
                }
            }

            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertices.ToArray(), 0, vertices.Count,
                    this.m_pIndices, 0, this.m_pIndices.Length / 3);
            }
        }