public override void Update(float time) { int i, j; for (i = 0; i < m_sGridSize.X + 1; ++i) { for (j = 0; j < m_sGridSize.Y + 1; ++j) { CCVertex3F v = OriginalVertex(new CCGridSize(i, j)); if (m_bVertical) { v.X = (v.X + ((float)Math.Sin(time * (float)Math.PI * m_nWaves * 2 + v.Y * .01f) * m_fAmplitude * m_fAmplitudeRate)); } if (m_bHorizontal) { v.Y = (v.Y + ((float)Math.Sin(time * (float)Math.PI * m_nWaves * 2 + v.X * .01f) * m_fAmplitude * m_fAmplitudeRate)); } SetVertex(new CCGridSize(i, j), ref v); } } }
public override void Update(float time) { int i, j; CCGridSize gs; for (i = 0; i < (m_sGridSize.X + 1); ++i) { for (j = 0; j < (m_sGridSize.Y + 1); ++j) { gs.X = i; gs.Y = j; CCVertex3F v = OriginalVertex(gs); float x = m_positionInPixels.X - v.X; float y = m_positionInPixels.Y - v.Y; var r = (float)Math.Sqrt((x * x + y * y)); if (r < m_fRadius) { r = m_fRadius - r; float r1 = r / m_fRadius; float rate = r1 * r1; v.Z += ((float)Math.Sin(time * MathHelper.Pi * m_nWaves * 2 + r * 0.1f) * m_fAmplitude * m_fAmplitudeRate * rate); } SetVertex(gs, ref v); } } }
public override void Update(float time) { int i, j; CCPoint c = m_positionInPixels; for (i = 0; i < (m_sGridSize.X + 1); ++i) { for (j = 0; j < (m_sGridSize.Y + 1); ++j) { CCVertex3F v = OriginalVertex(new CCGridSize(i, j)); var avg = new CCPoint(i - (m_sGridSize.X / 2.0f), j - (m_sGridSize.Y / 2.0f)); var r = (float)Math.Sqrt((avg.X * avg.X + avg.Y * avg.Y)); float amp = 0.1f * m_fAmplitude * m_fAmplitudeRate; float a = r * (float)Math.Cos((float)Math.PI / 2.0f + time * (float)Math.PI * m_nTwirls * 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(new CCGridSize(i, j), ref v); } } }
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 = /*0.01f */ +MathHelper.PiOver2 + deltaTheta; var sinTheta = (float)Math.Sin(theta); var cosTheta = (float)Math.Cos(theta); for (int i = 0; i <= m_sGridSize.X; ++i) { for (int j = 0; j <= m_sGridSize.Y; ++j) { // Get original vertex var gs = new CCGridSize(i, j); CCVertex3F p = OriginalVertex(gs); 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(gs, ref p); } } }
public override void Update(float time) { int i, j; for (i = 0; i < m_sGridSize.X + 1; ++i) { for (j = 0; j < m_sGridSize.Y + 1; ++j) { CCVertex3F v = OriginalVertex(new CCGridSize(i, j)); v.Z += ((float)Math.Sin((float)Math.PI * time * m_nWaves * 2 + (v.Y + v.X) * .01f) * m_fAmplitude * m_fAmplitudeRate); SetVertex(new CCGridSize(i, j), ref v); } } }
public override void Update(float time) { int i, j; for (i = 1; i < m_sGridSize.X; ++i) { for (j = 1; j < m_sGridSize.Y; ++j) { CCVertex3F v = OriginalVertex(new CCGridSize(i, j)); v.X = (v.X + ((float)Math.Sin(time * (float)Math.PI * m_nWaves * 2 + v.X * .01f) * m_fAmplitude * m_fAmplitudeRate)); v.Y = (v.Y + ((float)Math.Sin(time * (float)Math.PI * m_nWaves * 2 + v.Y * .01f) * m_fAmplitude * m_fAmplitudeRate)); SetVertex(new CCGridSize(i, j), ref v); } } }
protected CCVertex3F VertexFromAlphaPoint(CCPoint alpha) { var ret = new CCVertex3F(0.0f, 0.0f, 0.0f); if (m_pSprite == null) { return(ret); } CCV3F_C4B_T2F_Quad quad = m_pSprite.Quad; var min = new CCPoint(quad.BottomLeft.Vertices.X, quad.BottomLeft.Vertices.Y); var 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); }
public override void Update(float time) { if (m_bDirty) { int i, j; for (i = 0; i < m_sGridSize.X + 1; ++i) { for (j = 0; j < m_sGridSize.Y + 1; ++j) { CCVertex3F v = OriginalVertex(new CCGridSize(i, j)); var vect = new CCPoint(m_positionInPixels.X - v.X, m_positionInPixels.Y - v.Y); float r = vect.Length; if (r < m_fRadius) { r = m_fRadius - r; float pre_log = r / m_fRadius; if (pre_log == 0) { pre_log = 0.001f; } float l = (float)Math.Log(pre_log) * m_fLensEffect; float new_r = (float)Math.Exp(l) * m_fRadius; if (Math.Sqrt((vect.X * vect.X + vect.Y * vect.Y)) > 0) { vect = CCPoint.Normalize(vect); CCPoint new_vect = vect * new_r; v.Z += (m_bConcave ? -1.0f : 1.0f) * new_vect.Length * m_fLensEffect; } } SetVertex(new CCGridSize(i, j), ref v); } } m_bDirty = false; } }
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(new CCGridSize(1, 1)); v1 = OriginalVertex(new CCGridSize(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); }
public void SetVertex(CCGridSize pos, ref CCVertex3F vertex) { m_pGrid.SetVertex(pos, ref vertex); }
private 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.Perp(CCPoint.Normalize(p1 - points[i + 1])); } else if (i == nuPointsMinus) { perpVector = CCPoint.Perp(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.Perp(CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1))); } else if (angle < rad170) { perpVector = CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1)); } else { perpVector = CCPoint.Perp(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 = !ccVertexLineIntersect(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; } } }
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(new CCGridSize(1, 1)); v1 = OriginalVertex(new CCGridSize(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); }
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(new CCGridSize(1, 1)); v1 = OriginalVertex(new CCGridSize(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); }
public static CCVertex3F Vertex3(float x, float y, float z) { CCVertex3F c = new CCVertex3F(x, y, z); return c; }
protected CCVertex3F VertexFromAlphaPoint(CCPoint alpha) { var ret = new CCVertex3F(0.0f, 0.0f, 0.0f); if (m_pSprite == null) { return ret; } CCV3F_C4B_T2F_Quad quad = m_pSprite.Quad; var min = new CCPoint(quad.BottomLeft.Vertices.X, quad.BottomLeft.Vertices.Y); var 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; }
public override void CalculateVertexPoints() { float width = m_pTexture.PixelsWide; float height = m_pTexture.PixelsHigh; float imageH = m_pTexture.ContentSizeInPixels.Height; int numOfPoints = (m_sGridSize.X + 1) * (m_sGridSize.Y + 1); m_pVertexBuffer = new CCVertexBuffer <CCV3F_T2F>(numOfPoints, BufferUsage.WriteOnly); m_pVertexBuffer.Count = numOfPoints; m_pIndexBuffer = new CCIndexBuffer <ushort>(m_sGridSize.X * m_sGridSize.Y * 6, BufferUsage.WriteOnly); m_pIndexBuffer.Count = m_sGridSize.X * m_sGridSize.Y * 6; m_pVertices = m_pVertexBuffer.Data.Elements; m_pIndices = m_pIndexBuffer.Data.Elements; m_pOriginalVertices = new CCVertex3F[numOfPoints]; CCV3F_T2F[] vertArray = m_pVertices; ushort[] idxArray = m_pIndices; 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 < m_sGridSize.X; ++x) { for (int 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; var a = (short)(x * (m_sGridSize.Y + 1) + y); var b = (short)((x + 1) * (m_sGridSize.Y + 1) + y); var c = (short)((x + 1) * (m_sGridSize.Y + 1) + (y + 1)); var d = (short)(x * (m_sGridSize.Y + 1) + (y + 1)); int idx = ((y * m_sGridSize.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 (m_bIsTextureFlipped) { vertArray[tex1[i]].texCoords.V = tex2[i].Y / height; } else { vertArray[tex1[i]].texCoords.V = (imageH - tex2[i].Y) / height; } } } } int n = (m_sGridSize.X + 1) * (m_sGridSize.Y + 1); for (int i = 0; i < n; i++) { m_pOriginalVertices[i] = m_pVertices[i].vertices; } m_pIndexBuffer.UpdateBuffer(); m_bDirty = true; }
/// <summary> /// sets a new vertex at a given position /// </summary> public void SetVertex(CCGridSize pos, ref CCVertex3F vertex) { m_pVertices[pos.X * (m_sGridSize.Y + 1) + pos.Y].vertices = vertex; m_bDirty = true; }
public override void CalculateVertexPoints() { float width = m_pTexture.PixelsWide; float height = m_pTexture.PixelsHigh; float imageH = m_pTexture.ContentSizeInPixels.Height; int numOfPoints = (m_sGridSize.X + 1) * (m_sGridSize.Y + 1); m_pVertices = new CCV3F_T2F[numOfPoints]; m_pOriginalVertices = new CCVertex3F[numOfPoints]; //m_pTexCoordinates = new CCPoint[numOfPoints]; m_pIndices = new ushort[m_sGridSize.X * m_sGridSize.Y * 6]; CCV3F_T2F[] vertArray = m_pVertices; //var texArray = m_pTexCoordinates; ushort[] idxArray = m_pIndices; 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 < m_sGridSize.X; ++x) { for (int 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; var a = (short) (x * (m_sGridSize.Y + 1) + y); var b = (short) ((x + 1) * (m_sGridSize.Y + 1) + y); var c = (short) ((x + 1) * (m_sGridSize.Y + 1) + (y + 1)); var d = (short) (x * (m_sGridSize.Y + 1) + (y + 1)); int idx = ((y * m_sGridSize.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 (m_bIsTextureFlipped) { vertArray[tex1[i]].texCoords.V = tex2[i].Y / height; } else { vertArray[tex1[i]].texCoords.V = (imageH - tex2[i].Y) / height; } } } } int n = (m_sGridSize.X + 1) * (m_sGridSize.Y + 1); for (int i = 0; i < n; i++) { m_pOriginalVertices[i] = m_pVertices[i].vertices; } m_bDirty = true; }
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(new CCGridSize(1, 1)); v1 = OriginalVertex(new CCGridSize(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); }
public static CCVertex3F Vertex3(float x, float y, float z) { CCVertex3F c = new CCVertex3F(x, y, z); return(c); }