Example #1
0
        public override void Update(float time)
        {
            if (Target == null)
            {
                return;
            }

            int i, j;

            for (i = 0; i < (GridSize.X + 1); ++i)
            {
                for (j = 0; j < (GridSize.Y + 1); ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);

                    CCPoint diff = Position - new CCPoint(v.X, v.Y);
                    float   r    = diff.Length;

                    if (r < Radius)
                    {
                        r = Radius - r;
                        float r1   = r / Radius;
                        float rate = r1 * r1;
                        v.Z += ((float)Math.Sin(time * MathHelper.Pi * Waves * 2 + r * 0.1f) * Amplitude *
                                AmplitudeRate * rate);
                    }

                    SetVertex(i, j, ref v);
                }
            }
        }
Example #2
0
        public override void Update(float time)
        {
            int     i, j;
            CCPoint avg    = CCPoint.Zero;
            CCPoint c      = PositionInPixels;
            int     twirls = Twirls;

            for (i = 0; i < (GridSize.X + 1); ++i)
            {
                for (j = 0; j < (GridSize.Y + 1); ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);

                    avg.X = i - (GridSize.X / 2.0f);
                    avg.Y = j - (GridSize.Y / 2.0f);

                    var r = (float)Math.Sqrt((avg.X * avg.X + avg.Y * avg.Y));

                    float amp = 0.1f * Amplitude * AmplitudeRate;
                    float a   = r * (float)Math.Cos((float)Math.PI / 2.0f + time * (float)Math.PI * twirls * 2) * amp;

                    float dx = (float)Math.Sin(a) * (v.Y - c.Y) + (float)Math.Cos(a) * (v.X - c.X);
                    float dy = (float)Math.Cos(a) * (v.Y - c.Y) - (float)Math.Sin(a) * (v.X - c.X);

                    v.X = c.X + dx;
                    v.Y = c.Y + dy;

                    SetVertex(i, j, ref v);
                }
            }
        }
Example #3
0
 public CCV3F_C4B(CCPoint position, CCColor4B color)
 {
     this.Vertices   = CCVertex3F.Zero;
     this.Vertices.X = position.X;
     this.Vertices.Y = position.Y;
     Colors          = color;
 }
        public override void Update(float time)
        {
            int i, j;

            for (i = 0; i < GridSize.X; i++)
            {
                for (j = 0; j < GridSize.Y; j++)
                {
                    CCQuad3    coords = OriginalTile(i, j);
                    CCVertex3F bl     = coords.BottomLeft;
                    CCVertex3F br     = coords.BottomRight;
                    CCVertex3F tl     = coords.TopLeft;
                    CCVertex3F tr     = coords.TopRight;

                    bl.Z = ((float)Math.Sin(time * (float)Math.PI * Waves * 2 + (bl.Y + bl.X) * .01f) * Amplitude * AmplitudeRate);
                    br.Z = bl.Z;
                    tl.Z = bl.Z;
                    tr.Z = bl.Z;

                    coords.BottomLeft  = bl;
                    coords.BottomRight = br;
                    coords.TopLeft     = tl;
                    coords.TopRight    = tr;

                    SetTile(i, j, ref coords);
                }
            }
        }
Example #5
0
        public override void Update(float time)
        {
            int   i, j;
            float ampRate = AmplitudeRate;

            for (i = 0; i < GridSize.X + 1; ++i)
            {
                for (j = 0; j < GridSize.Y + 1; ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);

                    if (Vertical)
                    {
                        v.X = (v.X +
                               ((float)Math.Sin(time * (float)Math.PI * Waves * 2 + v.Y * .01f) * Amplitude * ampRate));
                    }

                    if (Horizontal)
                    {
                        v.Y = (v.Y +
                               ((float)Math.Sin(time * (float)Math.PI * Waves * 2 + v.X * .01f) * Amplitude * ampRate));
                    }

                    SetVertex(i, j, ref v);
                }
            }
        }
Example #6
0
 public CCQuad3(CCVertex3F?tL = null, CCVertex3F?tR = null,
                CCVertex3F?bL = null, CCVertex3F?bR = null) : this()
 {
     TopLeft     = tL ?? new CCVertex3F();
     TopRight    = tR ?? new CCVertex3F();
     BottomLeft  = bL ?? new CCVertex3F();
     BottomRight = bR ?? new CCVertex3F();
 }
Example #7
0
        public override void Update(float time)
        {
            float tt      = Math.Max(0, time - 0.25f);
            float deltaAy = (tt * tt * 500);
            float ay      = -100 - deltaAy;

            float deltaTheta = -MathHelper.PiOver2 * (float)Math.Sqrt(time);
            float theta      = MathHelper.PiOver2 + deltaTheta;

            var sinTheta = (float)Math.Sin(theta);
            var cosTheta = (float)Math.Cos(theta);

            for (int i = 0; i <= GridSize.X; ++i)
            {
                for (int j = 0; j <= GridSize.Y; ++j)
                {
                    // Get original vertex
                    CCVertex3F p = OriginalVertex(i, j);

                    var   R       = (float)Math.Sqrt((p.X * p.X) + ((p.Y - ay) * (p.Y - ay)));
                    float r       = R * sinTheta;
                    var   alpha   = (float)Math.Asin(p.X / R);
                    float beta    = alpha / sinTheta;
                    var   cosBeta = (float)Math.Cos(beta);

                    // If beta > PI then we've wrapped around the cone
                    // Reduce the radius to stop these points interfering with others
                    if (beta <= MathHelper.Pi)
                    {
                        p.X = (r * (float)Math.Sin(beta));
                    }
                    else
                    {
                        // Force X = 0 to stop wrapped
                        // points
                        p.X = 0;
                    }

                    p.Y = (R + ay - (r * (1 - cosBeta) * sinTheta));

                    // We scale z here to avoid the animation being
                    // too much bigger than the screen due to perspective transform
                    p.Z = (r * (1 - cosBeta) * cosTheta) / 7; // "100" didn't work for

                    //    Stop z coord from dropping beneath underlying page in a transition
                    // issue #751
                    if (p.Z < 0.5f)
                    {
                        p.Z = 0.5f;
                    }

                    // Set new coords
                    SetVertex(i, j, ref p);
                }
            }
        }
Example #8
0
        public override void Update(float time)
        {
            int i, j;

            for (i = 0; i < GridSize.X + 1; ++i)
            {
                for (j = 0; j < GridSize.Y + 1; ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);
                    v.Z += ((float)Math.Sin((float)Math.PI * time * Waves * 2 + (v.Y + v.X) * .01f) * Amplitude *
                            AmplitudeRate);
                    SetVertex(i, j, ref v);
                }
            }
        }
Example #9
0
        public override void Update(float time)
        {
            if (Target == null)
            {
                return;
            }

            int i, j;

            CCPoint vect = CCPoint.Zero;

            for (i = 0; i < GridSize.X + 1; ++i)
            {
                for (j = 0; j < GridSize.Y + 1; ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);
                    vect = Position - new CCPoint(v.X, v.Y);

                    float r      = vect.Length;
                    float radius = Radius;

                    if (r < radius)
                    {
                        r = radius - r;
                        float pre_log = r / radius;
                        if (pre_log == 0)
                        {
                            pre_log = 0.001f;
                        }

                        float lensEffect = LensScale;
                        float l          = (float)Math.Log(pre_log) * lensEffect;
                        float new_r      = (float)Math.Exp(l) * radius;

                        if (Math.Sqrt((vect.X * vect.X + vect.Y * vect.Y)) > 0)
                        {
                            vect = CCPoint.Normalize(vect);

                            CCPoint new_vect = vect * new_r;
                            v.Z += (Concave ? -1.0f : 1.0f) * new_vect.Length * lensEffect;
                        }
                    }

                    SetVertex(i, j, ref v);
                }
            }
        }
Example #10
0
        CCVertex3F VertexFromAlphaPoint(CCPoint alpha)
        {
            CCVertex3F ret = new CCVertex3F(0.0f, 0.0f, 0.0f);

            if (Sprite != null)
            {
                CCV3F_C4B_T2F_Quad quad = Sprite.Quad;

                CCPoint min = new CCPoint(quad.BottomLeft.Vertices.X, quad.BottomLeft.Vertices.Y);
                CCPoint max = new CCPoint(quad.TopRight.Vertices.X, quad.TopRight.Vertices.Y);

                ret.X = min.X * (1f - alpha.X) + max.X * alpha.X;
                ret.Y = min.Y * (1f - alpha.Y) + max.Y * alpha.Y;
            }

            return(ret);
        }
Example #11
0
        public override void Update(float time)
        {
            int i, j;

            for (i = 1; i < GridSize.X; ++i)
            {
                for (j = 1; j < GridSize.Y; ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);
                    v.X = (v.X +
                           ((float)Math.Sin(time * (float)Math.PI * Waves * 2 + v.X * .01f) * Amplitude *
                            AmplitudeRate));
                    v.Y = (v.Y +
                           ((float)Math.Sin(time * (float)Math.PI * Waves * 2 + v.Y * .01f) * Amplitude *
                            AmplitudeRate));
                    SetVertex(i, j, ref v);
                }
            }
        }
Example #12
0
 /// <summary>
 /// sets a new vertex at a given position
 /// </summary>
 public void SetVertex(CCGridSize pos, ref CCVertex3F vertex)
 {
     grid3D [pos] = vertex;
 }
Example #13
0
 /// <summary>
 /// sets a new vertex at a given position
 /// </summary>
 public void SetVertex (int x, int y, ref CCVertex3F vertex)
 {
     grid3D [x, y] = vertex;
 }
Example #14
0
 /// <summary>
 /// sets a new vertex at a given position
 /// </summary>
 public void SetVertex (CCGridSize pos, ref CCVertex3F vertex)
 {
     grid3D [pos] = vertex;
 }
 public void AddVertex(CCVertex3F vertex, CCColor4B color, PrimitiveType primitiveType)
 {
     AddVertex(new CCVector2(vertex.X, vertex.Y), color, primitiveType);
 }
Example #16
0
 public CCV3F_C4B(CCVertex3F position, CCColor4B color)
 {
     this.Vertices = position;
     Colors        = color;
 }
Example #17
0
        public override void CalculateVertexPoints()
        {
            float width  = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numOfPoints = (GridSize.X + 1) * (GridSize.Y + 1);

            vertexBuffer       = new CCVertexBuffer <CCV3F_T2F>(numOfPoints, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numOfPoints;
            indexBuffer        = new CCIndexBuffer <ushort>(GridSize.X * GridSize.Y * 6, BufferUsage.WriteOnly);
            indexBuffer.Count  = GridSize.X * GridSize.Y * 6;

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

            OriginalVertices = new CCVertex3F[numOfPoints];

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

            var l1   = new int[4];
            var l2   = new CCVertex3F[4];
            var tex1 = new int[4];
            var tex2 = new CCPoint[4];

            //int idx = -1;
            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;

                    var a = (short)(x * (GridSize.Y + 1) + y);
                    var b = (short)((x + 1) * (GridSize.Y + 1) + y);
                    var c = (short)((x + 1) * (GridSize.Y + 1) + (y + 1));
                    var d = (short)(x * (GridSize.Y + 1) + (y + 1));

                    int idx = ((y * GridSize.X) + x) * 6;

                    idxArray[idx + 0] = (ushort)a;
                    idxArray[idx + 1] = (ushort)b;
                    idxArray[idx + 2] = (ushort)d;
                    idxArray[idx + 3] = (ushort)b;
                    idxArray[idx + 4] = (ushort)c;
                    idxArray[idx + 5] = (ushort)d;

                    //var tempidx = new short[6] {a, d, b, b, d, c};
                    //Array.Copy(tempidx, 0, idxArray, 6 * idx, tempidx.Length);

                    l1[0] = a;
                    l1[1] = b;
                    l1[2] = c;
                    l1[3] = d;

                    //var e = new Vector3(x1, y1, 0);
                    //var f = new Vector3(x2, y1, 0);
                    //var g = new Vector3(x2, y2, 0);
                    //var h = new Vector3(x1, y2, 0);

                    l2[0] = new CCVertex3F(x1, y1, 0);
                    l2[1] = new CCVertex3F(x2, y1, 0);
                    l2[2] = new CCVertex3F(x2, y2, 0);
                    l2[3] = new CCVertex3F(x1, y2, 0);

                    tex1[0] = a;
                    tex1[1] = b;
                    tex1[2] = c;
                    tex1[3] = d;

                    tex2[0] = new CCPoint(x1, y1);
                    tex2[1] = new CCPoint(x2, y1);
                    tex2[2] = new CCPoint(x2, y2);
                    tex2[3] = new CCPoint(x1, y2);

                    for (int i = 0; i < 4; ++i)
                    {
                        vertArray[l1[i]].Vertices = l2[i];

                        vertArray[tex1[i]].TexCoords.U = tex2[i].X / width;

                        if (TextureFlipped)
                        {
                            vertArray[tex1[i]].TexCoords.V = tex2[i].Y / height;
                        }
                        else
                        {
                            vertArray[tex1[i]].TexCoords.V = (imageH - tex2[i].Y) / height;
                        }
                    }
                }
            }

            int n = (GridSize.X + 1) * (GridSize.Y + 1);

            for (int i = 0; i < n; i++)
            {
                OriginalVertices[i] = Vertices[i].Vertices;
            }

            indexBuffer.UpdateBuffer();

            dirty = true;
        }
Example #18
0
		public CCQuad3(CCVertex3F? tL = null, CCVertex3F? tR = null, 
			CCVertex3F? bL = null, CCVertex3F? bR = null) : this()
        {
			TopLeft = tL ?? new CCVertex3F();
			TopRight = tR ?? new CCVertex3F();
			BottomLeft = bL ?? new CCVertex3F();
			BottomRight = bR ?? new CCVertex3F();
        }
Example #19
0
        public override void Update (float time)
        {

            if (Target == null)
                return; 
            
            float angle = (float)Math.PI * time; // 180 degrees
            var mz = (float)Math.Sin (angle);
            angle = angle / 2.0f; // x calculates degrees from 0 to 90
            var my = (float)Math.Cos (angle);

            CCVertex3F v0, v1, v;
            var diff = new CCVertex3F ();

            v0 = OriginalVertex (1, 1);
            v1 = OriginalVertex (0, 0);

            float y0 = v0.Y;
            float y1 = v1.Y;
            float y;
            CCGridSize a, b, c, d;

            if (y0 > y1)
            {
                // Normal Grid
                a = new CCGridSize (0, 0);
                b = new CCGridSize (0, 1);
                c = new CCGridSize (1, 0);
                d = new CCGridSize (1, 1);
                y = y0;
            }
            else
            {
                // Reversed Grid
                b = new CCGridSize (0, 0);
                a = new CCGridSize (0, 1);
                d = new CCGridSize (1, 0);
                c = new CCGridSize (1, 1);
                y = y1;
            }

            diff.Y = y - y * my;
            diff.Z = Math.Abs ((float)Math.Floor ((y * mz) / 4.0f));

            // bottom-left
            v = OriginalVertex (a);
            v.Y = diff.Y;
            v.Z += diff.Z;
            SetVertex (a, ref v);

            // upper-left
            v = OriginalVertex (b);
            v.Y -= diff.Y;
            v.Z -= diff.Z;
            SetVertex (b, ref v);

            // bottom-right
            v = OriginalVertex (c);
            v.Y = diff.Y;
            v.Z += diff.Z;
            SetVertex (c, ref v);

            // upper-right
            v = OriginalVertex (d);
            v.Y -= diff.Y;
            v.Z -= diff.Z;
            SetVertex (d, ref v);
        }
Example #20
0
        public override void Update (float time)
        {
            float angle = (float)Math.PI * time; // 180 degrees
            var mz = (float)Math.Sin (angle);
            angle = angle / 2.0f; // x calculates degrees from 0 to 90
            var mx = (float)Math.Cos (angle);

            CCVertex3F v0, v1, v;
            var diff = new CCVertex3F ();

            v0 = OriginalVertex (1, 1);
            v1 = OriginalVertex (0, 0);

            float x0 = v0.X;
            float x1 = v1.X;
            float x;
            CCGridSize a, b, c, d;

            if (x0 > x1)
            {
                // Normal Grid
                a = new CCGridSize (0, 0);
                b = new CCGridSize (0, 1);
                c = new CCGridSize (1, 0);
                d = new CCGridSize (1, 1);
                x = x0;
            }
            else
            {
                // Reversed Grid
                c = new CCGridSize (0, 0);
                d = new CCGridSize (0, 1);
                a = new CCGridSize (1, 0);
                b = new CCGridSize (1, 1);
                x = x1;
            }

            diff.X = (x - x * mx);
            diff.Z = Math.Abs ((float)Math.Floor ((x * mz) / 4.0f));

            // bottom-left
            v = OriginalVertex (a);
            v.X = diff.X;
            v.Z += diff.Z;
            SetVertex (a, ref v);

            // upper-left
            v = OriginalVertex (b);
            v.X = diff.X;
            v.Z += diff.Z;
            SetVertex (b, ref v);

            // bottom-right
            v = OriginalVertex (c);
            v.X -= diff.X;
            v.Z -= diff.Z;
            SetVertex (c, ref v);

            // upper-right
            v = OriginalVertex (d);
            v.X -= diff.X;
            v.Z -= diff.Z;
            SetVertex (d, ref v);
        }
Example #21
0
        static void VertexLineToPolygon(CCPoint[] points, float stroke, CCV3F_C4B_T2F[] vertices, int offset, int nuPoints)
        {
            nuPoints += offset;
            if (nuPoints <= 1)
            {
                return;
            }

            stroke *= 0.5f;

            int idx;
            int nuPointsMinus = nuPoints - 1;

            float rad70  = MathHelper.ToRadians(70);
            float rad170 = MathHelper.ToRadians(170);

            for (int i = offset; i < nuPoints; i++)
            {
                idx = i * 2;
                CCPoint p1 = points[i];
                CCPoint perpVector;

                if (i == 0)
                {
                    perpVector = CCPoint.PerpendicularCCW(CCPoint.Normalize(p1 - points[i + 1]));
                }
                else if (i == nuPointsMinus)
                {
                    perpVector = CCPoint.PerpendicularCCW(CCPoint.Normalize(points[i - 1] - p1));
                }
                else
                {
                    CCPoint p2 = points[i + 1];
                    CCPoint p0 = points[i - 1];

                    CCPoint p2p1 = CCPoint.Normalize(p2 - p1);
                    CCPoint p0p1 = CCPoint.Normalize(p0 - p1);

                    // Calculate angle between vectors
                    var angle = (float)Math.Acos(CCPoint.Dot(p2p1, p0p1));

                    if (angle < rad70)
                    {
                        perpVector = CCPoint.PerpendicularCCW(CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1)));
                    }
                    else if (angle < rad170)
                    {
                        perpVector = CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1));
                    }
                    else
                    {
                        perpVector = CCPoint.PerpendicularCCW(CCPoint.Normalize(p2 - p0));
                    }
                }

                perpVector = perpVector * stroke;

                vertices[idx].Vertices     = new CCVertex3F(p1.X + perpVector.X, p1.Y + perpVector.Y, 0);
                vertices[idx + 1].Vertices = new CCVertex3F(p1.X - perpVector.X, p1.Y - perpVector.Y, 0);
            }

            // Validate vertexes
            offset = (offset == 0) ? 0 : offset - 1;
            for (int i = offset; i < nuPointsMinus; i++)
            {
                idx = i * 2;
                int idx1 = idx + 2;

                CCVertex3F p1 = vertices[idx].Vertices;
                CCVertex3F p2 = vertices[idx + 1].Vertices;
                CCVertex3F p3 = vertices[idx1].Vertices;
                CCVertex3F p4 = vertices[idx1 + 1].Vertices;

                float s;
                bool  fixVertex = !VertexLineIntersect(p1.X, p1.Y, p4.X, p4.Y, p2.X, p2.Y, p3.X, p3.Y, out s);
                if (!fixVertex)
                {
                    if (s < 0.0f || s > 1.0f)
                    {
                        fixVertex = true;
                    }
                }

                if (fixVertex)
                {
                    vertices[idx1].Vertices     = p4;
                    vertices[idx1 + 1].Vertices = p3;
                }
            }
        }
Example #22
0
 public CCV3F_C4B(CCPoint position, CCColor4B color)
 {
     this.Vertices = CCVertex3F.Zero;
     this.Vertices.X = position.X;
     this.Vertices.Y = position.Y;
     Colors = color;
 }
Example #23
0
        public override void Update(float time)
        {
            float angle = (float)Math.PI * time; // 180 degrees
            var   mz    = (float)Math.Sin(angle);

            angle = angle / 2.0f; // x calculates degrees from 0 to 90
            var mx = (float)Math.Cos(angle);

            CCVertex3F v0, v1, v;
            var        diff = new CCVertex3F();

            v0 = OriginalVertex(1, 1);
            v1 = OriginalVertex(0, 0);

            float      x0 = v0.X;
            float      x1 = v1.X;
            float      x;
            CCGridSize a, b, c, d;

            if (x0 > x1)
            {
                // Normal Grid
                a = new CCGridSize(0, 0);
                b = new CCGridSize(0, 1);
                c = new CCGridSize(1, 0);
                d = new CCGridSize(1, 1);
                x = x0;
            }
            else
            {
                // Reversed Grid
                c = new CCGridSize(0, 0);
                d = new CCGridSize(0, 1);
                a = new CCGridSize(1, 0);
                b = new CCGridSize(1, 1);
                x = x1;
            }

            diff.X = (x - x * mx);
            diff.Z = Math.Abs((float)Math.Floor((x * mz) / 4.0f));

            // bottom-left
            v    = OriginalVertex(a);
            v.X  = diff.X;
            v.Z += diff.Z;
            SetVertex(a, ref v);

            // upper-left
            v    = OriginalVertex(b);
            v.X  = diff.X;
            v.Z += diff.Z;
            SetVertex(b, ref v);

            // bottom-right
            v    = OriginalVertex(c);
            v.X -= diff.X;
            v.Z -= diff.Z;
            SetVertex(c, ref v);

            // upper-right
            v    = OriginalVertex(d);
            v.X -= diff.X;
            v.Z -= diff.Z;
            SetVertex(d, ref v);
        }
Example #24
0
 public void AddVertex(CCVertex3F vertex, CCColor4B color, PrimitiveType primitiveType)
 {
     AddVertex(new CCVector2(vertex.X, vertex.Y), color, primitiveType);
 }
Example #25
0
 /// <summary>
 /// sets a new vertex at a given position
 /// </summary>
 public void SetVertex(int x, int y, ref CCVertex3F vertex)
 {
     grid3D [x, y] = vertex;
 }
Example #26
0
 public CCVertex2F(CCVertex3F vertex3F) : this(vertex3F.X, vertex3F.Y)
 {
 }
Example #27
0
 public CCVertex2F(CCVertex3F vertex3F) : this(vertex3F.X, vertex3F.Y)
 {
 }
Example #28
0
 public CCV3F_C4B(CCVertex3F position, CCColor4B color)
 {
     this.Vertices = position;
     Colors = color;
 }
Example #29
0
        CCVertex3F VertexFromAlphaPoint(CCPoint alpha)
        {
            CCVertex3F ret = new CCVertex3F(0.0f, 0.0f, 0.0f);

            if (Sprite != null) 
            {
                CCV3F_C4B_T2F_Quad quad = Sprite.Quad;

                CCPoint min = new CCPoint(quad.BottomLeft.Vertices.X, quad.BottomLeft.Vertices.Y);
                CCPoint max = new CCPoint(quad.TopRight.Vertices.X, quad.TopRight.Vertices.Y);

                ret.X = min.X * (1f - alpha.X) + max.X * alpha.X;
                ret.Y = min.Y * (1f - alpha.Y) + max.Y * alpha.Y;
            }

            return ret;
        }
Example #30
0
        public override void CalculateVertexPoints()
        {
            float width = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numOfPoints = (GridSize.X + 1) * (GridSize.Y + 1);

            vertexBuffer = new CCVertexBuffer<CCV3F_T2F>(numOfPoints, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numOfPoints;
            indexBuffer = new CCIndexBuffer<ushort>(GridSize.X * GridSize.Y * 6, BufferUsage.WriteOnly);
            indexBuffer.Count = GridSize.X * GridSize.Y * 6;

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

            OriginalVertices = new CCVertex3F[numOfPoints];

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

            var l1 = new int[4];
            var l2 = new CCVertex3F[4];
            var tex1 = new int[4];
            var tex2 = new CCPoint[4];

            //int idx = -1;
            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;

                    var a = (short) (x * (GridSize.Y + 1) + y);
                    var b = (short) ((x + 1) * (GridSize.Y + 1) + y);
                    var c = (short) ((x + 1) * (GridSize.Y + 1) + (y + 1));
                    var d = (short) (x * (GridSize.Y + 1) + (y + 1));

                    int idx = ((y * GridSize.X) + x) * 6;

                    idxArray[idx + 0] = (ushort) a;
                    idxArray[idx + 1] = (ushort) b;
                    idxArray[idx + 2] = (ushort) d;
                    idxArray[idx + 3] = (ushort) b;
                    idxArray[idx + 4] = (ushort) c;
                    idxArray[idx + 5] = (ushort) d;

                    //var tempidx = new short[6] {a, d, b, b, d, c};
                    //Array.Copy(tempidx, 0, idxArray, 6 * idx, tempidx.Length);

                    l1[0] = a;
                    l1[1] = b;
                    l1[2] = c;
                    l1[3] = d;

                    //var e = new Vector3(x1, y1, 0);
                    //var f = new Vector3(x2, y1, 0);
                    //var g = new Vector3(x2, y2, 0);
                    //var h = new Vector3(x1, y2, 0);

                    l2[0] = new CCVertex3F(x1, y1, 0);
                    l2[1] = new CCVertex3F(x2, y1, 0);
                    l2[2] = new CCVertex3F(x2, y2, 0);
                    l2[3] = new CCVertex3F(x1, y2, 0);

                    tex1[0] = a;
                    tex1[1] = b;
                    tex1[2] = c;
                    tex1[3] = d;

                    tex2[0] = new CCPoint(x1, y1);
                    tex2[1] = new CCPoint(x2, y1);
                    tex2[2] = new CCPoint(x2, y2);
                    tex2[3] = new CCPoint(x1, y2);

                    for (int i = 0; i < 4; ++i)
                    {
                        vertArray[l1[i]].Vertices = l2[i];

                        vertArray[tex1[i]].TexCoords.U = tex2[i].X / width;

                        if (TextureFlipped)
                        {
                            vertArray[tex1[i]].TexCoords.V = tex2[i].Y / height;
                        }
                        else
                        {
                            vertArray[tex1[i]].TexCoords.V = (imageH - tex2[i].Y) / height;
                        }
                    }
                }
            }

            int n = (GridSize.X + 1) * (GridSize.Y + 1);
            for (int i = 0; i < n; i++)
            {
                OriginalVertices[i] = Vertices[i].Vertices;
            }

            indexBuffer.UpdateBuffer();

            dirty = true;
        }
Example #31
0
        public override void Update(float time)
        {
            float angle = (float)Math.PI * time; // 180 degrees
            var   mz    = (float)Math.Sin(angle);

            angle = angle / 2.0f; // x calculates degrees from 0 to 90
            var my = (float)Math.Cos(angle);

            CCVertex3F v0, v1, v;
            var        diff = new CCVertex3F();

            v0 = OriginalVertex(1, 1);
            v1 = OriginalVertex(0, 0);

            float      y0 = v0.Y;
            float      y1 = v1.Y;
            float      y;
            CCGridSize a, b, c, d;

            if (y0 > y1)
            {
                // Normal Grid
                a = new CCGridSize(0, 0);
                b = new CCGridSize(0, 1);
                c = new CCGridSize(1, 0);
                d = new CCGridSize(1, 1);
                y = y0;
            }
            else
            {
                // Reversed Grid
                b = new CCGridSize(0, 0);
                a = new CCGridSize(0, 1);
                d = new CCGridSize(1, 0);
                c = new CCGridSize(1, 1);
                y = y1;
            }

            diff.Y = y - y * my;
            diff.Z = Math.Abs((float)Math.Floor((y * mz) / 4.0f));

            // bottom-left
            v    = OriginalVertex(a);
            v.Y  = diff.Y;
            v.Z += diff.Z;
            SetVertex(a, ref v);

            // upper-left
            v    = OriginalVertex(b);
            v.Y -= diff.Y;
            v.Z -= diff.Z;
            SetVertex(b, ref v);

            // bottom-right
            v    = OriginalVertex(c);
            v.Y  = diff.Y;
            v.Z += diff.Z;
            SetVertex(c, ref v);

            // upper-right
            v    = OriginalVertex(d);
            v.Y -= diff.Y;
            v.Z -= diff.Z;
            SetVertex(d, ref v);
        }