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; }
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; }
/// <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 void SetVertex(CCGridSize pos, ref CCVertex3F vertex) { m_pGrid.SetVertex(pos, ref vertex); }