Exemple #1
0
        public override void Update(float time)
        {
            int i, j;

            float sinz  = ((float)Math.Sin((float)Math.PI * time * NumberOfJumps * 2) * Amplitude * AmplitudeRate);
            float sinz2 = (float)(Math.Sin((float)Math.PI * (time * NumberOfJumps * 2 + 1)) * Amplitude * AmplitudeRate);

            for (i = 0; i < GridSize.X; i++)
            {
                for (j = 0; j < GridSize.Y; j++)
                {
                    CCQuad3 coords = OriginalTile(i, j);

                    if (((i + j) % 2) == 0)
                    {
                        coords.BottomLeft.Z  += sinz;
                        coords.BottomRight.Z += sinz;
                        coords.TopLeft.Z     += sinz;
                        coords.TopRight.Z    += sinz;
                    }
                    else
                    {
                        coords.BottomLeft.Z  += sinz2;
                        coords.BottomRight.Z += sinz2;
                        coords.TopLeft.Z     += sinz2;
                        coords.TopRight.Z    += sinz2;
                    }

                    SetTile(i, j, ref coords);
                }
            }
        }
        public override void TransformTile(CCGridSize pos, float distance)
        {
            CCQuad3 coords = OriginalTile(pos);
            CCPoint step   = Target.Grid.Step;

            float dy = (step.Y / 2) * (1.0f - distance);

            coords.BottomLeft.Y  += dy; // (step.Y / 2) * (1.0f - distance);
            coords.BottomRight.Y += dy; //  (step.Y / 2) * (1.0f - distance);
            coords.TopLeft.Y     -= dy; //  (step.Y / 2) * (1.0f - distance);
            coords.TopRight.Y    -= dy; // (step.Y / 2) * (1.0f - distance);

            SetTile(pos, ref coords);
        }
        public virtual void TransformTile(CCGridSize pos, float distance)
        {
            CCQuad3 coords = OriginalTile(pos);

            var step = (Target is CCNodeGrid) ?  ((CCNodeGrid)Target).Grid.Step : Target.Grid.Step;

            float dx = (step.X / 2) * (1.0f - distance);
            float dy = (step.Y / 2) * (1.0f - distance);

            coords.BottomLeft.X += dx;
            coords.BottomLeft.Y += dy;

            coords.BottomRight.X -= dx;
            coords.BottomRight.Y += dy;

            coords.TopLeft.X += dx;
            coords.TopLeft.Y -= dy;

            coords.TopRight.X -= dx;
            coords.TopRight.Y -= dy;

            SetTile(pos, ref coords);
        }
 /// <summary>
 /// sets a new tile quad at a given position
 /// </summary>
 public void SetTile(CCGridSize pos, ref CCQuad3 coords)
 {
     tiledGrid3D [pos] = coords;
 }
 /// <summary>
 /// sets a new tile quad at a given position
 /// </summary>
 public void SetTile(int x, int y, ref CCQuad3 coords)
 {
     tiledGrid3D [x, y] = coords;
 }
        public void TurnOnTile(CCGridSize pos)
        {
            CCQuad3 orig = OriginalTile(pos);

            SetTile(pos, ref orig);
        }
Exemple #7
0
        public override void CalculateVertexPoints()
        {
            float width = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numQuads = GridSize.X * GridSize.Y;

            vertexBuffer = new CCVertexBuffer<CCV3F_T2F>(numQuads * 4, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numQuads * 4;
            indexBuffer = new CCIndexBuffer<short>(numQuads * 6, BufferUsage.WriteOnly);
            indexBuffer.Count = numQuads * 6;

            Vertices = vertexBuffer.Data.Elements;
            Indices = indexBuffer.Data.Elements;

            OriginalVertices = new CCQuad3[numQuads];

            CCV3F_T2F[] vertArray = Vertices;
            short[] idxArray = Indices;


            int index = 0;

            for (int x = 0; x < GridSize.X; x++)
            {
                for (int y = 0; y < GridSize.Y; y++)
                {
                    float x1 = x * Step.X;
                    float x2 = x1 + Step.X;
                    float y1 = y * Step.Y;
                    float y2 = y1 + Step.Y;

                    vertArray[index + 0].Vertices = new CCVertex3F(x1, y1, 0);
                    vertArray[index + 1].Vertices = new CCVertex3F(x2, y1, 0);
                    vertArray[index + 2].Vertices = new CCVertex3F(x1, y2, 0);
                    vertArray[index + 3].Vertices = new CCVertex3F(x2, y2, 0);

                    float newY1 = y1;
                    float newY2 = y2;

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

                    vertArray[index + 0].TexCoords = new CCTex2F(x1 / width, newY1 / height);
                    vertArray[index + 1].TexCoords = new CCTex2F(x2 / width, newY1 / height);
                    vertArray[index + 2].TexCoords = new CCTex2F(x1 / width, newY2 / height);
                    vertArray[index + 3].TexCoords = new CCTex2F(x2 / width, newY2 / height);

                    index += 4;
                }
            }

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

                idxArray[i6 + 3] = (short) (i4 + 1);
                idxArray[i6 + 4] = (short) (i4 + 2);
                idxArray[i6 + 5] = (short) (i4 + 3);
            }

            indexBuffer.UpdateBuffer();

            for (int i = 0; i < numQuads; i++)
            {
                int i4 = i * 4;
                OriginalVertices[i].BottomLeft = vertArray[i4 + 0].Vertices;
                OriginalVertices[i].BottomRight = vertArray[i4 + 1].Vertices;
                OriginalVertices[i].TopLeft = vertArray[i4 + 2].Vertices;
                OriginalVertices[i].TopRight = vertArray[i4 + 3].Vertices;
            }
        }
Exemple #8
0
 public void TurnOffTile (CCGridSize pos)
 {
     var coords = new CCQuad3 ();
     //memset(&coords, 0, sizeof(ccQuad3));
     SetTile (pos, ref coords);
 }
 /// <summary>
 /// sets a new tile quad at a given position
 /// </summary>
 public void SetTile (CCGridSize pos, ref CCQuad3 coords)
 {
     tiledGrid3D [pos] = coords;
 }
 /// <summary>
 /// sets a new tile quad at a given position
 /// </summary>
 public void SetTile (int x, int y, ref CCQuad3 coords)
 {
     tiledGrid3D [x, y] = coords;
 }
Exemple #11
0
        public override void CalculateVertexPoints()
        {
            float width  = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numQuads = GridSize.X * GridSize.Y;

            vertexBuffer       = new CCVertexBuffer <CCV3F_T2F>(numQuads * 4, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numQuads * 4;
            indexBuffer        = new CCIndexBuffer <short>(numQuads * 6, BufferUsage.WriteOnly);
            indexBuffer.Count  = numQuads * 6;

            Vertices = vertexBuffer.Data.Elements;
            Indices  = indexBuffer.Data.Elements;

            OriginalVertices = new CCQuad3[numQuads];

            CCV3F_T2F[] vertArray = Vertices;
            short[]     idxArray  = Indices;


            int index = 0;

            for (int x = 0; x < GridSize.X; x++)
            {
                for (int y = 0; y < GridSize.Y; y++)
                {
                    float x1 = x * Step.X;
                    float x2 = x1 + Step.X;
                    float y1 = y * Step.Y;
                    float y2 = y1 + Step.Y;

                    vertArray[index + 0].Vertices = new CCVertex3F(x1, y1, 0);
                    vertArray[index + 1].Vertices = new CCVertex3F(x2, y1, 0);
                    vertArray[index + 2].Vertices = new CCVertex3F(x1, y2, 0);
                    vertArray[index + 3].Vertices = new CCVertex3F(x2, y2, 0);

                    float newY1 = y1;
                    float newY2 = y2;

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

                    vertArray[index + 0].TexCoords = new CCTex2F(x1 / width, newY1 / height);
                    vertArray[index + 1].TexCoords = new CCTex2F(x2 / width, newY1 / height);
                    vertArray[index + 2].TexCoords = new CCTex2F(x1 / width, newY2 / height);
                    vertArray[index + 3].TexCoords = new CCTex2F(x2 / width, newY2 / height);

                    index += 4;
                }
            }

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

                idxArray[i6 + 3] = (short)(i4 + 1);
                idxArray[i6 + 4] = (short)(i4 + 2);
                idxArray[i6 + 5] = (short)(i4 + 3);
            }

            indexBuffer.UpdateBuffer();

            for (int i = 0; i < numQuads; i++)
            {
                int i4 = i * 4;
                OriginalVertices[i].BottomLeft  = vertArray[i4 + 0].Vertices;
                OriginalVertices[i].BottomRight = vertArray[i4 + 1].Vertices;
                OriginalVertices[i].TopLeft     = vertArray[i4 + 2].Vertices;
                OriginalVertices[i].TopRight    = vertArray[i4 + 3].Vertices;
            }
        }